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             package Vote::Count::BottomRunOff;
2 39     39   38659 use Moose::Role;
  39         99  
  39         355  
3              
4 39     39   202947 use 5.024;
  39         143  
5 39     39   239 no warnings 'experimental';
  39         86  
  39         1875  
6 39     39   271 use feature ('signatures');
  39         108  
  39         4505  
7 39     39   279 use Carp;
  39         91  
  39         2990  
8 39     39   254 use Data::Dumper;
  39         82  
  39         1964  
9 39     39   24881 use Data::Printer;
  39         1112432  
  39         284  
10              
11             our $VERSION = '2.01';
12              
13             =head1 NAME
14              
15             Vote::Count::BottomRunOff
16              
17             =head1 VERSION 2.01
18              
19             =head2 Description
20              
21             Bottom RunOff is an elimination method which takes the two lowest choices, the choice which would lose a runoff is eliminated.
22              
23             =head1 Synopsis
24              
25             my $eliminate = $Election->BottomRunOff();
26             # log the pairing result
27             $Election->logd( $eliminate->{'runoff'} );
28             # log elimination in the short log too.
29             $Election->logt( "eliminated ${\ $eliminate->{'eliminate'} }.");
30             # Perform the elimination
31             $Election->Defeat( $eliminate->{'eliminate'} );
32              
33             =head1 BottomRunOff
34              
35             The TieBreakMethod must either be 'precedence' or TieBreakerFallBackPrecedence must be true or BottomRunOff will die. Takes an optional named parameter of an active set.
36              
37             my $result = $Election->BottomRunOff();
38             my $result = $Election->BottomRunOff( 'active' => $active );
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             =cut
45              
46 39     39 0 12218 sub BottomRunOff ( $Election, %args ) {
  39         92  
  39         166  
  39         73  
47             # IRV segregates its active set so BottomRunOff needs to accept one
48             my $active = defined $args{'active'}
49 39 100       200 ? $args{'active'}
50             : $Election->GetActive ;
51              
52 39 100       216 my $ranking2 = $args{'ranking2'} ? $args{'ranking2'} : 'Precedence';
53 39         445 my @ranked = $Election->UnTieList(
54             'ranking1' => 'TopCount',
55             'ranking2' => $ranking2,
56             'tied' => [ keys $active->%* ],
57             );
58              
59 38         1494 my $pairing =
60             $Election->PairMatrix()->GetPairResult( $ranked[-2], $ranked[-1] );
61 38         97 my $continuing = $pairing->{'winner'};
62 38         115 my $eliminate = $pairing->{'loser'};
63             # pairing should never be a tie because precedence must be enabled,
64             # there should be no ties in the Matrix.
65 38         211 my $runoffmsg =
66             qq/Elimination Runoff: *$continuing* $pairing->{$continuing} > $eliminate $pairing->{$eliminate}/;
67             return {
68 38         378 eliminate => $eliminate,
69             continuing => $continuing,
70             runoff => $runoffmsg
71             };
72             }
73              
74             1;
75              
76             #FOOTER
77              
78             =pod
79              
80             BUG TRACKER
81              
82             L<https://github.com/brainbuz/Vote-Count/issues>
83              
84             AUTHOR
85              
86             John Karr (BRAINBUZ) brainbuz@cpan.org
87              
88             CONTRIBUTORS
89              
90             Copyright 2019-2021 by John Karr (BRAINBUZ) brainbuz@cpan.org.
91              
92             LICENSE
93              
94             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>.
95              
96             SUPPORT
97              
98             This software is provided as is, per the terms of the GNU Public License. Professional support and customisation services are available from the author.
99              
100             =cut
101