Tutorial 6: Preferences and external data files

Before we fight the final bosses, the compensatory systems, let’s practice two other concepts:

  • Preferential vote method

  • Retrieving data from external files

Wikipedia - Condorcet method example

We will define an schema for the example in the en.Wikipedia page Condorcet method:

Voters from Tennessee should order 4 possible candidates in the order they prefer to be their new capital city:

  • 42% of voters prefers Memphis, then Nashville, then Chattanooga, then Knoxville

  • 26% of voters prefers Nashville, then Chattanooga, then Knoxville, then Memphis

  • 15% of voters prefers Chattanooga, then Knoxville, then Nashville, then Memphis

  • 17% of voters prefers Knoxville, then Chattanooga, then Nashville, then Memphis

This data can’t be provided using the Contender. We need to use Preference instead.

 1name: Tennessee - Capital city
 2method: copeland
 3preferences:
 4- votes: 42
 5  preference: ["Memphis", "Nashville", "Chattanooga", "Knoxville"]
 6- votes: 26
 7  preference: ["Nashville", "Chattanooga", "Knoxville", "Memphis"]
 8- votes: 15
 9  preference: ["Chattanooga", "Knoxville", "Nashville", "Memphis"]
10- votes: 17
11  preference: ["Knoxville", "Chattanooga", "Nashville", "Memphis"]

We have used the Copeland's method, but it could be replaced by any method in interregnum.methods.preferential.

Australia - Senate 2002 - Northern Territory

Each district is a multi-seat constituency where the contenders are candidates that can be allied to parties. Winners are elected using the Single Transferable Vote method with a Droop quota. Votes are transferred by the Weighted Inclusive Gregory's transfer method.

The Northern Territory will be represented by 2 senators.

 1name: Australia - Senate 2002
 2type: group
 3method: single_transferable_vote
 4method_params:
 5    quota_f: droop
 6    transfer_f: weighted_inclusive_gregory
 7    round_f: int
 8divisions:
 9
10- name: Northern Territory
11  seats: 2
12  candidates:
13  - name: PRICE Jacinta Nampijinpa [PJN]
14    alliance: NT CLP
15  - name: CIVITARESE Kris [CK]
16    alliance: NT CLP
17
18  - name: McMAHON Sam [MS]
19    alliance: Liberal Democrats
20
21  - name: McCARTHY Malarndirri [MM]
22    alliance: A.L.P.
23  - name: GANLEY Kate [GK]
24    alliance: A.L.P.
25
26  - name: LAWRENCE Lance [LL]
27    alliance: Legalise Cannabis Australia
28  - name: HIBBERT Kelly-Anne [HKA]
29    alliance: Legalise Cannabis Australia
30
31  - name: WHYTE Lamaan [WL]
32    alliance: Sustainable Australia Party - Stop Overdevelopment / Corruption
33  - name: BELCHER Richard [BR]
34    alliance: Sustainable Australia Party - Stop Overdevelopment / Corruption
35
36  - name: ARRIGO Steve [AS]
37    alliance: The Great Australian Party
38  - name: MARCUS Angela [MA]
39    alliance: The Great Australian Party
40
41  - name: CAMPBELL Trudy [CT]
42    alliance: Citizens Party
43  - name: FLYNN Peter [FP]
44    alliance: Citizens Party
45
46  - name: ANLEZARK Jane [AJ]
47    alliance: The Greens
48  - name: STOKES Dianne [SD]
49    alliance: The Greens
50
51  - name: RAJWIN Raj [RR]
52
53  preferences:
54      type: preferences-file
55      format: pref
56      path: au_senate_northern_territory_2002.pref

Registered candidates are provided for two reasons:

  • This allows to specify alliances,

  • Some methods require the full list of candidates, even if nobody voted for them.

Since the list of preferences is large, it will be tedious to add it to the schema. We will declare the use of an external file instead:

53preferences:
54    type: preferences-file
55    format: pref
56    path: au_senate_northern_territory_2002.pref

The format pref allows to write files in a more compact way:

