From: Ian Jackson Date: Mon, 1 Aug 2016 15:14:38 +0000 (+0100) Subject: stv: wip debug X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=appendix-a6.git;a=commitdiff_plain;h=0328306e06758d9fb43cec21611d044eda1acf09 stv: wip debug --- diff --git a/stv b/stv index a963609..fbd7b41 100755 --- 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; }