| 1 | 25 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 2 | 25 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 25 | ▶ | use 5.022; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 25 | ▶ | use feature qw /postderef signatures/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | # ABSTRACT: toolkit for implementing voting methods. | ||||||||||||||
| 7 | |||||||||||||||
| 8 | package Vote::Count; | ||||||||||||||
| 9 | 25 | ▶ | use namespace::autoclean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 25 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 25 | ▶ | use Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 25 | ▶ | use Time::Piece; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 25 | ▶ | use Path::Tiny; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 25 | ▶ | use Vote::Count::Matrix; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 25 | ▶ | use Vote::Count::ReadBallots qw( read_ballots read_range_ballots); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | # use Storable 3.15 'dclone'; | ||||||||||||||
| 18 | |||||||||||||||
| 19 | 25 | ▶ | no warnings 'experimental'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | |||||||||||||||
| 21 | 25 | our $VERSION='1.10'; | |||||||||||||
| 22 | |||||||||||||||
| 23 | =head1 NAME | ||||||||||||||
| 24 | |||||||||||||||
| 25 | Vote::Count | ||||||||||||||
| 26 | |||||||||||||||
| 27 | |||||||||||||||
| 28 | =head1 VERSION 1.10 | ||||||||||||||
| 29 | |||||||||||||||
| 30 | =cut | ||||||||||||||
| 31 | |||||||||||||||
| 32 | # ABSTRACT: Parent Module for Vote::Count. Toolkit for vote counting. | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 25 | has 'BallotSet' => ( is => 'ro', isa => 'HashRef', required => 1 ); | |||||||||||||
| 35 | |||||||||||||||
| 36 | ▶ | sub _load_ballotset ( $self ) { | |||||||||||||
|
Subroutine
_load_ballotset: called CC=3 SCAR=15.4
| |||||||||||||||
| 37 | 124 | ▶ | if ( $self->{'BallotSet'}{'read_ballots'} ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 38 | $self->{'BallotSet'} | ||||||||||||||
| 39 | 0 | = read_ballots( $self->{'BallotSet'}{'read_ballots'} ); | |||||||||||||
| 40 | } elsif ( $self->{'BallotSet'}{'read_range_ballots'} ) { | ||||||||||||||
| 41 | $self->{'BallotSet'} | ||||||||||||||
| 42 | 0 | = read_range_ballots( $self->{'BallotSet'}{'read_range_ballots'} ); | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 25 | has 'PairMatrix' => ( | |||||||||||||
| 47 | is => 'ro', | ||||||||||||||
| 48 | isa => 'Object', | ||||||||||||||
| 49 | lazy => 1, | ||||||||||||||
| 50 | builder => '_buildmatrix', | ||||||||||||||
| 51 | ); | ||||||||||||||
| 52 | |||||||||||||||
| 53 | ▶ | sub _buildmatrix ( $self ) { | |||||||||||||
|
Subroutine
_buildmatrix: called CC=2 SCAR=6.9
| |||||||||||||||
| 54 | 46 | ▶ | my $tiebreak = | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | defined( $self->TieBreakMethod() ) | ||||||||||||||
| 56 | ? $self->TieBreakMethod() | ||||||||||||||
| 57 | : 'none'; | ||||||||||||||
| 58 | 46 | return Vote::Count::Matrix->new( | |||||||||||||
| 59 | BallotSet => $self->BallotSet(), | ||||||||||||||
| 60 | Active => $self->Active(), | ||||||||||||||
| 61 | TieBreakMethod => $tiebreak, | ||||||||||||||
| 62 | LogTo => $self->LogTo() . '_matrix', | ||||||||||||||
| 63 | ); | ||||||||||||||
| 64 | } | ||||||||||||||
| 65 | |||||||||||||||
| 66 | sub BUILD { | ||||||||||||||
| 67 | 124 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 68 | # If files were given to ballotset they need to be loaded | ||||||||||||||
| 69 | 124 | $self->_load_ballotset(); | |||||||||||||
| 70 | # Verbose Log | ||||||||||||||
| 71 | 124 | $self->{'LogV'} = localtime->cdate . "\n"; | |||||||||||||
| 72 | # Debugging Log | ||||||||||||||
| 73 | 124 | $self->{'LogD'} = qq/Vote::Count Version $VERSION\n/; | |||||||||||||
| 74 | 124 | $self->{'LogD'} .= localtime->cdate . "\n"; | |||||||||||||
| 75 | # Terse Log | ||||||||||||||
| 76 | 124 | $self->{'LogT'} = ''; | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | # load the roles providing the underlying ops. | ||||||||||||||
| 80 | 25 | with | |||||||||||||
| 81 | 'Vote::Count::Common', | ||||||||||||||
| 82 | 'Vote::Count::Approval', | ||||||||||||||
| 83 | 'Vote::Count::Borda', | ||||||||||||||
| 84 | 'Vote::Count::Floor', | ||||||||||||||
| 85 | 'Vote::Count::IRV', | ||||||||||||||
| 86 | 'Vote::Count::Log', | ||||||||||||||
| 87 | 'Vote::Count::Score', | ||||||||||||||
| 88 | 'Vote::Count::TieBreaker', | ||||||||||||||
| 89 | 'Vote::Count::TopCount', | ||||||||||||||
| 90 | ; | ||||||||||||||
| 91 | |||||||||||||||
| 92 | 25 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 93 | 25 | 1; | |||||||||||||
| 94 | |||||||||||||||
| 95 | #buildpod | ||||||||||||||
| 96 | |||||||||||||||
| 97 | =pod | ||||||||||||||
| 98 | |||||||||||||||
| 99 | =head1 Vote::Count | ||||||||||||||
| 100 | |||||||||||||||
| 101 | |||||||||||||||
| 102 | =head2 A Toolkit for determining the outcome of Preferential Ballots. | ||||||||||||||
| 103 | |||||||||||||||
| 104 | Provides a Toolkit for implementing multiple voting systems, allowing a wide range of method options. This library allows the creation of election resolution methods matching a set of Election Rules that are written in an organization's governing rules, and not requiring the bylaws to specify the rules of the software that will be used for the election, especially important given that many of the other libraries available do not provide a bylaws compatible explanation of their process. | ||||||||||||||
| 105 | |||||||||||||||
| 106 | |||||||||||||||
| 107 | =head1 Synopsis | ||||||||||||||
| 108 | |||||||||||||||
| 109 | use 5.022; # Minimum Perl, or any later Perl. | ||||||||||||||
| 110 | use feature qw /postderef signatures/; | ||||||||||||||
| 111 | |||||||||||||||
| 112 | use Vote::Count; | ||||||||||||||
| 113 | use Vote::Count::ReadBallots; | ||||||||||||||
| 114 | use Vote::Count::Method::CondorcetDropping; | ||||||||||||||
| 115 | |||||||||||||||
| 116 | # example uses biggerset1 from the distribution test data. | ||||||||||||||
| 117 | my $ballotset = read_ballots 't/data/biggerset1.txt' ; | ||||||||||||||
| 118 | my $CondorcetElection = | ||||||||||||||
| 119 | Vote::Count::Method::CondorcetDropping->new( | ||||||||||||||
| 120 | 'BallotSet' => $ballotset , | ||||||||||||||
| 121 | 'DropStyle' => 'all', | ||||||||||||||
| 122 | 'DropRule' => 'topcount', | ||||||||||||||
| 123 | ); | ||||||||||||||
| 124 | # ChoicesAfterFloor a hashref of choices meeting the | ||||||||||||||
| 125 | # ApprovalFloor which defaulted to 5%. | ||||||||||||||
| 126 | my $ChoicesAfterFloor = $CondorcetElection->ApprovalFloor(); | ||||||||||||||
| 127 | # Apply the ChoicesAfterFloor to the Election. | ||||||||||||||
| 128 | $CondorcetElection->SetActive( $ChoicesAfterFloor ); | ||||||||||||||
| 129 | # Get Smith Set and the Election with it as the Active List. | ||||||||||||||
| 130 | my $SmithSet = $CondorcetElection->Matrix()->SmithSet() ; | ||||||||||||||
| 131 | $CondorcetElection->logt( | ||||||||||||||
| 132 | "Dominant Set Is: " . join( ', ', keys( $SmithSet->%* ))); | ||||||||||||||
| 133 | my $Winner = $CondorcetElection->RunCondorcetDropping( $SmithSet )->{'winner'}; | ||||||||||||||
| 134 | |||||||||||||||
| 135 | # Create an object for IRV, use the same Floor as Condorcet | ||||||||||||||
| 136 | |||||||||||||||
| 137 | my $IRVElection = Vote::Count->new( | ||||||||||||||
| 138 | 'BallotSet' => $ballotset, | ||||||||||||||
| 139 | 'Active' => $ChoicesAfterFloor ); | ||||||||||||||
| 140 | # Get a RankCount Object for the | ||||||||||||||
| 141 | my $Plurality = $IRVElection->TopCount(); | ||||||||||||||
| 142 | my $PluralityWinner = $Plurality->Leader(); | ||||||||||||||
| 143 | $IRVElection->logv( "Plurality Results", $Plurality->RankTable); | ||||||||||||||
| 144 | if ( $PluralityWinner->{'winner'}) { | ||||||||||||||
| 145 | $IRVElection->logt( "Plurality Winner: ", $PluralityWinner->{'winner'} ) | ||||||||||||||
| 146 | } else { | ||||||||||||||
| 147 | $IRVElection->logt( | ||||||||||||||
| 148 | "Plurality Tie: " . join( ', ', $PluralityWinner->{'tied'}->@*) ) | ||||||||||||||
| 149 | } | ||||||||||||||
| 150 | my $IRVResult = $IRVElection->RunIRV(); | ||||||||||||||
| 151 | |||||||||||||||
| 152 | # Now print the logs and winning information. | ||||||||||||||
| 153 | say $CondorcetElection->logv(); | ||||||||||||||
| 154 | say $IRVElection->logv(); | ||||||||||||||
| 155 | say '*'x60; | ||||||||||||||
| 156 | say "Plurality Winner: $PluralityWinner->{'winner'}"; | ||||||||||||||
| 157 | say "IRV Winner: $IRVResult->{'winner'}"; | ||||||||||||||
| 158 | say "Condorcet Winner: $Winner"; | ||||||||||||||
| 159 | |||||||||||||||
| 160 | |||||||||||||||
| 161 | =head1 Overview | ||||||||||||||
| 162 | |||||||||||||||
| 163 | |||||||||||||||
| 164 | =head2 Brief Review of Voting Methods | ||||||||||||||
| 165 | |||||||||||||||
| 166 | Several alternatives have been proposed to the simple vote for a single choice method that has been used in most elections for a single member. In addition a number of different methods have been used for multiple members. For alternative single member voting, the three common alternatives are I<Approval> (voters indicate all choices that they approve of), I<Ranked Choice> (Voters rank the choices), and I<Score> also known as I<Range> (voters give choices a score according to a scale). | ||||||||||||||
| 167 | |||||||||||||||
| 168 | I<Vote for One> ballots may be resolved by one of two methods: I<Majority> and I<Plurality>. Majority vote requires a majority of votes to win (but frequently produces no winner), and Plurality which selects the choice with the most votes. | ||||||||||||||
| 169 | |||||||||||||||
| 170 | Numerous methods have been proposed and tried for I<Ranked Choice Ballots>. To compare these methods a number of criteria have been developed. While Mathematicians often treat these criteria as absolutes, from a policy perspective it may be more valuable to see them as a spectrum where a method may be considered to satisfy or fail with varying degrees of severity. From a policy perspective it is appropriate to group most of the criteria into a single group: Consistency. Finally Mathematicians, typically, do not directly consider Complexity, but from a policy perspective this is just as important as any of the other criteria, and is definitely a scale not an absolute. | ||||||||||||||
| 171 | |||||||||||||||
| 172 | |||||||||||||||
| 173 | =head3 The Criteria for Resolving Ranked Choice (including Score) Ballots | ||||||||||||||
| 174 | |||||||||||||||
| 175 | |||||||||||||||
| 176 | =head4 Later Harm | ||||||||||||||
| 177 | |||||||||||||||
| 178 | Marking a later Choice on a Ballot should not cause a Voter's higher ranked choice to lose. | ||||||||||||||
| 179 | |||||||||||||||
| 180 | |||||||||||||||
| 181 | =head4 Condorcet Criteria | ||||||||||||||
| 182 | |||||||||||||||
| 183 | I<Condorcet Loser> states that a method should not choose a winner that would be defeated in a direct matchup to all other choices. | ||||||||||||||
| 184 | |||||||||||||||
| 185 | I<Condorcet Winner> states a choice which defeats all others in direct matchups should be the Winner. | ||||||||||||||
| 186 | |||||||||||||||
| 187 | I<Smith Criteria> the winner should belong to the smallest set of choices which defeats all choices outside of that set. | ||||||||||||||
| 188 | |||||||||||||||
| 189 | |||||||||||||||
| 190 | =head4 Consistency Criteria | ||||||||||||||
| 191 | |||||||||||||||
| 192 | The Consistency Criteria collectively state: Changes to non-winning alternatives that would not obviously alter the outcome should not change the winner. Adding or removing non-winning choices, or altering the votes for non-winning choices, except in a manner which directly changes the outcome should not alter the outcome. If votes are moved between non-winning alternatives in a manner that has no direct affect on the winner, the winner should not change. Changes to non-winning choices which increase support for the winner should not then cause a different choice to win. | ||||||||||||||
| 193 | |||||||||||||||
| 194 | To illustrate inconsistency: suppose every morning we vote on a flavor of Ice Cream and Chocolate always wins; one morning the three voters who always vote 1:RockyRoad 2:Chocolate simply vote for Chocolate, consistency is violated if Chocolate loses on that day. | ||||||||||||||
| 195 | |||||||||||||||
| 196 | Cloning occurs when similar choices are available, such as Vanilla and Vanilla Bean. If one of the clones would win without the presence of the other, the presence of both should not cause a non-clone to win. | ||||||||||||||
| 197 | |||||||||||||||
| 198 | The cases described above: Monotonocity, Independence of Irrelevant Alternatives and Clone Independence are normally discussed as separate criteria rather than components of one. Additional sub-criteria that haven't been mentioned include: Reversal Symmetry, Participation Consistency, and Later No Help (which could also be considered a sub-criteria of Later Harm). | ||||||||||||||
| 199 | |||||||||||||||
| 200 | There is a specific Criteria that is sometimes called Consistency, in this discussion consistency is discussed in the broad context. No method passes every possible consistency criteria, from a policy perspective a method is consistent if it has no major consistency failures. | ||||||||||||||
| 201 | |||||||||||||||
| 202 | |||||||||||||||
| 203 | =head4 Complexity | ||||||||||||||
| 204 | |||||||||||||||
| 205 | Is it feasible to count 100 ballots by hand? How difficult is it to understand the process (can the average middle school student understand it at all)? How many steps? | ||||||||||||||
| 206 | |||||||||||||||
| 207 | |||||||||||||||
| 208 | =head4 Resolvability | ||||||||||||||
| 209 | |||||||||||||||
| 210 | I<Majority> meets all of the above criteria, however, unless votes are restricted to two choices, it will frequently fail to provide a winner, or even a tie. No method can be completely impervious to ties. Methods that are not Resolvable are frequently combined with other methods, I<Instant Runoff Voting> is a compound method with I<Majority>, and all usable I<Condorcet> Methods combine seeking a Condorcet Winner with some other process. | ||||||||||||||
| 211 | |||||||||||||||
| 212 | |||||||||||||||
| 213 | =head4 Incentive for Strategic Voting | ||||||||||||||
| 214 | |||||||||||||||
| 215 | Voting systems have weaknesses which can incentivize voters to vote in an insincere manner. Later Harm Violation is a strong driver for tactical voting. Inconsistency may create circumstances by which a block of voters by voting in certain ways can boost or harm a choice, this vulnerability type is often referred to as an attack. | ||||||||||||||
| 216 | |||||||||||||||
| 217 | |||||||||||||||
| 218 | =head3 Arrow's Theorem | ||||||||||||||
| 219 | |||||||||||||||
| 220 | Arrows Theorem states that it is impossible to have a system that can resolve Ranked Choice Ballots which meets Later Harm and Condorcet Winner. To extend the notion, if it is impossible to meet two criteria it is truly impossible to meet five. Every method has a trade off, where it will fail some criteria and fail them to different degrees. | ||||||||||||||
| 221 | |||||||||||||||
| 222 | |||||||||||||||
| 223 | =head3 Popular Ranked Choice Resolution Systems | ||||||||||||||
| 224 | |||||||||||||||
| 225 | |||||||||||||||
| 226 | =head4 Instant Runoff Voting (IRV is also known as Hare System, Alternative Vote) | ||||||||||||||
| 227 | |||||||||||||||
| 228 | Seeks a Majority Winner. If there is none the lowest choice is eliminated until there is a Majority Winner or all remaining choices have the same number of votes. | ||||||||||||||
| 229 | |||||||||||||||
| 230 | =over | ||||||||||||||
| 231 | |||||||||||||||
| 232 | =item * | ||||||||||||||
| 233 | |||||||||||||||
| 234 | Easy to Hand Count and Easy to Understand. | ||||||||||||||
| 235 | |||||||||||||||
| 236 | |||||||||||||||
| 237 | =item * | ||||||||||||||
| 238 | |||||||||||||||
| 239 | Meets Later Harm. | ||||||||||||||
| 240 | |||||||||||||||
| 241 | |||||||||||||||
| 242 | =item * | ||||||||||||||
| 243 | |||||||||||||||
| 244 | Fails Condorcet Winner (but meets Condorcet Loser). | ||||||||||||||
| 245 | |||||||||||||||
| 246 | |||||||||||||||
| 247 | =item * | ||||||||||||||
| 248 | |||||||||||||||
| 249 | Fails many Consistency Criteria (The example given for Consistency can happen with IRV). IRV handles clones poorly. | ||||||||||||||
| 250 | |||||||||||||||
| 251 | |||||||||||||||
| 252 | =back | ||||||||||||||
| 253 | |||||||||||||||
| 254 | |||||||||||||||
| 255 | =head4 Borda Count and Scoring | ||||||||||||||
| 256 | |||||||||||||||
| 257 | When Range (Cardinal) Ballots are used, the scores assigned by the voters are tallied to score the choices. | ||||||||||||||
| 258 | |||||||||||||||
| 259 | Since Scoring is native to Range Ballots, to use the approach to resolve Ranked Ballots requires a method of assigning scores. | ||||||||||||||
| 260 | |||||||||||||||
| 261 | Borda Count Scores choices on a ballot based on their position. Borda supporters often disagree about the weighting rule to use in the scoring. Iterative Borda Methods (Baldwin, Nansen) eliminate the lowest choice(s) and recalculate the Borda score ignoring eliminated choices (if your second choice is eliminated your third choice is promoted). | ||||||||||||||
| 262 | |||||||||||||||
| 263 | =over | ||||||||||||||
| 264 | |||||||||||||||
| 265 | =item * | ||||||||||||||
| 266 | |||||||||||||||
| 267 | Easy to Understand. | ||||||||||||||
| 268 | |||||||||||||||
| 269 | |||||||||||||||
| 270 | =item * | ||||||||||||||
| 271 | |||||||||||||||
| 272 | Fails Later Harm. | ||||||||||||||
| 273 | |||||||||||||||
| 274 | |||||||||||||||
| 275 | =item * | ||||||||||||||
| 276 | |||||||||||||||
| 277 | Fails Condorcet Winner. | ||||||||||||||
| 278 | |||||||||||||||
| 279 | |||||||||||||||
| 280 | =item * | ||||||||||||||
| 281 | |||||||||||||||
| 282 | Inconsistent. | ||||||||||||||
| 283 | |||||||||||||||
| 284 | |||||||||||||||
| 285 | =item * | ||||||||||||||
| 286 | |||||||||||||||
| 287 | The basic Borda Method is vulnerable to a Cloning Attack, but not Range Ballot Scoring and iterative Borda methods. | ||||||||||||||
| 288 | |||||||||||||||
| 289 | |||||||||||||||
| 290 | =back | ||||||||||||||
| 291 | |||||||||||||||
| 292 | |||||||||||||||
| 293 | =head4 Condorcet | ||||||||||||||
| 294 | |||||||||||||||
| 295 | Technically this family of methods should be called Condorcet Pairwise, because any method that meets both Condorcet Criteria is technically a Condorcet Method. However, in discussion and throughout this software collection the term Condorcet will refer to methods which uses a Matrix of Wins and Losses derived from direct pairing of choices and seeks to identify a Condorcet Winner. | ||||||||||||||
| 296 | |||||||||||||||
| 297 | The basic Condorcet Method will frequently fail to identify a winner. One possibility is a Loop (Condorcet's Paradox) Where A > B, B > C, and C > A. Another possibility is a knot (not an accepted term, but one which will be used in this documentation). To make Condorcet resolvable a second method is typically used to resolve Loops and Knots. | ||||||||||||||
| 298 | |||||||||||||||
| 299 | =over | ||||||||||||||
| 300 | |||||||||||||||
| 301 | =item * | ||||||||||||||
| 302 | |||||||||||||||
| 303 | Complexity Varies among sub-methods. | ||||||||||||||
| 304 | |||||||||||||||
| 305 | |||||||||||||||
| 306 | |||||||||||||||
| 307 | =item * | ||||||||||||||
| 308 | |||||||||||||||
| 309 | Fails Later Harm. | ||||||||||||||
| 310 | |||||||||||||||
| 311 | |||||||||||||||
| 312 | |||||||||||||||
| 313 | =item * | ||||||||||||||
| 314 | |||||||||||||||
| 315 | Meets both Condorcet Criteria. | ||||||||||||||
| 316 | |||||||||||||||
| 317 | |||||||||||||||
| 318 | |||||||||||||||
| 319 | =item * | ||||||||||||||
| 320 | |||||||||||||||
| 321 | When a Condorcet Winner is present Consistency is very high. When there is no Condorcet Winner this Consistency applies between a Dominant (Smith) Set and the rest of the choices, but not within the Smith Set. Sub-methods vary in consistency when there is no Condorcet Winner. | ||||||||||||||
| 322 | |||||||||||||||
| 323 | |||||||||||||||
| 324 | |||||||||||||||
| 325 | =back | ||||||||||||||
| 326 | |||||||||||||||
| 327 | |||||||||||||||
| 328 | =head3 Range (Score) Voting Systems | ||||||||||||||
| 329 | |||||||||||||||
| 330 | Most Methods for Ranked Choice Ballots can be used for Range Ballots. | ||||||||||||||
| 331 | |||||||||||||||
| 332 | Score Voting proposals typically implement I<Borda Count>, with a fixed depth of choices. I<STAR>, creates a virtual runoff between the top two I<Borda Count> Choices. | ||||||||||||||
| 333 | |||||||||||||||
| 334 | Advocates claim that this Ballot Style is a better expression of voter preference. Where it shows a clear advantage is in allowing Voters to directly mitigate Later Harm by ranking a strongly favored choice with the highest score and weaker choices with the lowest. The downside to this strategy is that the voter is giving little help to later choices reaching the automatic runoff. Given a case with two roughly equal main factions, where one faction give strong support to all of its options, and the other faction's supporters give weak support to all later choices; the runoff will be between the two best choices of the first faction, even if the choices of the second faction all defeat any of the first's choices in pairwise comparison. | ||||||||||||||
| 335 | |||||||||||||||
| 336 | The Range Ballot resolves the Borda weighting problem and allows the voter to manage the later harm effect, so it is clearly a better choice than Borda. Condorcet and IRV can resolve Range Ballots, but ignore the extra information and would prefer strict ordinality (not allowing equal ranking). | ||||||||||||||
| 337 | |||||||||||||||
| 338 | Voters may find the Range Ballot to be more complex than the Ranked Choice Ballot. | ||||||||||||||
| 339 | |||||||||||||||
| 340 | |||||||||||||||
| 341 | =head1 Objective and Motivation | ||||||||||||||
| 342 | |||||||||||||||
| 343 | I wanted to be able to evaluate alternative methods for resolving elections and couldn't find a flexible enough existing library in any of the popular general purpose and web development languages: Perl, PHP, Python, Ruby, JavaScript, nor in the newer language Julia (created as an alternative to R and other math languages). More recently I was writing a bylaws proposal to use RCV and found that the existing libraries and services were not only constrained in what options they can provide, but also didn't always document them clearly, making it a challenge to have a method described in bylaws where it could be guaranteed hand and machine counts would agree. | ||||||||||||||
| 344 | |||||||||||||||
| 345 | The objective is to have a library that can handle any of the myriad variants that one might consider either from a study perspective or what is called for by the elections rules of our entity. | ||||||||||||||
| 346 | |||||||||||||||
| 347 | |||||||||||||||
| 348 | =head1 Basics | ||||||||||||||
| 349 | |||||||||||||||
| 350 | |||||||||||||||
| 351 | =head2 Reading Ballots | ||||||||||||||
| 352 | |||||||||||||||
| 353 | The L<Vote::Count::ReadBallots|https://metacpan.org/pod/Vote::Count::ReadBallots> library provides functionality for reading files from disc. Currently it defines a format for a ballot file and reads that from disk. In the future additional formats may be added. Range Ballots may be in either JSON or YAML formats. | ||||||||||||||
| 354 | |||||||||||||||
| 355 | |||||||||||||||
| 356 | =head2 Voting Method and Component Modules | ||||||||||||||
| 357 | |||||||||||||||
| 358 | The Modules in the space Vote::Count::%Component% provide functionality needed to create a functioning Voting Method. Many of these are consumed as Roles by the Vote::Count object, some such as RankCount and Matrix return their own objects. | ||||||||||||||
| 359 | |||||||||||||||
| 360 | The Modules in the space Vote::Count::Method::%Something% implement a Voting Method such as IRV. These Modules inherit the parent Vote::Count and all of the Components available to it. These modules all return a Hash Reference with the following key: I<winner>, some return additional keys. Methods that can be tied will have additional keys I<tie> and I<tied>. When there is no winner the value of I<winner> will be false. | ||||||||||||||
| 361 | |||||||||||||||
| 362 | Simpler Methods such as single iteration Borda or Approval can be run directly from the Vote::Count Object. | ||||||||||||||
| 363 | |||||||||||||||
| 364 | |||||||||||||||
| 365 | =head2 Vote::Count Module | ||||||||||||||
| 366 | |||||||||||||||
| 367 | The Core Module requires a Ballot Set (which can be obtained from ReadBallots). | ||||||||||||||
| 368 | |||||||||||||||
| 369 | my $Election = Vote::Count->new( | ||||||||||||||
| 370 | BallotSet => read_ballots( 'ballotfile'), # imported from ReadBallots | ||||||||||||||
| 371 | ActiveSet => { 'A' => 1, 'B' => 1, 'C' => 1 }, # Optional | ||||||||||||||
| 372 | ); | ||||||||||||||
| 373 | |||||||||||||||
| 374 | |||||||||||||||
| 375 | =head3 Optional Paramters to Vote::Count | ||||||||||||||
| 376 | |||||||||||||||
| 377 | |||||||||||||||
| 378 | =head4 Active | ||||||||||||||
| 379 | |||||||||||||||
| 380 | A Hashref with the active choices as keys. The Active Choices are represented by a Hashref because it is easier to manipulate hash keys than it is to manipulate random array elements. | ||||||||||||||
| 381 | |||||||||||||||
| 382 | |||||||||||||||
| 383 | =head4 LogTo | ||||||||||||||
| 384 | |||||||||||||||
| 385 | Sets a path and Naming pattern for writing logs with the WriteLogs method. | ||||||||||||||
| 386 | |||||||||||||||
| 387 | 'LogTo' => '/loggingI<path/election>name' | ||||||||||||||
| 388 | |||||||||||||||
| 389 | The WriteLogs method will write the logs appending '.brief', '.full', and '.debug' for the three logs where brief is a summary written with the logt (log terse) method, the full transcript log written with logv, and finally the debug log written with logd. Each higher log level captures all events of the lower log levels. | ||||||||||||||
| 390 | |||||||||||||||
| 391 | The default log location is '/tmp/votecount'. | ||||||||||||||
| 392 | |||||||||||||||
| 393 | When logging from your methods, use logt for events that produce a summary, use logv for events that should be in the full transcript such as round counts, and finally debug is for events that may be helpful in debugging but which should not be in the transcript. | ||||||||||||||
| 394 | |||||||||||||||
| 395 | |||||||||||||||
| 396 | =head3 Active Sets | ||||||||||||||
| 397 | |||||||||||||||
| 398 | Active sets are typically represented as a Hash Reference where the keys represent the active choices and the value is true. The VoteCount Object contains an Active Set which can be Accessed via the Active() method which will return a reference to the Active Set (changing the reference will change the active set). The GetActive and SetActive methods do not preserve any reference links and should be preferred. GetActiveList returns the Active Set as a sorted list. | ||||||||||||||
| 399 | |||||||||||||||
| 400 | Many Components will take an argument for $activeset or default to the current Active set of the Vote::Count object, which will default to the Choices defined in the BallotSet. | ||||||||||||||
| 401 | |||||||||||||||
| 402 | |||||||||||||||
| 403 | =head1 Vote::Count Methods | ||||||||||||||
| 404 | |||||||||||||||
| 405 | Most of these are provided by the Role Common and available directly in both Matrix objects and Vote::Count Objects. Vote::Count objects create a child Matrix object: PairMatrix. | ||||||||||||||
| 406 | |||||||||||||||
| 407 | |||||||||||||||
| 408 | =head3 new | ||||||||||||||
| 409 | |||||||||||||||
| 410 | |||||||||||||||
| 411 | =head3 Active | ||||||||||||||
| 412 | |||||||||||||||
| 413 | Get Active Set as HashRef to the active set. Changing the new HashRef will change the internal Active Set, GetActive is recommended as it will return a HashRef that is a copy instead. | ||||||||||||||
| 414 | |||||||||||||||
| 415 | |||||||||||||||
| 416 | =head3 GetActive | ||||||||||||||
| 417 | |||||||||||||||
| 418 | Returns a hashref containing a copy of the Active Set. | ||||||||||||||
| 419 | |||||||||||||||
| 420 | |||||||||||||||
| 421 | =head3 GetActiveList | ||||||||||||||
| 422 | |||||||||||||||
| 423 | Returns a simple array of the members of the Active Set. | ||||||||||||||
| 424 | |||||||||||||||
| 425 | |||||||||||||||
| 426 | =head3 ResetActive | ||||||||||||||
| 427 | |||||||||||||||
| 428 | Sets the Active Set to the full choices list of the BallotSet. | ||||||||||||||
| 429 | |||||||||||||||
| 430 | |||||||||||||||
| 431 | =head3 SetActive | ||||||||||||||
| 432 | |||||||||||||||
| 433 | Sets the Active Set to provided HashRef. The values to the hashref should evaluate as True. | ||||||||||||||
| 434 | |||||||||||||||
| 435 | |||||||||||||||
| 436 | =head3 SetActiveFromArrayRef | ||||||||||||||
| 437 | |||||||||||||||
| 438 | Same as SetActive except it takes an ArrayRef of the choices to be set as Active. | ||||||||||||||
| 439 | |||||||||||||||
| 440 | |||||||||||||||
| 441 | =head3 BallotSet | ||||||||||||||
| 442 | |||||||||||||||
| 443 | Get BallotSet | ||||||||||||||
| 444 | |||||||||||||||
| 445 | |||||||||||||||
| 446 | =head3 PairMatrix | ||||||||||||||
| 447 | |||||||||||||||
| 448 | Get a Matrix Object for the Active Set. Generated and cached on the first request. | ||||||||||||||
| 449 | |||||||||||||||
| 450 | |||||||||||||||
| 451 | =head3 UpdatePairMatrix | ||||||||||||||
| 452 | |||||||||||||||
| 453 | Regenerate and cache Matrix with current Active Set. | ||||||||||||||
| 454 | |||||||||||||||
| 455 | |||||||||||||||
| 456 | =head3 VotesCast | ||||||||||||||
| 457 | |||||||||||||||
| 458 | Returns the number of votes cast. | ||||||||||||||
| 459 | |||||||||||||||
| 460 | |||||||||||||||
| 461 | =head3 VotesActive | ||||||||||||||
| 462 | |||||||||||||||
| 463 | Returns the number of non-exhausted ballots based on the current Active Set. | ||||||||||||||
| 464 | |||||||||||||||
| 465 | |||||||||||||||
| 466 | =head1 Minimum Perl Version | ||||||||||||||
| 467 | |||||||||||||||
| 468 | It is the policy of Vote::Count to only develop with recent versions of Perl. Support for older versions will be dropped as they either start failing tests or impair adoption of new features. | ||||||||||||||
| 469 | |||||||||||||||
| 470 | |||||||||||||||
| 471 | =head2 Components | ||||||||||||||
| 472 | |||||||||||||||
| 473 | |||||||||||||||
| 474 | =head3 Catalog of Methods | ||||||||||||||
| 475 | |||||||||||||||
| 476 | Directory of Vote Counting Methods linking to the Vote::Count module for it. | ||||||||||||||
| 477 | |||||||||||||||
| 478 | =over | ||||||||||||||
| 479 | |||||||||||||||
| 480 | =item * | ||||||||||||||
| 481 | |||||||||||||||
| 482 | L<Catalog|https://metacpan.org/pod/distribution/Vote-Count/lib/Vote/Catalog.pod> | ||||||||||||||
| 483 | |||||||||||||||
| 484 | |||||||||||||||
| 485 | =back | ||||||||||||||
| 486 | |||||||||||||||
| 487 | |||||||||||||||
| 488 | =head3 Consumed As Roles By Vote::Count | ||||||||||||||
| 489 | |||||||||||||||
| 490 | =over | ||||||||||||||
| 491 | |||||||||||||||
| 492 | =item * | ||||||||||||||
| 493 | |||||||||||||||
| 494 | L<Vote::Count::Approval|https://metacpan.org/pod/Vote::Count::Approval> | ||||||||||||||
| 495 | |||||||||||||||
| 496 | |||||||||||||||
| 497 | =item * | ||||||||||||||
| 498 | |||||||||||||||
| 499 | L<Vote::Count::Borda|https://metacpan.org/pod/Vote::Count::Borda> | ||||||||||||||
| 500 | |||||||||||||||
| 501 | |||||||||||||||
| 502 | =item * | ||||||||||||||
| 503 | |||||||||||||||
| 504 | L<Vote::Count::Floor|https://metacpan.org/pod/Vote::Count::Floor> | ||||||||||||||
| 505 | |||||||||||||||
| 506 | |||||||||||||||
| 507 | =item * | ||||||||||||||
| 508 | |||||||||||||||
| 509 | L<Vote::Count::IRV|https://metacpan.org/pod/Vote::Count::IRV> | ||||||||||||||
| 510 | |||||||||||||||
| 511 | |||||||||||||||
| 512 | =item * | ||||||||||||||
| 513 | |||||||||||||||
| 514 | L<Vote::Count::TopCount|https://metacpan.org/pod/Vote::Count::TopCount> | ||||||||||||||
| 515 | |||||||||||||||
| 516 | |||||||||||||||
| 517 | =item * | ||||||||||||||
| 518 | |||||||||||||||
| 519 | L<Vote::Count::Redact|https://metacpan.org/pod/Vote::Count::Redact> | ||||||||||||||
| 520 | |||||||||||||||
| 521 | |||||||||||||||
| 522 | =item * | ||||||||||||||
| 523 | |||||||||||||||
| 524 | L<Vote::Count::Score|https://metacpan.org/pod/Vote::Count::Score> | ||||||||||||||
| 525 | |||||||||||||||
| 526 | |||||||||||||||
| 527 | =item * | ||||||||||||||
| 528 | |||||||||||||||
| 529 | L<Vote::Count::TieBreaker|https://metacpan.org/pod/Vote::Count::TieBreaker> | ||||||||||||||
| 530 | |||||||||||||||
| 531 | |||||||||||||||
| 532 | =back | ||||||||||||||
| 533 | |||||||||||||||
| 534 | |||||||||||||||
| 535 | =head3 Return Their Own Objects | ||||||||||||||
| 536 | |||||||||||||||
| 537 | =over | ||||||||||||||
| 538 | |||||||||||||||
| 539 | =item * | ||||||||||||||
| 540 | |||||||||||||||
| 541 | L<Vote::Count::Matrix|https://metacpan.org/pod/Vote::Count::Matrix> | ||||||||||||||
| 542 | |||||||||||||||
| 543 | |||||||||||||||
| 544 | =item * | ||||||||||||||
| 545 | |||||||||||||||
| 546 | L<Vote::Count::RankCount|https://metacpan.org/pod/Vote::Count::RankCount> | ||||||||||||||
| 547 | |||||||||||||||
| 548 | |||||||||||||||
| 549 | =back | ||||||||||||||
| 550 | |||||||||||||||
| 551 | |||||||||||||||
| 552 | =head3 Voting Methods | ||||||||||||||
| 553 | |||||||||||||||
| 554 | =over | ||||||||||||||
| 555 | |||||||||||||||
| 556 | =item * | ||||||||||||||
| 557 | |||||||||||||||
| 558 | L<Vote::Count::Method::CondorcetDropping|https://metacpan.org/pod/Vote::Count::Method::CondorcetDropping> | ||||||||||||||
| 559 | |||||||||||||||
| 560 | |||||||||||||||
| 561 | =item * | ||||||||||||||
| 562 | |||||||||||||||
| 563 | L<Vote::Count::Method::CondorcetIRV|https://metacpan.org/pod/Vote::Count::Method::CondorcetIRV> | ||||||||||||||
| 564 | |||||||||||||||
| 565 | |||||||||||||||
| 566 | =item * | ||||||||||||||
| 567 | |||||||||||||||
| 568 | L<Vote::Count::Method::CondorcetVsIRV|https://metacpan.org/pod/Vote::Count::Method::CondorcetVsIRV> | ||||||||||||||
| 569 | |||||||||||||||
| 570 | |||||||||||||||
| 571 | =item * | ||||||||||||||
| 572 | |||||||||||||||
| 573 | L<Vote::Count::Method::MinMax|https://metacpan.org/pod/Vote::Count::Method::MinMax> | ||||||||||||||
| 574 | |||||||||||||||
| 575 | |||||||||||||||
| 576 | |||||||||||||||
| 577 | =item * | ||||||||||||||
| 578 | |||||||||||||||
| 579 | L<Vote::Count::Method::STAR|https://metacpan.org/pod/Vote::Count::Method::STAR> | ||||||||||||||
| 580 | |||||||||||||||
| 581 | |||||||||||||||
| 582 | =back | ||||||||||||||
| 583 | |||||||||||||||
| 584 | |||||||||||||||
| 585 | =head3 Non Object Oriented Components | ||||||||||||||
| 586 | |||||||||||||||
| 587 | =over | ||||||||||||||
| 588 | |||||||||||||||
| 589 | =item * | ||||||||||||||
| 590 | |||||||||||||||
| 591 | L<Vote::Count::Redact|https://metacpan.org/pod/Vote::Count::Redact> | ||||||||||||||
| 592 | |||||||||||||||
| 593 | |||||||||||||||
| 594 | =back | ||||||||||||||
| 595 | |||||||||||||||
| 596 | |||||||||||||||
| 597 | =head3 Utilities | ||||||||||||||
| 598 | |||||||||||||||
| 599 | =over | ||||||||||||||
| 600 | |||||||||||||||
| 601 | =item * | ||||||||||||||
| 602 | |||||||||||||||
| 603 | L<Vote::Count::ReadBallots|https://metacpan.org/pod/Vote::Count::ReadBallots> | ||||||||||||||
| 604 | |||||||||||||||
| 605 | |||||||||||||||
| 606 | =item * | ||||||||||||||
| 607 | |||||||||||||||
| 608 | L<Vote::Count::Start|https://metacpan.org/pod/Vote::Count::Start> | ||||||||||||||
| 609 | |||||||||||||||
| 610 | |||||||||||||||
| 611 | =back | ||||||||||||||
| 612 | |||||||||||||||
| 613 | |||||||||||||||
| 614 | =head3 Additional Documentation | ||||||||||||||
| 615 | |||||||||||||||
| 616 | =over | ||||||||||||||
| 617 | |||||||||||||||
| 618 | =item * | ||||||||||||||
| 619 | |||||||||||||||
| 620 | L<Catalog|https://metacpan.org/pod/distribution/Vote-Count/lib/Vote/Catalog.pod> | ||||||||||||||
| 621 | |||||||||||||||
| 622 | |||||||||||||||
| 623 | =item * | ||||||||||||||
| 624 | |||||||||||||||
| 625 | L<Hand Count|https://metacpan.org/pod/distribution/Vote-Count/lib/Vote/Hand_Count.pod> | ||||||||||||||
| 626 | |||||||||||||||
| 627 | |||||||||||||||
| 628 | =item * | ||||||||||||||
| 629 | |||||||||||||||
| 630 | L<Multi Member|https://metacpan.org/pod/distribution/Vote-Count/lib/Vote/MultiMember.pod> | ||||||||||||||
| 631 | |||||||||||||||
| 632 | |||||||||||||||
| 633 | =item * | ||||||||||||||
| 634 | |||||||||||||||
| 635 | L<Vote::Count::Start|https://metacpan.org/pod/Vote::Count::Start> | ||||||||||||||
| 636 | |||||||||||||||
| 637 | |||||||||||||||
| 638 | =back | ||||||||||||||
| 639 | |||||||||||||||
| 640 | |||||||||||||||
| 641 | =head1 Call for Contributions | ||||||||||||||
| 642 | |||||||||||||||
| 643 | This project needs contributions from Programmers and Mathematicians. Review and citations from Mathematicians are urgently requested, because in addition to being a Tool-set for implementing vote counting this documentation will for many also be the manual. From coders there is a lot of help that could be given: any well known method could use a write up if it is easy to implement with the toolkit (see Benham) or a code submission if it is not. Currently Tiedeman, SSD, and Kemmeny-Young are unimplemented. | ||||||||||||||
| 644 | |||||||||||||||
| 645 | =cut | ||||||||||||||
| 646 | |||||||||||||||
| 647 | #buildpod | ||||||||||||||
| 648 | |||||||||||||||
| 649 | #FOOTER | ||||||||||||||
| 650 | |||||||||||||||
| 651 | =pod | ||||||||||||||
| 652 | |||||||||||||||
| 653 | BUG TRACKER | ||||||||||||||
| 654 | |||||||||||||||
| 655 | L<https://github.com/brainbuz/Vote-Count/issues> | ||||||||||||||
| 656 | |||||||||||||||
| 657 | AUTHOR | ||||||||||||||
| 658 | |||||||||||||||
| 659 | John Karr (BRAINBUZ) brainbuz@cpan.org | ||||||||||||||
| 660 | |||||||||||||||
| 661 | CONTRIBUTORS | ||||||||||||||
| 662 | |||||||||||||||
| 663 | Copyright 2019 by John Karr (BRAINBUZ) brainbuz@cpan.org. | ||||||||||||||
| 664 | |||||||||||||||
| 665 | LICENSE | ||||||||||||||
| 666 | |||||||||||||||
| 667 | This module is released under the GNU Public License Version 3. See license file for details. For more information on this license visit L<http://fsf.org>. | ||||||||||||||
| 668 | |||||||||||||||
| 669 | =cut | ||||||||||||||