!!preference >
!!equal =
!!score :
!a=PRICE Jacinta Nampijinpa [PJN]
!b=McCARTHY Malarndirri [MM]
!c=HIBBERT Kelly-Anne [HKA]
!d=CIVITARESE Kris [CK]
!e=BELCHER Richard [BR]
!f=LAWRENCE Lance [LL]
!g=CAMPBELL Trudy [CT]
!h=STOKES Dianne [SD]
!i=MARCUS Angela [MA]
!j=ANLEZARK Jane [AJ]
!k=WHYTE Lamaan [WL]
!l=ARRIGO Steve [AS]
!m=McMAHON Sam [MS]
!n=GANLEY Kate [GK]
!o=FLYNN Peter [FP]
!p=RAJWIN Raj [RR]
!q=HANSEN Jed [HJ]
5206:a>d>m>q>b>n>f>c>k>e>l>i
4272:b>n>j>h>m>q>f>c>k>e>a>d
1787:a>d>m>q>b>n>f>c>k>e>l>i>g>o>j>h
1385:j>h>b>n>f>c>k>e>a>d>m>q
709:b>n
660:b>n>l>i>m>q>f>c>k>e>a>d
530:a>d
...

Spain - General elections - Parliament (revisited… again)

In Spain - General elections - Parliament - Full process we omitted candidates to keep the schema short. Now we will use an external file

 1name: Elecciones a Cortes Generales
 2type: group
 3divisions:
 4
 5- name: Distribución de escaños
 6  type: group
 7  aggregate: yes
 8  meta:
 9    notes: |
10        Seats apportionment based on provintial census
11  fill_candidates:
12      path: censo_provincial_2015.csv
13      format: csv
14  divisions:
15  - name: Ciudades autónomas
16    method: noop
17    initial_seats: 1
18  - name: Provincias
19    seats: 248
20    method: largest_remainder
21    method_params:
22      quota_f: hare
23    initial_seats: 2
24    resume_allocation: no
25
26- name: Circunscripciones
27  type: group
28  aggregate: yes
29  method: highest_averages
30  method_params:
31  divisor_f: dhondt
32  exclude: valid_votes < 3%
33  meta:
34    notes: |
35        Seats allocation based on votes
36  fill_candidates:
37    path: votos_generales_2015.csv
38    format: csv
39  divisions:
40  - name: Andalucía
41    type: group
42    aggregate: yes
43    divisions:
44    - name: Almería
45      seats: Distribución de escaños
46    - name: Cádiz
47      seats: Distribución de escaños
48    - name: Córdoba
49      seats: Distribución de escaños
50    - name: Granada
51      seats: Distribución de escaños
52    - name: Huelva
53      seats: Distribución de escaños
54    - name: Jaén
55      seats: Distribución de escaños
56    - name: Málaga
57      seats: Distribución de escaños
58    - name: Sevilla
59      seats: Distribución de escaños
60  ...
61  - name: País Vasco
62    type: group
63    aggregate: yes
64    divisions:
65    - name: Araba/Álava
66      seats: Distribución de escaños
67    - name: Bizkaia
68      seats: Distribución de escaños
69    - name: Gipuzkoa
70      seats: Distribución de escaños

When file is provided to a node through unserialize_node(), files with candidates data will be injected to that node or some of its children:

  • If a row has a column node, the value will be used to identify the node.

  • Otherwise, if a row has a column district, the vlaue will be used to identify the node.

  • If no node could be identified, all candidates will be assigned to the root node where the file was declared.

Let’s see the head of the file censo_provincial_2015.csv:

district,name,votes
Ciudades autónomas,Ceuta,84963
Ciudades autónomas,Melilla,84509
Provincias,Almería,701688
Provincias,Cádiz,1240175
Provincias,Córdoba,799402
Provincias,Granada,919455
Provincias,Huelva,519229
Provincias,Jaén,659033
Provincias,Málaga,1621968

And the head of votos_generales_2015.csv:

district,name,votes
Almería,PARTIDO POPULAR,117635
Almería,PARTIDO SOCIALISTA OBRERO ESPAÑOL,89434
Almería,CIUDADANOS-PARTIDO DE LA CIUDADANÍA,44494
Almería,PODEMOS,39780
Almería,"UNIDAD POPULAR: IZQUIERDA UNIDA, UNIDAD POPULAR EN",10828
Almería,PARTIDO ANIMALISTA CONTRA EL MALTRATO ANIMAL,2126
Almería,UNIÓN PROGRESO Y DEMOCRACIA,1532
Almería,VOX,558
Almería,FALANGE ESPAÑOLA DE LAS J.O.N.S.,343
Almería,PARTIDO COMUNISTA DE LOS PUEBLOS DE ESPAÑA,318
Almería,RECORTES CERO-GRUPO VERDE,297
Almería,POR UN MUNDO MÁS JUSTO,176
Almería,DEMOCRACIA NACIONAL,164
Cádiz,PARTIDO SOCIALISTA OBRERO ESPAÑOL,180895
Cádiz,PARTIDO POPULAR,179319
Cádiz,PODEMOS,130734

External files can also be specified when using the Command Line Interface.