RuleSequentialTieBreak

class whalrus.RuleSequentialTieBreak(*args, rules: list = None, **kwargs)[source]

A rule by sequential tie-break.

Parameters
  • args – Cf. parent class.

  • rules (list of Rule) –

  • kwargs – Cf. parent class.

Examples

The winner is determined by the first rule. If there is a tie, it is broken by the second rule. Etc. There may still be a tie at the end: in that case, it is broken by the tie-breaking rule of this object.

>>> rule = RuleSequentialTieBreak(
...     ['a > d > e > b > c', 'b > d > e > a > c', 'c > d > e > a > b',
...      'd > e > b > a > c', 'e > d > b > a > c'],
...     weights=[2, 2, 2, 1, 1],
...     rules=[RulePlurality(), RuleBorda()], tie_break=Priority.ASCENDING)
>>> rule.rules_[0].gross_scores_
{'a': 2, 'b': 2, 'c': 2, 'd': 1, 'e': 1}
>>> rule.rules_[1].gross_scores_
{'a': 14, 'b': 14, 'c': 8, 'd': 25, 'e': 19}
>>> rule.order_
[{'a', 'b'}, {'c'}, {'d'}, {'e'}]
>>> 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, in RuleScoreNum, it is the candidates that are tied for the worst score.

Type

NiceSet

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, in RuleScoreNum, it is the candidates that are tied for the best score.

Type

NiceSet

property n_candidates_

Number of candidates.

Type

int

property rules_

The rules (once applied to the profile).

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 in cotrailers_.

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 in cowinners_.

Type

object