From: Ian Jackson Date: Sun, 21 Aug 2016 16:02:36 +0000 (+0100) Subject: normalise: Support tie X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=appendix-a6.git;a=commitdiff_plain;h=7b75aa25275e551506f5cad2d54fe3548c65ef67;ds=sidebyside normalise: Support tie --- diff --git a/README.format b/README.format index 6bbc5d6..1a75aae 100644 --- a/README.format +++ b/README.format @@ -60,6 +60,10 @@ Currently defined OPTNAMEs (default values shown) Election seats=1 Number of seats to be filled. Election _nodefault For Debian A6, no default option Election quorum=NUM Quorum (default, none) + Election _tie=C,C>D,D Tie break: in tie of Cs vs Ds, + take Cs to have more votes than Ds. + also available with <, normalised to > + normalised form has Cs and Ds sorted Candidate Super=1:1 For Debian A6, RAT:IO, Candidate default For Debian A6, Is the default option diff --git a/normalise b/normalise index c5a9077..0af8f19 100755 --- a/normalise +++ b/normalise @@ -14,9 +14,11 @@ use strict; our @options; our %candidates; # $candidates{CAND}{Desc}, {Opts}[] +our %candref; # $candref{CAND} => msg of why needed our @ballots; my $candvoter_re = '\w+'; +my $cands_re = '\w+(?,\w+)*'; my $opt_re = '\w+(?:=\S*)?'; sub badinput ($) { @@ -31,6 +33,17 @@ sub normalise_opts_list ($$) { foreach my $o (split /\s+/, $os) { if ($o =~ m/^\w+$/) { push @o, $&; + } elsif ($o =~ s/^_[Tt]ie\=//) { + $o =~ m/^($cands_re)([<>])($cands_re)$/ + or badinput "bad value \`$_' for tie option"; + my ($l,$op,$r) = ($1,$2,$3); + ($l,$op,$r) = ($r,'>',$l) if $op eq '<'; + $candref{$_} = "tie break spec" foreach $o =~ m/\w+/g; + $l = join ',', sort split /\,/, $l; + $r = join ',', sort split /\,/, $r; + $l =~ m/\b$_\b/ and badinput "reflexive tie" + foreach split /\,/, $r; + push @o, "$l$op$r"; } elsif ($o =~ m/^\w+\=\S+$/) { push @o, $&; } elsif ($o !~ m/\S/) { @@ -111,6 +124,11 @@ print STDERR Dumper($1,$2,$3); print "| @options\n" or die $!; +foreach my $cand (sort keys %candref) { + badinput "missing candidate $cand (ref. by $candref{$cand}" + unless defined $candidates{$cand}; +} + foreach my $cand (sort keys %candidates) { my $c = $candidates{$cand}; $c->{Desc} //= $cand;