Correct bug/logic error in ERS97

Do not double-count surpluses of elected candidates towards total active vote
This commit is contained in:
RunasSudo 2021-01-09 04:51:34 +11:00
parent ede1da73ad
commit c3c2fed444
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 5 additions and 3 deletions

View File

@ -478,7 +478,7 @@ class BaseSTVCounter:
orig_vre = self.vote_required_election orig_vre = self.vote_required_election
total_active_vote = \ total_active_vote = \
sum((cc.votes for c, cc in self.candidates.items() if cc.state == CandidateState.HOPEFUL or cc.state == CandidateState.EXCLUDING), Num('0')) + \ sum((cc.votes for c, cc in self.candidates.items() if cc.state == CandidateState.HOPEFUL or cc.state == CandidateState.EXCLUDING), Num('0')) + \
sum((cc.votes - self.quota for c, cc in self.candidates.items() if cc.votes > self.quota), Num('0')) sum((cc.votes - self.quota for c, cc in self.candidates.items() if (cc.state == CandidateState.PROVISIONALLY_ELECTED or cc.state == CandidateState.DISTRIBUTING_SURPLUS or cc.state == CandidateState.ELECTED) and cc.votes > self.quota), Num('0'))
self.vote_required_election = total_active_vote / Num(self.election.seats - self.num_elected + 1) self.vote_required_election = total_active_vote / Num(self.election.seats - self.num_elected + 1)
if self.options['round_votes'] is not None: if self.options['round_votes'] is not None:
self.vote_required_election = self.vote_required_election.round(self.options['round_votes'], self.vote_required_election.ROUND_UP) self.vote_required_election = self.vote_required_election.round(self.options['round_votes'], self.vote_required_election.ROUND_UP)
@ -528,8 +528,10 @@ class BaseSTVCounter:
meets_quota.remove(x) meets_quota.remove(x)
if self.options['quota_mode'] == 'ers97':
self.compute_quota() # Vote required for election may have changed
if self.options['quota_mode'] == 'ers97': if self.options['quota_mode'] == 'ers97':
self.compute_quota()
self.elect_meeting_quota() # Repeat as the vote required for election may have changed self.elect_meeting_quota() # Repeat as the vote required for election may have changed
return return

View File

@ -32,7 +32,7 @@ with open('tests/data/ers97.csv', 'r', newline='') as f:
candidates = [data[i][0] for i in range(2, len(data) - 2)] candidates = [data[i][0] for i in range(2, len(data) - 2)]
@test_steps(*['Stage {}'.format(data[0][i]) for i in range(1, len(data[0]), 2)]) @test_steps(*['Stage {}'.format(data[0][i]) for i in range(1, len(data[0]), 2)])
def test_aec_tas19(): def test_ers97():
"""Compare count of ers97.blt with model result computed by hand""" """Compare count of ers97.blt with model result computed by hand"""
pyRCV2.numbers.set_numclass(pyRCV2.numbers.Fixed) pyRCV2.numbers.set_numclass(pyRCV2.numbers.Fixed)