File Coverage

blib/lib/Vote/Count/BottomRunOff.pm
Criterion Covered Total %
statement 32 32 100.0
branch 4 4 100.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 44 45 97.7


line stmt bran cond sub pod time code
1             use Moose::Role;
2 39     39   40530  
  39         111  
  39         387  
3             use 5.024;
4 39     39   223917 no warnings 'experimental';
  39         171  
5 39     39   238 use feature ('signatures');
  39         92  
  39         1689  
6 39     39   334 use Carp;
  39         142  
  39         4688  
7 39     39   370 use Data::Dumper;
  39         115  
  39         3217  
8 39     39   287 use Data::Printer;
  39         91  
  39         2207  
9 39     39   22682  
  39         1166608  
  39         295  
10             our $VERSION='2.02';
11              
12             =head1 NAME
13              
14             Vote::Count::BottomRunOff
15              
16             =head1 VERSION 2.02
17              
18             =head2 Description
19              
20             Bottom RunOff is an elimination method which takes the two lowest choices, the choice which would lose a runoff is eliminated.
21              
22             =head1 Synopsis
23              
24             my $eliminate = $Election->BottomRunOff();
25             # log the pairing result
26             $Election->logd( $eliminate->{'runoff'} );
27             # log elimination in the short log too.
28             $Election->logt( "eliminated ${\ $eliminate->{'eliminate'} }.");
29             # Perform the elimination
30             $Election->Defeat( $eliminate->{'eliminate'} );
31              
32             =head1 BottomRunOff
33              
34             The TieBreakMethod must either be 'precedence' or TieBreakerFallBackPrecedence must be true or BottomRunOff will die. Takes an optional named parameter of an active set.
35              
36             my $result = $Election->BottomRunOff();
37             my $result = $Election->BottomRunOff( 'active' => $active );
38             my $result = $Election->BottomRunOff( 'ranking2' => $othermethod );
39              
40             Orders the Choices according to Top Count and uses Precedence to resolve any equal rankings. Then conducts a runoff between the two lowest choices in the order.
41              
42             The returned value is a hashref with the keys: B<eliminate>, B<continuing>, and B<runoff>, runoff describes the totals for the two choices in the runoff.
43              
44             The optional values are B<ranking2> and B<active>. See UnTieList in L<Vote::Count::TieBreaker|Vote::Count::TieBreaker/UnTieList>, the B<ranking1> passed to it is always B<TopCount>. B<active> is used to provide a hashref to override the current active list.
45              
46             =cut
47              
48             # IRV segregates its active set so BottomRunOff needs to accept one
49 39     39 0 10761 my $active = defined $args{'active'}
  39         66  
  39         87  
  39         56  
50             ? $args{'active'}
51             : $Election->GetActive ;
52 39 100       122  
53             my $ranking2 = $args{'ranking2'} ? $args{'ranking2'} : 'Precedence';
54             my @ranked = $Election->UnTieList(
55 39 100       110 'ranking1' => 'TopCount',
56 39         222 'ranking2' => $ranking2,
57             'tied' => [ keys $active->%* ],
58             );
59              
60             my $pairing =
61             $Election->PairMatrix()->GetPairResult( $ranked[-2], $ranked[-1] );
62 38         1216 my $continuing = $pairing->{'winner'};
63             my $eliminate = $pairing->{'loser'};
64 38         88 # pairing should never be a tie because precedence must be enabled,
65 38         71 # there should be no ties in the Matrix.
66             my $runoffmsg =
67             qq/Elimination Runoff: *$continuing* $pairing->{$continuing} > $eliminate $pairing->{$eliminate}/;
68 38         146 return {
69             eliminate => $eliminate,
70             continuing => $continuing,
71 38         244 runoff => $runoffmsg
72             };
73             }
74              
75             1;
76              
77             #FOOTER
78              
79             =pod
80              
81             BUG TRACKER
82              
83             L<https://github.com/brainbuz/Vote-Count/issues>
84              
85             AUTHOR
86              
87             John Karr (BRAINBUZ) brainbuz@cpan.org
88              
89             CONTRIBUTORS
90              
91             Copyright 2019-2021 by John Karr (BRAINBUZ) brainbuz@cpan.org.
92              
93             LICENSE
94              
95             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>.
96              
97             SUPPORT
98              
99             This software is provided as is, per the terms of the GNU Public License. Professional support and customisation services are available from the author.
100              
101             =cut
102