Optimisation: Do not re-sort already sorted parcels in exclusion by_value
This commit is contained in:
parent
6d3e283d1d
commit
673b531475
@ -538,6 +538,7 @@ class WIGSTVCounter(BaseSTVCounter):
|
|||||||
if len(cand_ballots) > 0:
|
if len(cand_ballots) > 0:
|
||||||
__pragma__('opov')
|
__pragma__('opov')
|
||||||
self.candidates[candidate].parcels.append(new_parcel)
|
self.candidates[candidate].parcels.append(new_parcel)
|
||||||
|
self.candidates[candidate]._parcels_sorted = False
|
||||||
__pragma__('noopov')
|
__pragma__('noopov')
|
||||||
|
|
||||||
__pragma__('opov')
|
__pragma__('opov')
|
||||||
@ -590,12 +591,14 @@ class WIGSTVCounter(BaseSTVCounter):
|
|||||||
count_card.parcels.remove(parcel)
|
count_card.parcels.remove(parcel)
|
||||||
elif self.options['exclusion'] == 'by_value':
|
elif self.options['exclusion'] == 'by_value':
|
||||||
# Sort the ballots by value
|
# Sort the ballots by value
|
||||||
|
if not count_card._parcels_sorted:
|
||||||
ballots = [(b, bv) for p in count_card.parcels for b, bv in p]
|
ballots = [(b, bv) for p in count_card.parcels for b, bv in p]
|
||||||
__pragma__('opov')
|
__pragma__('opov')
|
||||||
ballots.sort(key=lambda x: x[1] / x[0].value, reverse=True)
|
ballots.sort(key=lambda x: x[1] / x[0].value, reverse=True)
|
||||||
# Round to 8 decimal places to consider equality
|
# Round to 8 decimal places to consider equality
|
||||||
# FIXME: Work out a better way of doing this
|
# FIXME: Work out a better way of doing this
|
||||||
count_card.parcels = groupby(ballots, lambda x: (x[1] / x[0].value).round(8, x[1].ROUND_DOWN))
|
count_card.parcels = groupby(ballots, lambda x: (x[1] / x[0].value).round(8, x[1].ROUND_DOWN))
|
||||||
|
count_card._parcels_sorted = True
|
||||||
__pragma__('noopov')
|
__pragma__('noopov')
|
||||||
|
|
||||||
if len(count_card.parcels) > 0:
|
if len(count_card.parcels) > 0:
|
||||||
@ -618,6 +621,7 @@ class WIGSTVCounter(BaseSTVCounter):
|
|||||||
if len(cand_ballots) > 0:
|
if len(cand_ballots) > 0:
|
||||||
__pragma__('opov')
|
__pragma__('opov')
|
||||||
self.candidates[candidate].parcels.append(new_parcel)
|
self.candidates[candidate].parcels.append(new_parcel)
|
||||||
|
self.candidates[candidate]._parcels_sorted = False
|
||||||
__pragma__('noopov')
|
__pragma__('noopov')
|
||||||
|
|
||||||
__pragma__('opov')
|
__pragma__('opov')
|
||||||
@ -669,6 +673,7 @@ class UIGSTVCounter(WIGSTVCounter):
|
|||||||
if len(cand_ballots) > 0:
|
if len(cand_ballots) > 0:
|
||||||
__pragma__('opov')
|
__pragma__('opov')
|
||||||
self.candidates[candidate].parcels.append(new_parcel)
|
self.candidates[candidate].parcels.append(new_parcel)
|
||||||
|
self.candidates[candidate]._parcels_sorted = False
|
||||||
__pragma__('noopov')
|
__pragma__('noopov')
|
||||||
|
|
||||||
__pragma__('opov')
|
__pragma__('opov')
|
||||||
@ -736,6 +741,7 @@ class EGSTVCounter(UIGSTVCounter):
|
|||||||
if len(cand_ballots) > 0:
|
if len(cand_ballots) > 0:
|
||||||
__pragma__('opov')
|
__pragma__('opov')
|
||||||
self.candidates[candidate].parcels.append(new_parcel)
|
self.candidates[candidate].parcels.append(new_parcel)
|
||||||
|
self.candidates[candidate]._parcels_sorted = False
|
||||||
__pragma__('noopov')
|
__pragma__('noopov')
|
||||||
|
|
||||||
__pragma__('opov')
|
__pragma__('opov')
|
||||||
|
@ -71,6 +71,7 @@ class CountCard:
|
|||||||
# Parcel = List[Tuple[Ballot, Num]]
|
# Parcel = List[Tuple[Ballot, Num]]
|
||||||
# The exhausted/loss to fraction piles will have only one parcel
|
# The exhausted/loss to fraction piles will have only one parcel
|
||||||
self.parcels = []
|
self.parcels = []
|
||||||
|
self._parcels_sorted = False # Optimisation to avoid re-sorting in exclusion by_value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def votes(self):
|
def votes(self):
|
||||||
|
Reference in New Issue
Block a user