Package elections :: Module irv
[frames] | no frames]

Module irv

source code

Implement all the functions for computing IRV margins and bounds.

Functions
number, dict, list, Node
irv_round(profile, rounds, rules=0)
Perform at most rounds rounds of IRV using rules.
source code
number, dict, list
irv(election, rules=0)
Perform IRV using rules and return the winner, vote counts, and elimination order.
source code
number
irv_simple_lb(election, rules=1)
Compute and return an IRV margin lower bound using the elimination sets dictated by the rules.
source code
number
irv_margin(election, winner=None, elim_order=None, ub=None, trace=False, timeout=1e+75)
Compute the exact IRV margin of the election.
source code
number
irv_lb(election, eliminations=None, trace=False)
Compute and return an IRV margin lower bound and the optimal sequence of eliminations that gives it.
source code
number
irv_ub(election, rules=1, winner=None, elim_order=None, trace=False)
Compute and return an IRV margin upper bound.
source code
Variables
  BASE_IRV_RULES = 0
  SF_RCV_RULES = 1
  COMPLETE_IRV_RULES = 2
  __package__ = 'elections'
Function Details

irv_round(profile, rounds, rules=0)

source code 

Perform at most rounds rounds of IRV using rules.

Parameters:
  • profile (Node) - The ballot profile.
  • rounds (number) - The maximum number of rounds to perform.
  • rules (enum) - The IRV rules to use for elimination.
Returns: number, dict, list, Node
Returns the winner, if any, the count of votes in each round, the list of elimination sets used, and the reduced tree after having eliminated candidates.

irv(election, rules=0)

source code 

Perform IRV using rules and return the winner, vote counts, and elimination order.

Parameters:
  • election (Election) - The election.
  • rules (enum) - The rules to use.
Returns: number, dict, list
Returns the winner, the vote counts, and the elimination order.

irv_simple_lb(election, rules=1)

source code 

Compute and return an IRV margin lower bound using the elimination sets dictated by the rules.

Parameters:
  • election (Election) - The election.
  • rules (enum) - The rules to use.
Returns: number
Returns the lower bound.

irv_margin(election, winner=None, elim_order=None, ub=None, trace=False, timeout=1e+75)

source code 

Compute the exact IRV margin of the election.

Parameters:
  • election (Election) - The election.
  • winner (number) - The winner of the election. If None, it will be computed.
  • elim_order (list) - The elimination order. If None, it will be computed.
  • ub (number) - An upper bound on the margin. If None, it will be computed via irv_ub.
  • trace (boolean) - If True, print a trace of the computation.
  • timeout (number) - The amount of time to spend computing the margin.
Returns: number
Returns the IRV margin.

irv_lb(election, eliminations=None, trace=False)

source code 

Compute and return an IRV margin lower bound and the optimal sequence of eliminations that gives it.

Parameters:
  • election (Election) - The election.
  • eliminations (list) - If not None, it is set to the optimal sequence of eliminations that gives the lower bound.
  • trace (boolean) - If True, then print out at trace of the computation.
Returns: number
Returns the lower bound.

irv_ub(election, rules=1, winner=None, elim_order=None, trace=False)

source code 

Compute and return an IRV margin upper bound.

Parameters:
  • election (Election) - The election.
  • rules (enum) - The rules to use. Should probably not be changed.
  • trace (boolean) - If True, then print a trace of the computation.
Returns: number
Returns an upper bound on the margin.