Created
June 17, 2019 07:31
-
-
Save joriki/f30671d3390b13e762ad071c7ffbae6f to your computer and use it in GitHub Desktop.
Allocate seats according to Sainte-Laguë
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jetzt.bewegung; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
public class SainteLaguë { | |
// Sitzzuteilung an die Landeslisten der CDU zur Europawahl 2019 | |
final static int seatTotal = 23; | |
final static int [] votes = { | |
353789, | |
140023, | |
1119078, | |
63814, | |
2237476, | |
657840, | |
613835, | |
1498629, | |
161895, | |
229251 - 26143, | |
215542, | |
184840, | |
474633, | |
226540, | |
259908, | |
}; | |
final static String [] names = { | |
"Schleswig-Holstein", | |
"Hamburg", | |
"Niedersachsen", | |
"Bremen", | |
"Nordrhein-Westfalen", | |
"Hessen", | |
"Rheinland-Pfalz", | |
"Baden-Württemberg", | |
"Saarland", | |
"Berlin", | |
"Brandenburg", | |
"Mecklenburg-Vorpommern", | |
"Sachsen", | |
"Sachsen-Anhalt", | |
"Thüringen", | |
}; | |
/* Sitzzuteilung an die Parteien zur Europawahl 2019 | |
Für einen Sitz waren 187210 Stimmen erforderlich, also 187210 / 37389231 = 0.5007%. | |
DiE fehlten 57138 Stimmen. | |
final static int seatTotal = 96; | |
final static int [] votes = { | |
8437093, | |
5914953, | |
7675584, | |
2056010, | |
4103453, | |
2354817, | |
2028353, | |
806590, | |
243363, | |
541984, | |
101323, | |
273755, | |
370006, | |
898386, | |
58541, | |
81881, | |
20419, | |
18340, | |
5293, | |
99731, | |
68597, | |
66228, | |
68654, | |
40834, | |
25530, | |
130072, | |
12822, | |
71282, | |
24627, | |
27814, | |
33152, | |
55258, | |
76172, | |
43965, | |
34447, | |
15943, | |
35794, | |
62613, | |
85722, | |
71006, | |
248824, | |
}; | |
final static String [] names = { | |
"CDU", | |
"SPD", | |
"GRÜNE", | |
"DIE LINKE", | |
"AfD", | |
"CSU", | |
"FDP", | |
"FREIE WÄHLER", | |
"PIRATEN", | |
"Tierschutzpartei", | |
"NPD", | |
"FAMILIE", | |
"ÖDP", | |
"Die PARTEI", | |
"Volksabstimmung", | |
"BP", | |
"DKP", | |
"MLPD", | |
"SGP", | |
"TIERSCHUTZ hier!", | |
"Tierschutzallianz", | |
"Bündnis C", | |
"BIG", | |
"BGE", | |
"DIE DIREKTE!", | |
"DiEM25", | |
"III. Weg", | |
"Die Grauen", | |
"DIE RECHTE", | |
"DIE VIOLETTEN", | |
"LIEBE", | |
"DIE FRAUEN", | |
"Graue Panther", | |
"LKR", | |
"MENSCHLICHE WELT", | |
"NL", | |
"ÖkoLinX", | |
"Die Humanisten", | |
"PARTEI FÜR DIE TIERE", | |
"Gesundheitsforschung", | |
"Volt", | |
}; | |
*/ | |
/* Sitzzuteilung an die Parteien bei der Gemeinderatswahl in Tübingen 2019 | |
final static int seatTotal = 40; | |
final static String [] names = { | |
"Grüne", | |
"CDU", | |
"SPD", | |
"Tübinger Liste", | |
"Linke", | |
"FDP", | |
"PARTEI", | |
"DiB", | |
"AfD" | |
}; | |
final static int [] votes = { | |
610681, | |
231758, | |
245550, | |
245084, | |
197343, | |
100218, | |
73081, | |
46216, | |
16237 | |
}; | |
*/ | |
public static void main(String [] args) { | |
doSainteLaguë(Arrays.stream(votes).boxed().collect(Collectors.toList()), Arrays.asList(names),seatTotal); | |
} | |
static class Party implements Comparable<Party> { | |
String name; | |
int vote; | |
int divisor; | |
int seats; | |
public Party(String name,int vote,int divisor) { | |
this.name = name; | |
this.vote = vote; | |
this.divisor = divisor; | |
} | |
public int compareTo(Party o) { | |
return vote * o.divisor - divisor * o.vote; | |
} | |
} | |
static void doSainteLaguë(List<Integer> votes,List<String> names,int nseats) { | |
if (votes.size() != names.size()) | |
throw new IllegalArgumentException(); | |
List<Party> parties = new ArrayList<>(); | |
for (int i = 0;i < votes.size();i++) | |
parties.add(new Party(names.get(i),votes.get(i),1)); | |
while (nseats-- > 0) { | |
Party party = Collections.max(parties); | |
System.out.println(party.name + " : " + party.vote / (double) party.divisor); | |
party.seats++; | |
party.divisor += 2; | |
} | |
System.out.println(); | |
for (Party party : parties) | |
if (party.seats != 0) | |
System.out.println(party.name + " : " + party.seats); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment