Class ElectoralSimulations
java.lang.Object
org.episteme.social.politics.ElectoralSimulations
Provides algorithms for simulating complex electoral systems such as
Instant Runoff Voting (IRV) and Single Transferable Vote (STV).
- Since:
- 1.0
- Version:
- 1.1
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Method Summary
Modifier and TypeMethodDescriptionallocateDHondt(Map<String, Long> votes, int seats) Allocates seats using the D'Hondt method (Jefferson method).allocateHuntingtonHill(Map<String, Long> votes, int seats) Allocates seats using the Huntington-Hill method.allocateLargestRemainderDroop(Map<String, Long> votes, int seats) Allocates seats using the Largest Remainder method with Droop quota.allocateLargestRemainderHare(Map<String, Long> votes, int seats) Allocates seats using the Largest Remainder method with Hare quota.allocateModifiedSainteLague(Map<String, Long> votes, int seats) Allocates seats using Modified Sainte-Laguë method.allocateSainteLague(Map<String, Long> votes, int seats) Allocates seats using the Sainte-Laguë method (Webster method).static int[][]Computes the pairwise comparison matrix from ranked ballots.findCondorcetWinner(List<List<String>> ballots) Checks if a Condorcet winner exists (beats all others in pairwise comparisons).static StringresolveAntiPlurality(List<List<String>> ballots) Resolves an election using the Anti-plurality method (Veto).static StringresolveApproval(List<List<String>> approvals) Resolves an election using Approval Voting.static StringresolveBorda(List<List<String>> ballots) Resolves an election using the Borda Count method.static StringresolveBucklin(List<List<String>> ballots) Resolves an election using Bucklin Voting.static StringresolveCondorcet(List<List<String>> ballots) Resolves an election using the Condorcet method.static StringresolveCoombs(List<List<String>> ballots) Resolves an election using Coombs' Method.static StringresolveCopeland(List<List<String>> ballots) Resolves an election using Copeland's method.resolveCumulative(Map<String, Long> totalVotes, int seats) Resolves an election using Cumulative Voting.static StringresolveDodgson(List<List<String>> ballots) Resolves an election using a simplified Dodgson's method.static StringresolveInstantRunoff(List<List<String>> ballots) Resolves an Instant Runoff (Ranked Choice) election.static StringresolveKemenyYoung(List<List<String>> ballots) Resolves an election using the Kemeny-Young method.static StringresolveMajorityJudgment(List<Map<String, Integer>> grades) Resolves an election using Majority Judgment.static StringresolveMinimax(List<List<String>> ballots) Resolves an election using the Minimax method (Simpson-Kramer).static StringresolveRange(List<Map<String, Integer>> scores) Resolves an election using Range/Score Voting.static StringresolveRankedPairs(List<List<String>> ballots) Resolves an election using Tideman's Ranked Pairs method.static StringresolveSchulze(List<List<String>> ballots) Resolves an election using the Schulze method (Beatpath).resolveSNTV(Map<String, Long> votes, int seats) Resolves an election using Single Non-Transferable Vote (SNTV).static StringresolveSTAR(List<Map<String, Integer>> scores) Resolves an election using STAR Voting (Score Then Automatic Runoff).resolveSTV(List<List<String>> ballots, int seats) Calculates seat distribution using Single Transferable Vote (STV) algorithm with Droop Quota.static StringresolveTwoRound(List<List<String>> ballots) Simulates a Two-Round System (TRS) election.
-
Method Details
-
resolveInstantRunoff
Resolves an Instant Runoff (Ranked Choice) election. Voters' preferences are processed iteratively until a majority is reached.- Parameters:
ballots- List of voter preferences (each list is a ranked list of candidate names)- Returns:
- the name of the winning candidate, or "No Winner"
-
resolveCondorcet
Resolves an election using the Condorcet method. A candidate is a Condorcet winner if they defeat every other candidate in pairwise comparisons.- Parameters:
ballots- List of voter preferences (each list is a ranked list of candidate names)- Returns:
- the name of the Condorcet winner, or "No Condorcet Winner"
-
resolveBorda
Resolves an election using the Borda Count method. Candidates are assigned points based on their rank in each ballot. For N candidates, 1st place gets N-1 points, 2nd gets N-2, etc.- Parameters:
ballots- List of voter preferences- Returns:
- the name of the winner
-
resolveSTV
Calculates seat distribution using Single Transferable Vote (STV) algorithm with Droop Quota.- Parameters:
ballots- preference listsseats- number of seats to fill- Returns:
- map of winners to the number of seats they won (typically 1 in STV)
-
resolveSchulze
Resolves an election using the Schulze method (Beatpath). This is a Condorcet completion method that finds the strongest paths between candidates. Used by Debian, Ubuntu, and many open-source organizations.- Parameters:
ballots- List of voter preferences- Returns:
- the name of the Schulze winner
-
resolveCopeland
Resolves an election using Copeland's method. Candidates earn 1 point for each pairwise win, 0.5 for ties. The candidate with the most points wins.- Parameters:
ballots- List of voter preferences- Returns:
- the name of the Copeland winner
-
resolveApproval
Resolves an election using Approval Voting. Each voter approves of multiple candidates, and the candidate with most approvals wins. Input format: each list contains the candidates approved by that voter.- Parameters:
approvals- List of approval sets (each inner list = candidates approved by one voter)- Returns:
- the name of the winner
-
resolveRange
Resolves an election using Range/Score Voting. Voters assign scores to candidates, and the candidate with highest average score wins. Input format: List of maps, where each map represents a voter's scores for candidates.- Parameters:
scores- List of score maps (Candidate -> Score)- Returns:
- the name of the winner
-
resolveSTAR
Resolves an election using STAR Voting (Score Then Automatic Runoff). First round: candidates scored 0-5, top two advance. Second round: automatic runoff between top two based on ballot preferences.- Parameters:
scores- List of score maps (Candidate -> Score, typically 0-5)- Returns:
- the name of the STAR winner
-
allocateDHondt
Allocates seats using the D'Hondt method (Jefferson method). Favors larger parties, used in many European countries.- Parameters:
votes- Map of Party -> Vote Countseats- Number of seats to allocate- Returns:
- Map of Party -> Seats Won
-
allocateSainteLague
Allocates seats using the Sainte-Laguë method (Webster method). More proportional than D'Hondt, uses odd number divisors (1, 3, 5, 7...).- Parameters:
votes- Map of Party -> Vote Countseats- Number of seats to allocate- Returns:
- Map of Party -> Seats Won
-
allocateModifiedSainteLague
Allocates seats using Modified Sainte-Laguë method. Uses 1.4 as the first divisor instead of 1, reducing fragmentation. Used in Norway, Sweden, and other Nordic countries.- Parameters:
votes- Map of Party -> Vote Countseats- Number of seats to allocate- Returns:
- Map of Party -> Seats Won
-
allocateHuntingtonHill
Allocates seats using the Huntington-Hill method. Used for apportioning seats in the U.S. House of Representatives. Uses geometric mean as divisor.- Parameters:
votes- Map of State/Party -> Population/Votesseats- Number of seats to allocate- Returns:
- Map of State/Party -> Seats
-
allocateLargestRemainderHare
Allocates seats using the Largest Remainder method with Hare quota. Also known as Hamilton's method.- Parameters:
votes- Map of Party -> Vote Countseats- Number of seats to allocate- Returns:
- Map of Party -> Seats Won
-
allocateLargestRemainderDroop
Allocates seats using the Largest Remainder method with Droop quota. Droop quota = (total votes / (seats + 1)) + 1- Parameters:
votes- Map of Party -> Vote Countseats- Number of seats to allocate- Returns:
- Map of Party -> Seats Won
-
resolveTwoRound
-
resolveMinimax
-
resolveAntiPlurality
Resolves an election using the Anti-plurality method (Veto). Each voter awards one point to all candidates except their least favorite. The candidate with the most points wins.- Parameters:
ballots- List of ranked preferences- Returns:
- the name of the winner
-
resolveBucklin
-
resolveCoombs
-
resolveKemenyYoung
Resolves an election using the Kemeny-Young method. Finds the ranking that maximizes pairwise agreement with voters. Note: This implementation uses a simple permutation search, limited to small sets.- Parameters:
ballots- List of ranked preferences- Returns:
- the name of the Kemeny-Young winner
-
resolveRankedPairs
-
resolveDodgson
-
resolveMajorityJudgment
-
resolveSNTV
Resolves an election using Single Non-Transferable Vote (SNTV). Voters have one vote; candidates with highest counts win multiple seats.- Parameters:
votes- Map of Candidate -> Vote Countseats- Number of seats to fill- Returns:
- Map of winners to seats won (always 1 in SNTV)
-
resolveCumulative
Resolves an election using Cumulative Voting. Voters can distribute multiple votes among candidates.- Parameters:
totalVotes- Map of Candidate -> Total Votes received from all votersseats- Number of seats to fill- Returns:
- Map of winners to seats
-
computePairwiseMatrix
Computes the pairwise comparison matrix from ranked ballots.- Parameters:
ballots- List of ranked preferencescandidates- List of all candidates- Returns:
- 2D array where [i][j] = number of ballots preferring candidate i over j
-
findCondorcetWinner
-