Class ElectoralSimulations

java.lang.Object
org.episteme.social.politics.ElectoralSimulations

public final class ElectoralSimulations extends Object
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 Details

    • resolveInstantRunoff

      public static String resolveInstantRunoff(List<List<String>> ballots)
      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

      public static String resolveCondorcet(List<List<String>> ballots)
      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

      public static String resolveBorda(List<List<String>> ballots)
      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

      public static Map<String,Integer> resolveSTV(List<List<String>> ballots, int seats)
      Calculates seat distribution using Single Transferable Vote (STV) algorithm with Droop Quota.
      Parameters:
      ballots - preference lists
      seats - number of seats to fill
      Returns:
      map of winners to the number of seats they won (typically 1 in STV)
    • resolveSchulze

      public static String resolveSchulze(List<List<String>> ballots)
      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

      public static String resolveCopeland(List<List<String>> ballots)
      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

      public static String resolveApproval(List<List<String>> approvals)
      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

      public static String resolveRange(List<Map<String,Integer>> scores)
      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

      public static String resolveSTAR(List<Map<String,Integer>> scores)
      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

      public static Map<String,Integer> allocateDHondt(Map<String,Long> votes, int seats)
      Allocates seats using the D'Hondt method (Jefferson method). Favors larger parties, used in many European countries.
      Parameters:
      votes - Map of Party -> Vote Count
      seats - Number of seats to allocate
      Returns:
      Map of Party -> Seats Won
    • allocateSainteLague

      public static Map<String,Integer> allocateSainteLague(Map<String,Long> votes, int seats)
      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 Count
      seats - Number of seats to allocate
      Returns:
      Map of Party -> Seats Won
    • allocateModifiedSainteLague

      public static Map<String,Integer> allocateModifiedSainteLague(Map<String,Long> votes, int seats)
      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 Count
      seats - Number of seats to allocate
      Returns:
      Map of Party -> Seats Won
    • allocateHuntingtonHill

      public static Map<String,Integer> allocateHuntingtonHill(Map<String,Long> votes, int seats)
      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/Votes
      seats - Number of seats to allocate
      Returns:
      Map of State/Party -> Seats
    • allocateLargestRemainderHare

      public static Map<String,Integer> allocateLargestRemainderHare(Map<String,Long> votes, int seats)
      Allocates seats using the Largest Remainder method with Hare quota. Also known as Hamilton's method.
      Parameters:
      votes - Map of Party -> Vote Count
      seats - Number of seats to allocate
      Returns:
      Map of Party -> Seats Won
    • allocateLargestRemainderDroop

      public static Map<String,Integer> allocateLargestRemainderDroop(Map<String,Long> votes, int seats)
      Allocates seats using the Largest Remainder method with Droop quota. Droop quota = (total votes / (seats + 1)) + 1
      Parameters:
      votes - Map of Party -> Vote Count
      seats - Number of seats to allocate
      Returns:
      Map of Party -> Seats Won
    • resolveTwoRound

      public static String resolveTwoRound(List<List<String>> ballots)
      Simulates a Two-Round System (TRS) election. If no candidate gets >50% in first round, top two go to runoff.
      Parameters:
      ballots - Ranked preferences
      Returns:
      the winner after one or two rounds
    • resolveMinimax

      public static String resolveMinimax(List<List<String>> ballots)
      Resolves an election using the Minimax method (Simpson-Kramer). The winner is the candidate whose greatest pairwise defeat is the smallest.
      Parameters:
      ballots - List of ranked preferences
      Returns:
      the name of the Minimax winner
    • resolveAntiPlurality

      public static String resolveAntiPlurality(List<List<String>> ballots)
      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

      public static String resolveBucklin(List<List<String>> ballots)
      Resolves an election using Bucklin Voting. Check 1st choices; if no majority, add 2nd choices, etc., until someone has a majority.
      Parameters:
      ballots - List of ranked preferences
      Returns:
      the name of the winner
    • resolveCoombs

      public static String resolveCoombs(List<List<String>> ballots)
      Resolves an election using Coombs' Method. Similar to IRV, but eliminates the candidate with the most LAST place votes.
      Parameters:
      ballots - List of ranked preferences
      Returns:
      the name of the winner
    • resolveKemenyYoung

      public static String resolveKemenyYoung(List<List<String>> ballots)
      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

      public static String resolveRankedPairs(List<List<String>> ballots)
      Resolves an election using Tideman's Ranked Pairs method. Pairs are "locked in" based on their margin of victory, avoiding cycles.
      Parameters:
      ballots - List of ranked preferences
      Returns:
      the name of the winner
    • resolveDodgson

      public static String resolveDodgson(List<List<String>> ballots)
      Resolves an election using a simplified Dodgson's method. Approximated by Tideman's score (n of wins) or simplified swap count.
      Parameters:
      ballots - List of ranked preferences
      Returns:
      the name of the winner
    • resolveMajorityJudgment

      public static String resolveMajorityJudgment(List<Map<String,Integer>> grades)
      Resolves an election using Majority Judgment. Voters assign median-based grades (Excellent=6, Very Good=5, ..., Poor=1).
      Parameters:
      grades - List of voter grades (Candidate -> Grade)
      Returns:
      the name of the winner
    • resolveSNTV

      public static Map<String,Integer> resolveSNTV(Map<String,Long> votes, int seats)
      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 Count
      seats - Number of seats to fill
      Returns:
      Map of winners to seats won (always 1 in SNTV)
    • resolveCumulative

      public static Map<String,Integer> resolveCumulative(Map<String,Long> totalVotes, int seats)
      Resolves an election using Cumulative Voting. Voters can distribute multiple votes among candidates.
      Parameters:
      totalVotes - Map of Candidate -> Total Votes received from all voters
      seats - Number of seats to fill
      Returns:
      Map of winners to seats
    • computePairwiseMatrix

      public static int[][] computePairwiseMatrix(List<List<String>> ballots, List<String> candidates)
      Computes the pairwise comparison matrix from ranked ballots.
      Parameters:
      ballots - List of ranked preferences
      candidates - List of all candidates
      Returns:
      2D array where [i][j] = number of ballots preferring candidate i over j
    • findCondorcetWinner

      public static Optional<String> findCondorcetWinner(List<List<String>> ballots)
      Checks if a Condorcet winner exists (beats all others in pairwise comparisons).
      Parameters:
      ballots - List of ranked preferences
      Returns:
      Optional containing the Condorcet winner, or empty if none exists