Election Methods in perl

Command Line Utility

votep.pl takes url formatted votes, one per line, on the standard input and runs VRR, IRNR, IRV and Histogram on them, producing HTML results on the standard output.

Election Method Implementations

Virtual Round Robin (Condorcet)VRR.pm
Instant Runoff Normalized RatingsIRNR.pm
Instant Runoff VotingIRV.pm
HistogramHistogram.pm

All election methods implement a common interface, taking votes and returning results through functions of the same signature. They are built as perl objects.

$obj->voteNameValues($);

Takes reference to array of alternating names and values like [ "a", 3, "B", 5 ]. Values are ratings, higher better.

$obj->voteNameValueHash($);

Takes reference to hash of name=>value entries like { "a" => 3, "B" => 5 }. Values are ratings, higher better.

$obj->voteOrderedNames($);

Takes reference to array of names ordered with highest ranked first like [ "B", "a" ].

$obj->get_results();

Returns array of alternating names and values, sortedy by winningest first.

$obj->htmlSummary();

Return a string with HTML text representing the results of this election and any other information.

$obj->name();

Return a string with the name of the election method.

Utility Code

Vote.pm contains some common code for parsing strings with vote information

gtEqVotesToNameValues($);

"a > b = c > d" becomes [ "a", 4, "b", 3, "c", 3, "d", 1 ]

gtEqVotesToNameValueHash($);

"a > b = c > d" becomes { "a" => 4, "b" => 3, "c" => 3, "d" => 1 }

urlVotesToNameValueHash($)

"a=9&b=2&c=1&d=3" becomes { "a" => 9, "b" => 2, "c" => 1, "d" => 3 }