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

diff --git a/stv b/stv
index a9636096ae9f90e1f1d58666bc2f5815360b7a04..fbd7b41050b18f535931223c8b7e0d8534c9f095 100755 (executable)
--- a/stv
+++ b/stv
@@ -48,16 +48,6 @@ sub votelog ($$) {
     push @{ $vote->{Log} }, "stage $stage: $m";
 }
 
-sub filterout ($$) {
-    my ($cand, $why) = @_;
-    foreach my $vote (@allvotes) {
-       my $oldprefs = $vote->{Prefs};
-       my @prefs = grep { $_ ne $cand } $oldprefs;
-       next if @prefs == @$oldprefs;
-       votelog $vote, "crossed out candidate $cand: $why";
-    }
-}
-
 our @elected; # $elected[] = $candidate
 
 our @unsorted = @allvotes;
@@ -74,6 +64,17 @@ our %continuing; # $continuing{$candidate}=1
 
 our @stagerecord; # $stagerecord[]{$candidate} = $total
 
+sub voteliveprefs ($) {
+    my ($vote) = @_;
+    grep { $continuing{$_} } @{ $vote->{Prefs} };
+}
+
+sub votelogfull ($$) {
+    my ($vote,$m) = @_;
+    votelog $vote, $m;
+    votelog $vote, ("continuing prefs: ". join ' ', voteliveprefs $vote);
+}
+
 foreach my $vote (@allvotes) {
     $continuing{$_}=1 foreach @{ $vote->{Prefs} };
 }
@@ -144,7 +145,7 @@ for (;;) {
     }
 
     while (my $vote = shift @unsorted) {
-       my ($firstpref) = grep { $continuing{$_} } @{ $vote->{Prefs} };
+       my ($firstpref) = voteliveprefs $vote;
        if (!defined $firstpref) {
            votelog $vote, "ballot exhausted";
            push @exhausted, $vote;
@@ -275,7 +276,7 @@ for (;;) {
            my $c = $s->{Cand};
            printf "%7s %10s %s\n", 'ELIM', $c, '----------';
            my $votes = $s->{Votes};
-           votelog $_, "failed to stop $c elimination" foreach @$votes;
+           votelogfull $_, "failed to stop $c elimination" foreach @$votes;
            $elimvotebefore += $s->{Total};
            delete $continuing{$c};
            delete $sorted{$c};
@@ -301,7 +302,7 @@ for (;;) {
     my $c = $s->{Cand};
     printf "%7s %10s\n", 'xfer', $c;
     my $votes = $s->{Votes};
-    votelog $_, "surplus transferred" foreach @$votes;
+    votelogfull $_, "surplus transferred" foreach @$votes;
     @surpluses = grep { $_->{Cand} ne $c } @surpluses;
     push @unsorted, @$votes;
 }