Tutorial 1: Our first electoral system¶
Let’s start defining real elections that are plain and simple.
UK - General election (Caerfyrddin)¶
In the UK General election, a Parliament member is elected from each constituency using the first-past-the-post system.
For out example, we will define the Caerfyrddin constituency (2014 General election).
We will use the YAML format for electoral systems definitions:
Create a
districtand set an identifier:1name: Caerfyrddin constituency (2014 UK General election)Add the election method (
first-past-the-post). This method can be accessed by two keys: first_past_the_post and winner_takes_all.1name: Caerfyrddin constituency (2014 UK General election) 2method: first_past_the_post
Add votes for candidates:
1name: Caerfyrddin constituency (2014 UK General election) 2method: first_past_the_post 3candidates: 4- name: DAVIES, Ann 5 alliance: PC 6 votes: 15520 7- name: O'NEIL, Martha 8 alliance: Lab 9 votes: 10985 10- name: HART, Simon 11 alliance: Con 12 votes: 8825 13- name: HOLTON, Bernard 14 alliance: RUK 15 votes: 6944 16- name: BECKETT, Nick 17 alliance: LD 18 votes: 1461 19- name: BEASLEY, Will 20 alliance: Green 21 votes: 1371 22- name: COLE, Nancy 23 alliance: WEP 24 votes: 282 25- name: EVANS, David 26 alliance: WPB 27 votes: 216
We can add invalid votes inserting a special candidate whose name starts with
!:1name: Caerfyrddin constituency (2014 UK General election) 2method: first_past_the_post 3candidates: 4- name: "! invalid vote" 5 votes: 187 6- name: DAVIES, Ann 7 alliance: PC 8 votes: 15520 9- name: O'NEIL, Martha 10 alliance: Lab 11 votes: 10985 12- name: HART, Simon 13 alliance: Con 14 votes: 8825 15- name: HOLTON, Bernard 16 alliance: RUK 17 votes: 6944 18- name: BECKETT, Nick 19 alliance: LD 20 votes: 1461 21- name: BEASLEY, Will 22 alliance: Green 23 votes: 1371 24- name: COLE, Nancy 25 alliance: WEP 26 votes: 282 27- name: EVANS, David 28 alliance: WPB 29 votes: 216
There are two special candidates recognised by a name prefix:
Invalid votes, with prefix
!.Blank votes (valid empty votes), with prefix
?.
Candidates can be provided directly from file. That will be covered soon.
Save the file as
Caerfyrddin_2014.yaml.
Now, this system can be computed using the command interregnum-cli:
interregnum-cli calc Caerfyrddin_2014.yaml results.yaml
Spain - European Parliament¶
No regional districts are considered for the Spanish EU Parliament elections:
Seats are apportioned using the
highest averagesmethod withd'Hondt divisors.In addition to invalid votes, blank votes (valid votes to no candidate) are also considered.
In the year 2024 61 members of the European Parliament were allocated to Spain.
We can reuse the schema for the UK General election, but with some additions:
1name: Spain 2024 - European Parliament 2method: highest_averages 3method_params: 4 divisor_f: dhondt 5seats: 61 6candidates: 7- name: "! invalid vote" 8 votes: 124569 9- name: "? blank vote" 10 votes: 124655 11...
The
HighestAveragesAllocatorrequires a parameterdivisor_fwith the name of the divisor function:2method: highest_averages 3method_params: 4 divisor_f: dhondt 5seats: 61
Since there is a multi-seat allocation, seats need to be provided:
3method_params: 4 divisor_f: dhondt 5seats: 61 6candidates:
Blank vote is added as a special candidate whose name has a prefix
?:6candidates: 7- name: "! invalid vote" 8 votes: 124569 9- name: "? blank vote" 10 votes: 124655 11...
Now, all candidates should be included to the schema, but we will omit it for the sake of brevity.
Belgium (2012) - Local elections¶
Let’s do one more…
In Belgium, the local elections used the same system than the Spain EU Parliament elections, but the Imperiali divisor is used instead.
In 2012 47 seats were allocated to Anderlecht:
1name: Commune d'Anderlecht - 2012
2method: highest_averages
3method_params:
4 divisor_f: imperiali
5seats: 47
6candidates:
7- name: "N-VA"
8 votes: 2258
9- name: "LB"
10 votes: 11648
11- name: "FDF"
12 votes: 3499
13- name: "ECOLO-GROEN"
14 votes: 5057
15- name: "VLAAMS BELANG"
16 votes: 1630
17- name: "PS-SP.A-CDH"
18 votes: 16383
19- name: "PTB*PVDA+"
20 votes: 755
21- name: "GAUCHES COMMUNES"
22 votes: 278
23- name: "ISLAM"
24 votes: 1839
25- name: "EGALITE"
26 votes: 829
27- name: "BELG-UNIE"
28 votes: 385