RuleSequentialElimination¶
-
class
whalrus.
RuleSequentialElimination
(*args, rules: Union[list, whalrus.rules.rule.Rule] = None, eliminations: Union[list, whalrus.eliminations.elimination.Elimination] = None, propagate_tie_break=True, **kwargs)[source]¶ A rule by sequential elimination (such as
RuleTwoRound
).- Parameters
args – Cf. parent class.
rules (list of Rule) – A list of rules, one for each round. Unlike for
RuleIteratedElimination
, different rounds may use different voting rules.eliminations (list of Elimination) – A list of elimination algorithms, one for each round except the last one.
propagate_tie_break (bool) – If True (default), then the tie-breaking rule of this object is also used for the base rules. Cf.
RuleIteratedElimination
for more explanation on this parameter.kwargs – Cf. parent class.
Examples
>>> rule = RuleSequentialElimination( ... ['a > b > c > d > e', 'b > c > d > e > a'], weights=[2, 1], ... rules=[RuleBorda(), RulePlurality(), RulePlurality()], ... eliminations=[EliminationBelowAverage(), EliminationLast(k=1)]) >>> rule.elimination_rounds_[0].rule_.gross_scores_ {'a': 8, 'b': 10, 'c': 7, 'd': 4, 'e': 1} >>> rule.elimination_rounds_[1].rule_.gross_scores_ {'a': 2, 'b': 1, 'c': 0} >>> rule.final_round_.gross_scores_ {'a': 2, 'b': 1}
If
rules
is not a list, the number of rounds is inferred fromeliminations
. An application of this is to define the two-round system:>>> rule = RuleSequentialElimination( ... ['a > b > c > d > e', 'b > a > c > d > e', 'c > a > b > d > e'], weights=[2, 2, 1], ... rules=RulePlurality(), eliminations=[EliminationLast(k=-2)]) >>> rule.elimination_rounds_[0].rule_.gross_scores_ {'a': 2, 'b': 2, 'c': 1, 'd': 0, 'e': 0} >>> rule.final_round_.gross_scores_ {'a': 3, 'b': 2}
Note: there exists a shortcut for the above rule in particular, the class
RuleTwoRound
.Similarly, if
elimination
is not a list, the number of rounds is deduced fromrules
:>>> rule = RuleSequentialElimination( ... ['a > b > c > d > e', 'b > a > c > d > e'], weights=[2, 1], ... rules=[RuleBorda(), RuleBorda(), RulePlurality()], eliminations=EliminationLast(k=1)) >>> rule.elimination_rounds_[0].rule_.gross_scores_ {'a': 11, 'b': 10, 'c': 6, 'd': 3, 'e': 0} >>> rule.elimination_rounds_[1].rule_.gross_scores_ {'a': 8, 'b': 7, 'c': 3, 'd': 0} >>> rule.final_round_.gross_scores_ {'a': 2, 'b': 1, 'c': 0}
-
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
elimination_rounds_
¶ The elimination rounds. A list of
Elimination
objects. All rounds except the last one.- Type
list
-
property
n_candidates_
¶ Number of candidates.
- Type
int
-
property
rounds_
¶ The rounds. All rounds but the last one are
Elimination
objects. The last one is aRule
object.Examples
Note that in some cases, there may be fewer actual rounds than declared in the definition of the rule:
>>> rule = RuleSequentialElimination( ... ['a > b > c > d', 'a > c > d > b', 'a > d > b > c'], ... rules=[RuleBorda(), RulePlurality(), RulePlurality()], ... eliminations=[EliminationBelowAverage(), EliminationLast(k=1)]) >>> len(rule.rounds_) 2 >>> rule.elimination_rounds_[0].rule_.gross_scores_ {'a': 9, 'b': 3, 'c': 3, 'd': 3} >>> rule.final_round_.gross_scores_ {'a': 3}
- Type
list
-
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