Reweighted range voting: Difference between revisions

Content added Content deleted
mNo edit summary
(Added python for RRV. Same code as SPAV roughly.)
Line 1: Line 1:
<br>
<br>
[[File:RRV Procedure.svg|thumb|RRV Procedure]]
[[File:RRV Procedure.svg|thumb|RRV Procedure]]


Line 35: Line 37:
# The remaining candidate with the highest total reweighted score wins each seat available- up until the final seat up for election.
# The remaining candidate with the highest total reweighted score wins each seat available- up until the final seat up for election.
# For the final seat available, the two highest-scoring candidates remaining runoff, with the candidate preferred (scored higher) by more reweighted ballots winning the final seat.
# For the final seat available, the two highest-scoring candidates remaining runoff, with the candidate preferred (scored higher) by more reweighted ballots winning the final seat.

==Example Code==
<syntaxhighlight lang="python" line>
import pandas

ballots = [
{"Red": 5, "Green": 0, "Yellow": 3, "Blue": 5},
{"Red": 5, "Green": 0, "Yellow": 0, "Blue": 4},
{"Red": 0, "Green": 5, "Yellow": 0, "Blue": 1},
{"Red": 1, "Green": 2, "Yellow": 4, "Blue": 3},
{"Red": 1, "Green": 0, "Yellow": 2, "Blue": 0},
{"Red": 1, "Green": 3, "Yellow": 0, "Blue": 1},
{"Red": 0, "Green": 0, "Yellow": 5, "Blue": 0},
{"Red": 5, "Green": 0, "Yellow": 0, "Blue": 4},
]

seats = 4
seated = []
max_score = max(max(ballot.values()) for ballot in ballots)

#reweight
def reweight(ballot):
seated_scores = [
ballot[candidate] for candidate in ballot if candidate in seated
]
weight = 1/(1+sum(seated_scores)/max_score)
return {candidate: weight*ballot[candidate] for candidate in ballot}

def nextRound(ballots):
reweightedBallots = [reweight(ballot) for ballot in ballots]
winner = pandas.DataFrame(reweightedBallots).sum().drop(seated).idxmax()
print(pandas.DataFrame(reweightedBallots).sum())
seated.append(winner)
return reweightedBallots

while len(seated) < seats:
nextRound(ballots)
print(seated)
</syntaxhighlight>
<syntaxhighlight lang="" line>
Red 18.0
Green 10.0
Yellow 14.0
Blue 18.0
dtype: float64
['Red']
Red 10.000000
Green 9.166667
Yellow 11.500000
Blue 10.833333
dtype: float64
['Red', 'Yellow']
Red 8.881410
Green 8.500000
Yellow 6.903846
Blue 9.256410
dtype: float64
['Red', 'Yellow', 'Blue']
Red 6.684219
Green 7.078755
Yellow 6.121795
Blue 6.947497
dtype: float64
['Red', 'Yellow', 'Blue', 'Green']
</syntaxhighlight>


==Related Systems==
==Related Systems==