apportionment/examples/alldifferent.py

30 wiersze
875 B
Python
Czysty Zwykły widok Historia

# Find vote distribution that produces a different apportionments
# for each of the specified apportionment methods
import apportionment.methods as app
from itertools import combinations
maxvoters = 20
parties = 5
seats = 20
methods = ["quota", "largest_remainder", "dhondt", "saintelague", "adams"]
2022-02-16 16:41:55 +00:00
for iterations, votes in enumerate(combinations(range(1, maxvoters + 1), parties)):
apportionments = set()
for method in methods:
2022-02-16 16:41:55 +00:00
apportionments.add(tuple(app.compute(method, votes, seats, verbose=False)))
if len(apportionments) == len(methods):
break
else:
print("No vote distribution found within the parameter range.")
quit()
print("votes = {}".format(votes))
print("found in {} iterations\n\n".format(iterations))
for method in methods:
2022-02-16 16:41:55 +00:00
print("{:>20s}: {}".format(method, app.compute(method, votes, seats, verbose=False)))