Count/BottomRunOff.pm

filter: Statementstmt 100% 30 / 30 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 97.6% 42 / 43 CC 3 SCAR 4.7
CC
3
Cov
100%
BottomRunOff
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« Count/Method/CondorcetIRV.pm ↑ Summary
1 package Vote::Count::BottomRunOff;
2 39 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 39 ▶use 5.024;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶no warnings 'experimental';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 39 ▶use feature ('signatures');
Subroutine BEGIN: called CC=1 SCAR=0.0
7 39 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 39 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 39 ▶use Data::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 39 our $VERSION='2.02';
12  
13 =head1 NAME
14  
15 Vote::Count::BottomRunOff
16  
17 =head1 VERSION 2.02
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 my $result = $Election->BottomRunOff( 'ranking2' => $othermethod );
40  
41 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.
42  
43 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.
44  
45 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.
46  
47 =cut
48  
49 ▶sub BottomRunOff ( $Election, %args ) {
Subroutine BottomRunOff: called CC=3 SCAR=11.0
Pod undocumented
50 # IRV segregates its active set so BottomRunOff needs to accept one
51 my $active = defined $args{'active'}
52 39 ▶ ? $args{'active'}
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'active'} ? : 28 11 39
53 : $Election->GetActive ;
54  
55 39 ▶ my $ranking2 = $args{'ranking2'} ? $args{'ranking2'} : 'Precedence';
Branch: 1 branch
BranchTrueFalseTotal
$args{'ranking2'} ? : 29 10 39
56 39 my @ranked = $Election->UnTieList(
57 'ranking1' => 'TopCount',
58 'ranking2' => $ranking2,
59 'tied' => [ keys $active->%* ],
60 );
61  
62 38 my $pairing =
63 $Election->PairMatrix()->GetPairResult( $ranked[-2], $ranked[-1] );
64 38 my $continuing = $pairing->{'winner'};
65 38 my $eliminate = $pairing->{'loser'};
66 # pairing should never be a tie because precedence must be enabled,
67 # there should be no ties in the Matrix.
68 38 my $runoffmsg =
69 qq/Elimination Runoff: *$continuing* $pairing->{$continuing} > $eliminate $pairing->{$eliminate}/;
70 return {
71 38 eliminate => $eliminate,
72 continuing => $continuing,
73 runoff => $runoffmsg
74 };
75 }
76  
77 39 1;
78  
79 #FOOTER
80  
81 =pod
82  
83 BUG TRACKER
84  
85 L<https://github.com/brainbuz/Vote-Count/issues>
86  
87 AUTHOR
88  
89 John Karr (BRAINBUZ) brainbuz@cpan.org
90  
91 CONTRIBUTORS
92  
93 Copyright 2019-2021 by John Karr (BRAINBUZ) brainbuz@cpan.org.
94  
95 LICENSE
96  
97 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>.
98  
99 SUPPORT
100  
101 This software is provided as is, per the terms of the GNU Public License. Professional support and customisation services are available from the author.
102  
103 =cut
104  
« Count/Method/CondorcetIRV.pm ↑ Summary