From c3c2fed4442ada6082812b50c00e6427720b67b9 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sat, 9 Jan 2021 04:51:34 +1100 Subject: [PATCH] Correct bug/logic error in ERS97 Do not double-count surpluses of elected candidates towards total active vote --- pyRCV2/method/base_stv.py | 6 ++++-- tests/test_ers97.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyRCV2/method/base_stv.py b/pyRCV2/method/base_stv.py index c11af83..4634473 100644 --- a/pyRCV2/method/base_stv.py +++ b/pyRCV2/method/base_stv.py @@ -478,7 +478,7 @@ class BaseSTVCounter: orig_vre = self.vote_required_election 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 - 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) 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) @@ -528,8 +528,10 @@ class BaseSTVCounter: 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': - self.compute_quota() self.elect_meeting_quota() # Repeat as the vote required for election may have changed return diff --git a/tests/test_ers97.py b/tests/test_ers97.py index 3cf8635..9e091b0 100644 --- a/tests/test_ers97.py +++ b/tests/test_ers97.py @@ -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)] @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""" pyRCV2.numbers.set_numclass(pyRCV2.numbers.Fixed)