Implememen backwards runoff
This commit is contained in:
parent
977ecf9d07
commit
f8226fa5a2
|
@ -43,11 +43,13 @@ def dump_ballots(ballots):
|
|||
for r in ballot:
|
||||
print(r)
|
||||
|
||||
def runoff(ballots):
|
||||
def runoff_forward(ballots):
|
||||
count = {}
|
||||
candidates = {}
|
||||
for ballot in ballots:
|
||||
for r in ballot:
|
||||
if r.id not in count or len(count[r.id]) < len(ballot):
|
||||
log.debug("count[%d] <- %d elements", r.id, len(ballot))
|
||||
count[r.id] = [0] * len(ballot)
|
||||
candidates[r.id] = r
|
||||
for ballot in ballots:
|
||||
|
@ -66,6 +68,21 @@ def runoff(ballots):
|
|||
]
|
||||
return loser, new_ballots
|
||||
|
||||
der runoff_backward(ballot):
|
||||
for ballot in ballots:
|
||||
for r in ballot:
|
||||
if r.id not in count or len(count[r.id]) < len(ballot):
|
||||
log.debug("count[%d] <- %d elements", r.id, len(ballot))
|
||||
count[r.id] = [0] * len(ballot)
|
||||
candidates[r.id] = r
|
||||
pprint(candidates)
|
||||
for ballot in ballots:
|
||||
for pos, r in enumerate(ballot):
|
||||
count[r.id][pos] += 1
|
||||
|
||||
pprint(count)
|
||||
return loser, new_ballots
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = get_args()
|
||||
|
||||
|
@ -74,7 +91,7 @@ if __name__ == "__main__":
|
|||
result = []
|
||||
while max(len(b) for b in ballots):
|
||||
dump_ballots(ballots)
|
||||
loser, ballots = runoff(ballots)
|
||||
loser, ballots = runoff_forward(ballots)
|
||||
result.append(loser)
|
||||
result = reversed(result)
|
||||
print("final result")
|
||||
|
|
Loading…
Reference in New Issue