chiark / gitweb /
stv: wip debug
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 1 Aug 2016 14:50:15 +0000 (15:50 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 1 Aug 2016 14:50:15 +0000 (15:50 +0100)
stv

diff --git a/stv b/stv
index bd95262..7059906 100755 (executable)
--- 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;
     }