my %options;
GetOptions(\%options,
'option=s@',
+ 'default_option|default-option!',
+ 'quorum=i',
);
if (not exists $options{option} or not ref($options{option}) or
@{$options{option}} < 2
}
my @options;
for my $option (@{$options{option}}) {
- my ($key,$name,$majority) = split /:/,$option;
+ my ($key,$name,$majority) = $option =~ /^\s*([^:]+)\s*:\s*(.+)\s*(?::(\d+))?$/;
$majority //= 1;
push @options,{key => $key,
name => $name,
majority => $majority,
};
}
- winner(options=>\@options);
+ winner(options=>\@options,
+ default_option => exists $options{default_option} ? $options{default_option} : 1,
+ quorum => exists $options{quorum} ? $options{quorum} : 2,
+ );
}
sub encode_base64{
tally_fh => {type => HANDLE,
optional => 1,
},
+ default_option => {default => 1,
+ type => BOOLEAN,
+ },
},
);
# options is an array to keep it ordered
}
# The constitution defines the maximum value of K to be 5
- my $K = 2; # Math::BigFloat->new($params{quorum});
+ my $K = $params{quorum};
# 1. Given two options A and B, V(A,B) is the number of voters who
# prefer option A over option B.
} elsif (m/^(.+) # the voter, can have spaces
\s*:\s+ # needs a colon and a space
((?:[$valid_options] # the vote
- \s*(?:,|=|<)?\s*)*) # allow < and , or =
+ \s*(?:,|=|>)?\s*)*) # allow > and , or =
\s*$/x # useless trailing spaces
) {
$voter = $1;
my $current_rank = 1;
my %option_rank;
while ($vote =~ /([$valid_options]) # the vote
- \s*((?:,|=|<)?)\s*/xg) {
+ \s*((?:,|=|>)?)\s*/xg) {
my ($option,$relationship) = ($1,$2);
$option_rank{$option} = $current_rank;
if ($relationship ne '=') {
print {$RESULTS} "V: $vote $voter\n";
} else {
- print STDERR "ignoring line '$_'; this is probably wrong!";
+ print STDERR "ignoring line '$_'; this is probably wrong!\n";
next;
}
my %Drop = ();
- foreach my $i (0..($max_choices - 2)) {
- if ($K > $Beat_Matrix[$i][$max_choices - 1]) {
- $Drop{$i}++;
- print {$RESULTS} "Dropping Option", $order_to_options{$i + 1}{key},
- " \"", $order_to_options{$i + 1}{name},
- "\" because of Quorum\n";
- } else {
- print {$RESULTS} "Option ", $order_to_options{$i + 1}{key},
- " Reached quorum: $Beat_Matrix[$i][$max_choices - 1] > $K\n";
+ if ($params{default_option}) {
+ foreach my $i (0..($max_choices - 2)) {
+ if ($K > $Beat_Matrix[$i][$max_choices - 1]) {
+ $Drop{$i}++;
+ print {$RESULTS} "Dropping Option", $order_to_options{$i + 1}{key},
+ " \"", $order_to_options{$i + 1}{name},
+ "\" because of Quorum\n";
+ } else {
+ print {$RESULTS} "Option ", $order_to_options{$i + 1}{key},
+ " Reached quorum: $Beat_Matrix[$i][$max_choices - 1] > $K\n";
+ }
}
+ print {$RESULTS} "\n\n";
}
- print {$RESULTS} "\n\n";
# Record Majority
my %Ratio = ();