From fa0279b26ffd9237060ac96f2a50e5e23daa246d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 1 Aug 2016 15:50:15 +0100 Subject: [PATCH] stv: wip debug --- stv | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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; } -- 2.30.2