line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
6100
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
93
|
|
2
|
2
|
|
|
2
|
|
16
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
65
|
|
3
|
2
|
|
|
2
|
|
60
|
use 5.024; |
|
2
|
|
|
|
|
10
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Vote::Count::Helper::NthApproval; |
6
|
2
|
|
|
2
|
|
12
|
use Moose::Role; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
21
|
|
7
|
2
|
|
|
2
|
|
12265
|
no warnings 'experimental'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
120
|
|
8
|
2
|
|
|
2
|
|
13
|
use feature qw /postderef signatures/; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
789
|
|
9
|
|
|
|
|
|
|
# use Vote::Count::TextTableTiny qw/generate_table/; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION='2.00'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ABSTRACT: Nth Approval Defeat rule for STV elections. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Vote::Count::Helper::NthApproval |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 VERSION 2.00 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=pod |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
package MySTVElection; |
28
|
|
|
|
|
|
|
use Moose; |
29
|
|
|
|
|
|
|
extends 'Vote::Count::Charge'; |
30
|
|
|
|
|
|
|
with 'Vote::Count::Charge::NthApproval'; |
31
|
|
|
|
|
|
|
for my $defeat ( NthApproval( $STV_Election ) ) { |
32
|
|
|
|
|
|
|
$STV_Election->Defeat( $defeat ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 NthApproval |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Finds the choice that would fill the last seat if the remaining seats were to be filled by highest Top Count, and sets the Vote Value for that Choice as the requirement. All Choices that do not have a weighted Approval greater than that requirement are returned, they will never be elected and are safe to defeat immediately. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Results are logged to the verbose log. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This rule is not strictly LNH safe. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
4
|
0
|
63
|
sub NthApproval ( $I ) { |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
9
|
|
46
|
4
|
|
|
|
|
32
|
my $tc = $I->TopCount(); |
47
|
4
|
|
|
|
|
77
|
my $ac = $I->Approval(); |
48
|
4
|
|
|
|
|
141
|
my $seats = $I->Seats() - $I->Elected(); |
49
|
4
|
|
|
|
|
12
|
my @defeat = (); |
50
|
4
|
|
|
|
|
136
|
my $bottomrunning = $tc->HashByRank()->{$seats}[0]; |
51
|
4
|
|
|
|
|
19
|
my $bar = $tc->RawCount()->{$bottomrunning}; |
52
|
4
|
|
|
|
|
19
|
for my $A ( $I->GetActiveList ) { |
53
|
25
|
100
|
|
|
|
60
|
next if $A eq $bottomrunning; |
54
|
21
|
|
|
|
|
34
|
my $avv = $ac->{'rawcount'}{$A}; |
55
|
21
|
100
|
|
|
|
132
|
push @defeat, ($A) if $avv <= $bar; |
56
|
|
|
|
|
|
|
} |
57
|
4
|
50
|
|
|
|
17
|
if (@defeat) { |
58
|
4
|
|
|
|
|
27
|
$I->logv( qq/ |
59
|
|
|
|
|
|
|
Seats: $seats Choice $seats: $bottomrunning ( $bar ) |
60
|
4
|
|
|
|
|
40
|
Choices Not Over $bar by Weighted Approval: ${\ join( ', ', @defeat ) } |
61
|
|
|
|
|
|
|
/); |
62
|
|
|
|
|
|
|
} |
63
|
4
|
|
|
|
|
96
|
return @defeat; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#FOOTER |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=pod |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
BUG TRACKER |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
L<https://github.com/brainbuz/Vote-Count/issues> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
AUTHOR |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
John Karr (BRAINBUZ) brainbuz@cpan.org |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
CONTRIBUTORS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Copyright 2019-2021 by John Karr (BRAINBUZ) brainbuz@cpan.org. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
LICENSE |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
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>. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
SUPPORT |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This software is provided as is, per the terms of the GNU Public License. Professional support and customisation services are available from the author. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|