X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=appendix-a6.git;a=blobdiff_plain;f=stv;fp=stv;h=7059906ccb810b37f8cb06d58ab4253b8d33710d;hp=bd952628c01ba1021a2294ef5295f24b4a585222;hb=fa0279b26ffd9237060ac96f2a50e5e23daa246d;hpb=24bf2bad96f040aacd4dd9ccdab7a300e812513b diff --git a/stv b/stv index bd95262..7059906 100755 --- a/stv +++ b/stv @@ -140,17 +140,18 @@ for (;;) { } $sorted{$_}{Cand} = $_ foreach keys %sorted; foreach my $firstpref (sort keys %sorted) { - $sorted{$firstpref}{Total} = 0; # recount foreach my $vote (@{ $sorted{$firstpref}{Votes} }) { votelog $vote, "counted $vote->{Weight} for $firstpref"; - $sorted{$firstpref}{Total} += $vote->{Weight}; } } my @sorted; - my $sort_update = sub { + my $things_update = sub { + foreach my $s (@surpluses, values %sorted) { + $s->{Total} = sum0 map { $_->{Weight} } @{ $s->{Votes } }; + } @sorted = nsort_by { -$_->{Total} } values %sorted; }; - $sort_update->(); + $things_update->(); print DEBUG "SORTED\n", Dumper(\@sorted); @@ -209,7 +210,9 @@ for (;;) { delete $sorted{ $s->{Cand} }; delete $continuing{ $s->{Cand} }; - $sort_update->(); + $things_update->(); + printf "%7s %10s %s\n", 'surplus', $s->{Cand}, pr $s->{Total}; + $need_to_transfer_surplus = 0; # before actually transferring a surplus, we will consider # eliminating, and then reconsider with a lower quota @@ -261,7 +264,7 @@ for (;;) { push @unsorted, @$votes; } - $sort_update->(); + $things_update->(); $need_to_transfer_surplus = 0; }