From 64d23751a5e5fb8074f5f5bbe87b59ddefa74822 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Mon, 4 Jan 2021 20:46:18 +1100 Subject: [PATCH] Fix bugs in ERS97 implementation Re-calculate votes required for election after electing a candidate Round votes required for election up in accordance with vote rounding --- pyRCV2/method/base_stv.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyRCV2/method/base_stv.py b/pyRCV2/method/base_stv.py index ffb167a..f1647de 100644 --- a/pyRCV2/method/base_stv.py +++ b/pyRCV2/method/base_stv.py @@ -530,11 +530,15 @@ class BaseSTVCounter: self.quota = self.quota.round(self.options['round_quota'], self.quota.ROUND_UP) __pragma__('noopov') - if self.options['quota_mode'] == 'ers97': + if self.options['quota_mode'] == 'ers97' and self.num_elected < self.election.seats: # Calculate the total active vote __pragma__('opov') - total_active_vote = sum((cc.votes for c, cc in self.candidates.items() if cc.state == CandidateState.HOPEFUL), Num('0')) + sum((cc.votes - self.quota for c, cc in self.candidates.items() if cc.votes > self.quota), Num('0')) + 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')) 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) __pragma__('noopov') def meets_quota(self, count_card): @@ -576,6 +580,7 @@ class BaseSTVCounter: meets_quota.remove(x) if self.options['quota_mode'] == 'ers97': + self.compute_quota() self.elect_meeting_quota() # Repeat as the vote required for election may have changed # -----------------