Count/Method/CondorcetIRV.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 100% 55 / 55 CC 4 SCAR 6.9
CC
4
Cov
100%
SmithSetIRV
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« Count/Log.pm ↑ Summary Count.pm »
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use 5.022;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use feature qw /postderef signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Vote::Count::Method::CondorcetIRV;
7 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 extends 'Vote::Count';
10  
11 3 our $VERSION='1.10';
12  
13 =head1 NAME
14  
15 Vote::Count::Method::CondorcetIRV
16  
17 =head1 VERSION 1.10
18  
19 =cut
20  
21 # ABSTRACT: Simple Condorcet IRV Methods.
22  
23 =pod
24  
25 =head1 SYNOPSIS
26  
27 use Vote::Count::Method::CondorcetIRV ;
28  
29 my $Election = Vote::Count::Method::CondorcetIRV->new(
30 'BallotSet' => $someballotset,
31 'TieBreakMethod' => 'precedence', # defaults to all
32 );
33 my $result = $Election->SmithSetIRV() ;
34 say "Winner is: " . $result->{'winner'};
35 say $Election->logv();
36  
37 =head1 Description
38  
39 Provides Common Basic Condorcet-IRV Methods. These methods are simple and beat other Condorcet Methods on Later Harm.
40  
41 =head1 Method Common Names: Smith Set IRV, Smith-IRV
42  
43 Identifies the Smith Set and runs IRV on it.
44  
45 =head2 Function Name: SmithSetIRV
46  
47 SmithSetIRV is exported and requires a Vote::Count object, an optional second argument is an IRV tiebreaker rule name (see IRV module). It will return a hashref similar to RunIRV, in the event of a tie the Vote::Count Object's Active Set will also be the tied choices (available for any later tie breakers you would implement). Events will be logged to the Vote::Count Object.
48  
49 =head2 Criteria
50  
51 =head3 Simplicity
52  
53 SmithSet IRV is easy to understand but requires a full matrix and thus is harder to handcount than Benham. If it desired to handcount, an aggressive Floor Rule like TCA (see Floor module) is recommended, or an Approval or Top Count Floor of up to 15%. 15% Top Count permits at most 6 choices, but 6 choices still require 15 pairings to complete the Matrix.
54  
55 =head3 Later Harm
56  
57 When there is no Condorcet Winner this method is Later Harm Sufficient. There might be edge cases where IRV's sensitivity to dropping order creates a Later Harm effect, but they should be pretty rare. When there is a Condorcet Winner the effect is the normal one for a Condorcet Method.
58  
59 The easiest way to imagine a case where a choice not in the Smith Set changed the outcome is by cloning the winner, such that there is a choice defeating them in early Top Count but not defeating them. The negative impact of the clone is an established weakness of IRV. It would appear that any possible Later Harm issue in addition to being very much at the edge is more than offset by consistency improvement.
60  
61 Smith Set IRV still inherits the Later Harm failure of requiring a Condorcet Winner, but it has the lowest possible Later Harm effect for a Smith compliant Method. Woodhull and restricting Pairwise Opposition to the Smith Set have equal Later Harm effect to Smith Set IRV.
62  
63 =head3 Condorcet Criteria
64  
65 Meets Condorcer Winner, Condorcet Loser, and Smith.
66  
67 =head3 Consistency
68  
69 By meeting the three Condorcet Criteria a level of consistency is guaranteed. When there is no Condorcet Winner the resolution has all of the weaknesses of IRV, as discussed in the Later Harm topic above restricting IRV to the Smith Set would appear to provide a consistency gain over basic IRV.
70  
71 Smith Set IRV is therefore substantially more consistent than basic IRV, but less consistent than Condorcet methods like SSD that focus on Consistency.
72  
73 =head1 Smith Set Restricted MinMax (Currently Unimplemented, See Vote::Count::Method::MinMax)
74  
75 MinMax methods do not meet the Smith Criteria nor the Condorcet Loser Criteria, two do meet the Condorcet Winner Criteria, and one meets Later Harm. Restricting MinMax to the Smith Set will make all of the sub-methods meet all three Condorcet Criteria; "Opposition" will match the Later Harm protection of Smith Set IRV.
76  
77 =head1 Method Common Name: Woodhull Method (Currently Unimplemented)
78  
79 The Woodhull method is similar to Smith Set IRV. The difference is: instead of eliminating the choices outside the Smith Set, Woodhull does not permit them to win. Since, it has to deal with the situation where an ineligible choice wins via IRV, it becomes slightly more complex. In addition, group elimination of unwinnable choices slightly improves consistency, which is another advantage to Smith Set IRV. As for possible differences in Later Harm effect, the Later Harm comes from the restriction of the victor to the Smith Set, which is the same effect for both methods.
80  
81 The argument in favor of Woodhull over Smith would be that: Anything which alters the dropping order can alter the outcome of IRV, and Woodhull preserves the IRV dropping order. Since, a dropping order change has an equal possiblity of helping or hurting one's preferred choice, this side-effect is a random flaw. Removing the least consequential choices is preventing them from impacting the election (in a random manner), thus this author sees it as an advantage for Smith Set IRV.
82  
83 =cut
84  
85 3 ▶no warnings 'experimental';
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 6 ▶sub SmithSetIRV ( $E, $tiebreaker = 'all' ) {
Subroutine SmithSetIRV: called CC=4 SCAR=13.9
Pod documented
90 6 my $matrix = $E->PairMatrix();
91 6 $E->logt('SmithSetIRV');
92 6 my $winner = $matrix->CondorcetWinner();
93 6 ▶ if ($winner) {
Branch: 1 branch
BranchTrueFalseTotal
if ($winner) { } 2 4 6
94 2 $E->logv("Condorcet Winner: $winner");
95 return {
96 2 'winner' => $winner,
97 'tied' => 0
98 };
99 }
100 else {
101 4 my $Smith = $matrix->SmithSet();
102 4 $E->logv( "Smith Set: " . join( ',', sort( keys $Smith->%* ) ) );
103 4 my $IRV = $E->RunIRV( $Smith, $tiebreaker );
104 4 ▶ unless ( $IRV->{'winner'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($IRV->{"winner"}) 1 3 4
105 1 $winner = '';
106 1 $E->SetActive( { map { $_ => 1 } ( $IRV->{'tied'}->@* ) } );
107 }
108 4 return $IRV;
109 }
110 }
111  
112 3 1;
113  
114 #FOOTER
115  
116 =pod
117  
118 BUG TRACKER
119  
120 L<https://github.com/brainbuz/Vote-Count/issues>
121  
122 AUTHOR
123  
124 John Karr (BRAINBUZ) brainbuz@cpan.org
125  
126 CONTRIBUTORS
127  
128 Copyright 2019-2020 by John Karr (BRAINBUZ) brainbuz@cpan.org.
129  
130 LICENSE
131  
132 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>.
133  
134 =cut
135  
« Count/Log.pm ↑ Summary Count.pm »