-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.py
121 lines (108 loc) · 4.02 KB
/
examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
""" Examples from
Paul Harrenstein, Marie-Louise Lackner, and Martin Lackner.
*A Mathematical Analysis of an Election System Proposed by
Gottlob Frege*. To appear in Erkenntnis. 2020.
Preprint: https://arxiv.org/abs/1907.03643
"""
from __future__ import print_function
from frege import frege, modfrege
import apportionment
print("************************************************")
print("Example 1 (Frege's original method)")
profile = [5, 3, 2]
k = 10
print("input (fixed electorate): ", profile)
print("rounds: ", k)
print("representatives distribution:", frege(profile, k))
print("details (verbose=True):")
frege(profile, k, verbose=True)
print()
print("************************************************")
print("Example 2 (Frege's original method)")
profile = [1, 1, 1, 1, 1, 5]
k = 17
print("input (fixed electorate): ", profile)
print("rounds: ", k)
print("representatives distribution:", frege(profile, k))
print("details (verbose=True):")
frege(profile, k, verbose=True)
print()
print("************************************************")
print("Example 3 (Frege's original method)")
print("Frege's original method with variable electorate")
print(" may not converge to quota")
profiles = []
k = 100
for i in range(k):
profiles.append([2**(i + 1), 2**i])
print("rounds: ", k)
print("representatives distribution:", frege(profiles))
print()
print("************************************************")
print("Example 4 (Frege's modified method)")
profile = [1, 1, 1, 1, 1, 5]
k = 10
print("input (fixed electorate): ", profile)
print("rounds: ", k)
print("representatives distribution:", modfrege(profile, k))
print("details (verbose=True):")
modfrege(profile, k, verbose=True)
print()
print("************************************************")
print("Example 4 (Frege's modified method)")
print("Frege's modified method violates variable lower quota")
print(" for m=6")
profile = [1001, 1000, 161, 151, 146, 141]
k = 13
print("input (fixed electorate): ", profile)
print("rounds: ", k)
print("representatives distribution:", modfrege(profile, k))
print("details (verbose=True):")
modfrege(profile, k, verbose=True, checkquota=True)
print()
print("************************************************")
print("Example 5 (Frege's modified method)")
print("Frege's modified method violates variable lower quota")
print(" for m=5")
profile = [1001, 1000, 300, 107, 92]
k = 15
print("input (fixed electorate): ", profile)
print("rounds: ", k)
print("representatives distribution:", modfrege(profile, k))
print("details (verbose=True):")
modfrege(profile, k, verbose=True, checkquota=True)
print()
print("************************************************")
print("Example 5 (Frege's modified method)")
print("Frege's modified method violates variable lower quota")
print(" for m=4")
profile = [1001, 1000, 115, 26]
k = 30
print("input (fixed electorate): ", profile)
print("rounds: ", k)
print("representatives distribution:",
modfrege(profile, k, tiebreakingallowed=False))
print("details (verbose=True):")
modfrege(profile, k, verbose=True, checkquota=True)
print()
print("************************************************")
print("Example 8 (apportionment)")
print("all apportionment methods yield different results")
methods = ["quota", "largest_remainder", "dhondt",
"saintelague", "huntington", "adams", "modfrege"]
distribution = (79, 7, 6, 3, 2, 1)
seats = 20
print("vote distribution : ", distribution)
print("seats: ", k)
print("\nresults: ")
for method in methods:
if method == "frege":
rep = frege(
distribution, seats, modifiedfrege=False, verbose=False)
elif method == "modfrege":
rep = frege(
distribution, seats, modifiedfrege=True, verbose=False)
else:
rep = apportionment.compute(
method, distribution, seats, tiesallowed=False, verbose=False)
print(method, "." * (25 - len(method)), rep)