ICTSA Programming Contest 2009Legal Cheating in Elections
Gordon Pace
Claudia Borg
Chris Porter
Legal Cheating
District boundary manipulation to give an unfair advantage, or gerrymandering has a long history… 1812: Governor Elbridge Gerry in Massachusetts drew up a
district so distorted geographically, that it was likened to a salamander – ‘better call it a gerrymander’ someone commented!
Legal Cheating
Legal Cheating
Gerrymandering works through the wasted vote effect. Why do we not use a more effective electoral system?
Arrow’s impossibility theorem from 1951 demonstrates that no voting system can convert individual rankings into a global one – there can be no fair election system.
An Example
An ExampleWest Gozo
PX=80PY=100
East GozoPX=120PY=190
CirkewwaPX=60PY=50
St Paul’sPX=70PY=90
MostaPX=100PY=150
RabatPX=120PY=140
VallettaPX=240PY=100
MarsaxlokkPX=100PY=50
ZurrieqPX=210PY=100
An ExamplePX elects 7
Variance = 255
An ExamplePX elects 8
Variance = 147
An ExamplePX elects 8
Variance = 141
The Programming Task
Given: A set of villages Connections between villages Expected voting preferences in each village for
the two parties PX and PY Number of districts to have
To return in less than 5 minutes: A district partitioning such that districts are
connected components
The Programming Task
A good partition is one which: Maximises the number of seats il-Partit tax-
Xurbana (PX) elects; and Minimises the differences in populations across
districts. Ideally there would have been:
A bound on the difference between district populations;
A bound on the distance between villages in a single district.
How to Solve It
The problem can be shown to be NP-complete (eg via the Knapsack problem).
A brute-force solution will only work for small instances.
Larger problems require the use of some search heuristic.
The Teams
5. Eat Your Apple! • David Bailey • Andrew Calleja • Alan Cassar • Stephen Fenech
6. dot • Marco Muscat • Joseph Borg
7. HND4 • Norbert DeBono • Matthew Xuereb • Andrew Vella
8. CG • Andrew Said
9. Village People • Darren Demicoli
1. Beeef • Alessio Magro • Reuben Bartolo • Jonathan Caruana
2. Unicus • Gianluca Valentino
3. WM • James Scicluna • Kevin Falzon • Ingram Bondin • Andrew Gauci
4. iLike • Andrew Borg Cardona • Michael Debono
The Teams Solutions: Beeef
Genetic Algorithm: using only selection and mutation (cross-over did not give better results).
Chromosome representation: consist of a list of districts, which in turn are composed of a list of villages.
Creation: ensures that: All the villages in a district must belong to the same `island'. Districts must be connected.
Mutation: works by selecting two districts at random and swapping two villages across: The two districts must belong to the same `island'. Check that connectivity is not lost by the addition or the removal.
Fitness function: Number of PX members elected, variance. Termination: upon convergence.
The Teams Solutions: Unicus
Heuristic based: The generator worked as follows, repeating as necessary. Repeat a number of times:
Identified the village where PX has the largest majority and population and place in District 1.
Identified the village with the largest PY majority and second largest population, and the village with the second largest PX majority and 3rd largest population, both of which had to be connected to each other, and placed them in District 2.
Create a district with the villages with the largest PX and PY majority, and repeat to use up the remaining villages. Repeat this process for all permutations.
Programmed in C using .NET 2.0
The Teams Solutions: WM
Special case scenarios, a brute-force search and a Montecarlo method were implemented one of which is chosen depending on the problem given.
For non-special cases, a measure of the complexity of the graph is estimated and depending on this one of the solutions is chosen based on benchmarking. Approach 1: Fully enumerative approach, resembling
brute force, but with immediate pruning of some impossible candidate solutions
Approach 2: An adaptive Montecarlo based approach with generation of results through analysis of the given accident space and appropriate ranking of resulting candidate solutions
A timer ensures a solution in the allotted 5 minutes.
The Teams Solutions: iLike
Random search: A modified Monte Carlo method, taking features from genetic algorithms
Chromosome: District configurations Random generation: Generates random distribution
of villages (randomising villages, and placing random separators), and checked for validity
Selection: Fitness: More elected PX MPs or better variance is preferred. Validity: Checked later for performance reasons
Stopping criteria: 100 generations or reaching a long enough plateau (dependant on size of the problem)
The Teams Solutions: Eat Your Apple! Preprocessing:
Split the country into separate islands Each island (based on its population) is assigned a number of
districts to be allocated within it. Phase 1: Clustering Algorithm
On each island a clustering algorithm groups villages into districts such that the number of elected PX candidates is maximized.
Starts off a random village, and adds others clustered around the initial village.
Phase 2: Genetic Algorithm A genetic algorithm is applied on the output of the clustering
algorithm to generate fitter solutions Fitness function was global maximization of PX candidate count
and a globally minimized PY candidate count. Assigning more weight to the PX count gave better results.
The Teams Solutions: . (dot, tikka) Preprocessing: Splits the problem into
'islands' to support disconnected nodes.
Genetic algorithm Generation: using random starting village and
generate a connected district with a modified BFS search.
Fitness function: Number of PX members elected and variance
The Teams Solutions: HND4
Developed using C# on .NET framework 2.0 Preprocessing: Separate into different
islands. Heuristic search:
Grouping villages where PY dominates and group them in one district if possible
If more districts are still required PX dominant districts are divided into smaller ones.
The Teams Solutions: CG
Calculate all possible district sizes For each possible combination of sizes:
A district is created starting from a village and proceeding in a BFS manner.
Try to create the remaining districts ensuring no overlap. Remember the best solution found.
Would have liked to add: Heuristics to merge villages in a pre-analysis phase eg PY-
strong villages close to each other. Use a timer to ensure giving results on time.
The Teams Solutions: Village People Genetic algorithm coded in C Chromosome representation: partitions with
connected villages Crossover: injects a district into the chromosone Mutation: randomly assigns a village to a district Genetic repair: is used to ensure that the partitions
are still valid Fitness function: Sum of the ratio of members
elected of party X against party Y, and the inverse of the variance.
The Test Problems
Set of properties specified for 17 fictitious countries.
Each village has: 300 ≤ Voters ≤ 500
Generated randomly before the contest The ratio between the votes for the parties PX:PY was
allowed to could range between 20:80 and 80:20 Generated randomly before the contest
A number of regular map layouts were used.
The number of district was chosen so as to ensure an average of 4 villages per district.
The Test Problems
8 grid countries: 3x3 to 10x10
Asgvvjfcne Szoxxldneo Lltrdabguo
Lczktvafoj Moawloiblf Tgxgmzcaqw
Ciioesvamf Kazucjrgqf Hmxfstqddp
198,264 175,144 220,91
129,187 267,144 218,179
187,120 232,232 354,106
The Test Problems
3 full-mesh grid countries: 3x3, 7x7, 10x10
Asgvvjfcne Szoxxldneo Lltrdabguo
Lczktvafoj Moawloiblf Tgxgmzcaqw
Ciioesvamf Kazucjrgqf Hmxfstqddp
198,264 175,144 220,91
129,187 267,144 218,179
187,120 232,232 354,106
The Test Problems
3 circular countries with 10, 20 and 50 villages
AsgvvjfcneSzoxxldneo
Lczktvafoj
Ciioesvamf
198,264175,144
129,187
187,120
Lvjanqoway
Vvjzivqcmq
Xasfeuqsyp
165,309
Yisfhxnfvz
Imutautvmw
168,156
84,266
Wdyvaxlzyb
214,285
200,227
174,190
The Test Problems
3 circular countries with a hub sizes 10, 20 and 50
AsgvvjfcneSzoxxldneo
Lczktvafoj
Ciioesvamf
198,264175,144
129,187
187,120
Lvjanqoway
Vvjzivqcmq
Xasfeuqsyp
165,309
Yisfhxnfvz
Imutautvmw
168,156
84,266
Wdyvaxlzyb
214,285
200,227
174,190
Dastautvmw
74,263
The Test Problem
The biggest problem of them all
The Test Problem
The biggest problem of them all
Malta
The Test Problem: Malta
The Test Problem: Malta
An example from real-life: Malta 69 villages Connectivity based on geographical proximity Vote distribution based on the results of the last
local elections (2006 – 2008)1
13 districts
1taken from http://www.maltadata.com/tr-count1.htm
The Results: Grids [3x3]
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
3x311
829.54
N/A 11
829.54
11
1081.46
11
1081.46
11
829.54
8
860.24
11
829.54
11
829.54
The Results: Grids [4x4]
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
3x311
829.54
N/A 11
829.54
11
1081.46
11
1081.46
11
826.54
8
860.24
11
829.54
11
829.54
4x413
743.72
N/A 15
2126.26
14
2045.46
14
1855.38
14
1201.70
10
1246.64
14
1385.91
14
1557.84
The Results: Grids [5x5]
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
3x311
829.54
N/A 11
829.54
11
1081.46
11
1081.46
11
826.54
8
860.24
11
829.54
11
829.54
4x413
743.72
N/A 15
2126.26
14
2045.46
14
1855.38
14
1201.70
10
1246.64
14
1385.91
14
1557.84
5x520
628.31
N/A 24
2462.99
23
2346.45
21
1759.58
21
488.39
22
1644.56
TIME-OUT
22
2086.26
The Results: Grids [6x6]
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
3x311
829.54
N/A 11
829.54
11
1081.46
11
1081.46
11
826.54
8
860.24
11
829.54
11
829.54
4x413
743.72
N/A 15
2126.26
14
2045.46
14
1855.38
14
1201.70
10
1246.64
14
1385.91
14
1557.84
5x520
628.31
N/A 24
2462.99
23
2346.45
21
1759.58
21
488.39
22
1644.56
TIME-OUT
22
2086.26
6x6IN-VALID
N/A 33
3182.35
TIME-OUT
32
2932.91
30
545.97
23
3596.41
TIME-OUT
29
1583.77
The Results: Grids [7x7]
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
3x311
829.54
N/A 11
829.54
11
1081.46
11
1081.46
11
826.54
8
860.24
11
829.54
11
829.54
4x413
743.72
N/A 15
2126.26
14
2045.46
14
1855.38
14
1201.70
10
1246.64
14
1385.91
14
1557.84
5x520
628.31
N/A 24
2462.99
23
2346.45
21
1759.58
21
488.39
22
1644.56
TIME-OUT
22
2086.26
6x6IN-VALID
N/A 33
3182.35
TIME-OUT
32
2932.91
30
545.97
23
3596.41
TIME-OUT
29
1583.77
7x7IN-VALID
N/A 43
1670.34
TIME-OUT
TIME-OUT
42
1158.84
30
2862.67
TIME-OUT
39
2655.99
The Results: Grids [8x8]
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
3x311
829.54
N/A 11
829.54
11
1081.46
11
1081.46
11
826.54
8
860.24
11
829.54
11
829.54
4x413
743.72
N/A 15
2126.26
14
2045.46
14
1855.38
14
1201.70
10
1246.64
14
1385.91
14
1557.84
5x520
628.31
N/A 24
2462.99
23
2346.45
21
1759.58
21
488.39
22
1644.56
TIME-OUT
22
2086.26
6x6IN-VALID
N/A 33
3182.35
TIME-OUT
32
2932.91
30
545.97
23
3596.41
TIME-OUT
29
1583.77
7x7IN-VALID
N/A 43
1670.34
TIME-OUT
TIME-OUT
42
1158.84
30
2862.67
TIME-OUT
39
2655.99
8x845
1286.76
N/A 51
3200.13
TIME-OUT
TIME-OUT
47
759.37
41
3921.77
TIME-OUT
IN-VALID
The Results: Grids [9x9]
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
3x311
829.54
N/A 11
829.54
11
1081.46
11
1081.46
11
826.54
8
860.24
11
829.54
11
829.54
4x413
743.72
N/A 15
2126.26
14
2045.46
14
1855.38
14
1201.70
10
1246.64
14
1385.91
14
1557.84
5x520
628.31
N/A 24
2462.99
23
2346.45
21
1759.58
21
488.39
22
1644.56
TIME-OUT
22
2086.26
6x6IN-VALID
N/A 33
3182.35
TIME-OUT
32
2932.91
30
545.97
23
3596.41
TIME-OUT
29
1583.77
7x7IN-VALID
N/A 43
1670.34
TIME-OUT
TIME-OUT
42
1158.84
30
2862.67
TIME-OUT
39
2655.99
8x845
1286.76
N/A 51
3200.13
TIME-OUT
TIME-OUT
47
759.37
41
3921.77
TIME-OUT
IN-VALID
9x958
921.59
N/A 64
2627.06
TIME-OUT
TIME-OUT
61
647.30
51
3848.34
TIME-OUT
IN-VALID
The Results: Grids [10x10]
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
3x311
829.54
N/A 11
829.54
11
1081.46
11
1081.46
11
826.54
8
860.24
11
829.54
11
829.54
4x413
743.72
N/A 15
2126.26
14
2045.46
14
1855.38
14
1201.70
10
1246.64
14
1385.91
14
1557.84
5x520
628.31
N/A 24
2462.99
23
2346.45
21
1759.58
21
488.39
22
1644.56
TIME-OUT
22
2086.26
6x6IN-VALID
N/A 33
3182.35
TIME-OUT
32
2932.91
30
545.97
23
3596.41
TIME-OUT
29
1583.77
7x7IN-VALID
N/A 43
1670.34
TIME-OUT
TIME-OUT
42
1158.84
30
2862.67
TIME-OUT
39
2655.99
8x845
1286.76
N/A 51
3200.13
TIME-OUT
TIME-OUT
47
759.37
41
3921.77
TIME-OUT
IN-VALID
9x958
921.59
N/A 64
2627.06
TIME-OUT
TIME-OUT
61
647.30
51
3848.34
TIME-OUT
IN-VALID
10x1071
1477.11
N/A 77
3028.64
TIME-OUT
TIME-OUT
77
884.98
74
4552.36
TIME-OUT
73
2022.64
The Results: Grids+Diagonal [3x3]
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
3x37
645.46
N/A 7
643.58
7
646.30
7
1258.76
6
36.40
5
1163.59
7
719.40
7
645.46
The Results: Grids+Diagonal [7x7]
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
3x37
645.46
N/A 7
643.58
7
646.30
7
1258.76
6
36.40
5
1163.59
7
719.40
7
645.46
7x735
895.96
N/A 42
2153.71
TIME-OUT
TIME-OUT
40
1111.75
45
3749.09
TIME-OUT
39
2693.27
The Results: Grids+Diagonal [10x10]
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
3x37
645.46
N/A 7
643.58
7
646.30
7
1258.76
6
36.40
5
1163.59
7
719.40
7
645.46
7x735
895.96
N/A 42
2153.71
TIME-OUT
TIME-OUT
40
1111.75
45
3749.09
TIME-OUT
39
2693.27
10x1070
1352.75
N/A 75
4132.35
TIME-OUT
TIME-OUT
72
477.99
82
5560.82
TIME-OUT
69
1917.86
The Results: Wheels – 10 Villages
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
108
235.65
N/A 8
235.65
8
235.65
8
1084.11
8
235.65
7
1071.86
8
235.65
8
235.65
The Results: Wheels – 20 Villages
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
108
235.65
N/A 8
235.65
8
235.65
8
1084.11
8
235.65
7
1071.86
8
235.65
8
235.65
2015
1042.78
N/A 16
2066.65
TIME-OUT
14
1972.18
15
983.30
13
898.80
16
1336.61
15
1164.74
The Results: Wheels – 50 Villages
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
108
235.65
N/A 8
235.65
8
235.65
8
1084.11
8
235.65
7
1071.86
8
235.65
8
235.65
2015
1042.78
N/A 16
2066.65
TIME-OUT
14
1972.18
15
983.30
13
898.80
16
1336.61
15
1164.74
5037
1021.30
N/A 39
1876.99
TIME-OUT
TIME-OUT
39
703.74
35
2748.83
TIME-OUT
IN-VALID
The Results: Wheels+Hub: 10 Villages
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
109
1323.17
N/A 9
839.56
9
1086.27
9
1347.51
8
261.67
9
1323.17
9
839.56
9
1323.17
The Results: Wheels+Hub: 20 Villages
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
109
1323.17
N/A 9
839.56
9
1086.27
9
1347.51
8
261.67
9
1323.17
9
839.56
9
1323.17
2015
2000.66
N/A 16
2475.86
14
2404.72
14
2064.76
15
938.33
11
1826.32
16
1519.45
15
2213.36
The Results: Wheels+Hub: 50 Villages
Beeef Unicus WM iLikeEat
Your Apple!
Dot HND4 CGVillage People
109
1323.17
N/A 9
839.56
9
1086.27
9
1347.51
8
261.67
9
1323.17
9
839.56
9
1323.17
2015
2000.66
N/A 16
2475.86
14
2404.72
14
2064.76
15
938.33
11
1826.32
16
1519.45
15
2213.36
5036
3073.85
N/A 40
3716.95
TIME-OUT
TIME-OUT
37
1250.92
43
3851.62
TIME-OUT
37
2533.44
The Results: Malta
Beeef Unicus WM iLikeEat Your Apple!
Dot HND4 CGVillage People
Malta43
16553.87
N/A 35
35562.72
TIME-OUT
TIME-OUT
47
21847.33
28
53259.60
TIME-OUT
42
12016.04
The Scores
Team Score
Unicus No submission
The Scores
Team Score
Eat Your Apple 35
Unicus No submission
The Scores
Team Score
iLike 110
Eat Your Apple 35
Unicus No submission
The Scores
Team Score
Village People 205
iLike 110
Eat Your Apple 35
Unicus No submission
The Scores
Team Score
HND4 250
Village People 205
iLike 110
Eat Your Apple 35
Unicus No submission
The Scores
Team Score
Beeef 275
CG 275
HND4 250
Village People 205
iLike 110
Eat Your Apple 35
Unicus No submission
The Scores
Team Score
dot 495
Beeef 275
CG 275
HND4 250
Village People 205
iLike 110
Eat Your Apple 35
Unicus No submission
The Scores
Team ScoreWM 720
dot 495
Beeef 275
CG 275
HND4 250
Village People 205
iLike 110
Eat Your Apple 35
Unicus No submission
An Observation
Interesting result: One team managed to elect 47 members of parliament in
Malta out of 65! (PX=PL) Switching parties (not part of the contest) resulted in
another layout electing 43 members for the other party. (PX=PN)
In practice variance should be given more importance so as not to be accused of breach of the Constitution of Malta 61(4): “the number obtained by dividing the total electorate in the
division by the number of members to be returned to the House of Representatives from that division is as nearly equal to the electoral quota as is reasonably practicable”
Prosit tal-Programmi!
The password of the test suite was the first line of the Brikkuni song Il-Bar ta’ Taħt il-Knisja:
Fil-bar ta’ taħt il-knisja jonxru ħwejjeġ tal-mistħija u smajt li bintek tgħidx kemm tħobb tintelaq hemm