RuleTwoRound¶
-
class
whalrus.
RuleTwoRound
(*args, rule1: whalrus.rules.rule.Rule = None, rule2: whalrus.rules.rule.Rule = None, elimination: whalrus.eliminations.elimination.Elimination = None, **kwargs)[source]¶ The two-round system.
Parameters: - args – Cf. parent class.
- rule1 – The first rule. Default:
RulePlurality
. - rule2 – The second rule. Default:
RulePlurality
. - elimination (Elimination) – The elimination algorithm used during the first round. Default:
EliminationLast
withk=-2
, which only keeps the 2 best candidates. - kwargs – Cf. parent class.
Examples
With its default settings, this class implements the classic two-round system, using plurality at both rounds:
>>> rule = RuleTwoRound(['a > b > c > d > e', 'b > a > c > d > e', 'c > a > b > d > e'], ... weights=[2, 2, 1]) >>> rule.first_round_.rule_.gross_scores_ {'a': 2, 'b': 2, 'c': 1, 'd': 0, 'e': 0} >>> rule.second_round_.gross_scores_ {'a': 3, 'b': 2}
Using the options, some more exotic two-round systems can be defined, such as changing the rule of a round:
>>> rule = RuleTwoRound(['a > b > c > d > e', 'b > a > c > d > e', 'c > a > b > d > e'], ... weights=[2, 2, 1], rule1=RuleBorda()) >>> rule.first_round_.rule_.gross_scores_ {'a': 17, 'b': 16, 'c': 12, 'd': 5, 'e': 0} >>> rule.second_round_.gross_scores_ {'a': 3, 'b': 2}
… or changing the elimination algorithm:
>>> rule = RuleTwoRound(['a > b > c > d > e', 'b > a > c > d > e', 'c > a > b > d > e'], ... weights=[2, 2, 1], elimination=EliminationLast(k=-3)) >>> rule.first_round_.rule_.gross_scores_ {'a': 2, 'b': 2, 'c': 1, 'd': 0, 'e': 0} >>> rule.second_round_.gross_scores_ {'a': 2, 'b': 2, 'c': 1}
-
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: NiceSet
-
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: NiceSet
-
elimination_rounds_
¶ The elimination rounds. A list of
Elimination
objects. All rounds except the last one.Type: list
-
first_round_
¶ The first round. This is just a shortcut for
self.elimination_rounds_[0]
.Type: Elimination
-
n_candidates_
¶ Number of candidates.
Type: int
-
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
-
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
-
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
-
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