RuleIRV¶
-
class
whalrus.RuleIRV(*args, base_rule: whalrus.rules.rule.Rule = None, elimination: whalrus.eliminations.elimination.Elimination = None, **kwargs)[source]¶ Instant-Runoff Voting, also known as Alternative Vote, Single Transferable Vote, etc.
- Parameters
args – Cf. parent class.
base_rule (Rule) – Default:
RulePlurality.elimination (Elimination) – Default:
EliminationLastwithk=1.kwargs – Cf. parent class.
Examples
At each round, the candidate with the worst Plurality score is eliminated.
>>> rule = RuleIRV(['a > b > c', 'b > a > c', 'c > a > b'], weights=[2, 3, 4]) >>> rule.eliminations_[0].rule_.gross_scores_ {'a': 2, 'b': 3, 'c': 4} >>> rule.eliminations_[1].rule_.gross_scores_ {'b': 5, 'c': 4} >>> rule.eliminations_[2].rule_.gross_scores_ {'b': 9} >>> rule.winner_ 'b'
An example using the tie-break:
>>> rule = RuleIRV(['a > c > b', 'b > a > c', 'c > a > b'], weights=[1, 2, 1], ... tie_break=Priority.ASCENDING) >>> rule.eliminations_[0].rule_.gross_scores_ {'a': 1, 'b': 2, 'c': 1} >>> rule.eliminations_[1].rule_.gross_scores_ {'a': 2, 'b': 2} >>> rule.eliminations_[2].rule_.gross_scores_ {'a': 4} >>> rule.winner_ 'a'
-
property
cotrailers_¶ “Cotrailers” of the election, i.e. the candidates that fare worst in the election. This is the last equivalence class in
order_. For example, inRuleScoreNum, it is the candidates that are tied for the worst score.- Type
-
property
cowinners_¶ Cowinners of the election, i.e. the candidates that fare best in the election.. This is the first equivalence class in
order_. For example, inRuleScoreNum, it is the candidates that are tied for the best score.- Type
-
property
eliminations_¶ The elimination rounds. A list of
Eliminationobjects. The first one corresponds to the first round, etc.- Type
list
-
property
n_candidates_¶ Number of candidates.
- Type
int
-
property
strict_order_¶ Result of the election as a strict order over the candidates. The first element is the winner, etc. This may use the tie-breaking rule.
- Type
list
-
property
trailer_¶ The “trailer” of the election. This is the last candidate in
strict_order_and also the unfavorable choice of the tie-breaking rule incotrailers_.- Type
object
-
property
winner_¶ The winner of the election. This is the first candidate in
strict_order_and also the choice of the tie-breaking rule incowinners_.- Type
object