EliminationLast

class whalrus.EliminationLast(*args, k: int = 1, **kwargs)[source]

Elimination of the last candidates (with a fixed number of candidates to eliminate, or to qualify).

Parameters
  • args – Cf. parent class.

  • k (int) – A nonzero integer. The number of eliminated candidates. If this number is negative, then len(rule.candidates_) - abs(k) candidates are eliminated, i.e. abs(k) candidates are qualified.

  • kwargs` – Cf. parent class.

Examples

In the most general syntax, firstly, you define the elimination method:

>>> elimination = EliminationLast(k=1)

Secondly, you use it as a callable to load a particular election (rule, profile, candidates):

>>> rule = RulePlurality(ballots=['a', 'a', 'b', 'b', 'c'])
>>> elimination(rule)  
<... object at ...>

Finally, you can access the computed variables:

>>> elimination.eliminated_
{'c'}

Later, if you wish, you can load another election with the same elimination method, and so on.

Optionally, you can specify an election (rule, profile, candidates) as soon as the Elimination object is initialized. This allows for one-liners such as:

>>> EliminationLast(rule=RulePlurality(ballots=['a', 'a', 'b', 'b', 'c']), k=1).eliminated_
{'c'}

Typical usage with k = 1 (e.g. for RuleIRV):

>>> rule = RulePlurality(ballots=['a', 'a', 'a', 'b', 'b', 'c', 'c', 'd', 'e'],
...                      tie_break=Priority.ASCENDING)
>>> EliminationLast(rule=rule, k=1).eliminated_
{'e'}

Typical usage with k = -2 (e.g. for RuleTwoRound):

>>> rule = RulePlurality(ballots=['a', 'a', 'a', 'b', 'b', 'c', 'c', 'd', 'e'],
...                      tie_break=Priority.ASCENDING)
>>> EliminationLast(rule=rule, k=-2).qualified_
{'a', 'b'}

Order of elimination:

>>> rule = RulePlurality(ballots=['a', 'a', 'a', 'b', 'b', 'c', 'c', 'd', 'e'],
...                      tie_break=Priority.ASCENDING)
>>> EliminationLast(rule=rule, k=-2).eliminated_order_
[{'c'}, {'d', 'e'}]

There must always be at least one eliminated candidate. If it is not possible to eliminate (case k > 0) or keep (case k < 0) as many candidates as required, then everybody is eliminated:

>>> rule = RulePlurality(ballots=['a'])
>>> EliminationLast(rule=rule, k=1).eliminated_
{'a'}
>>> EliminationLast(rule=rule, k=-2).eliminated_
{'a'}
property eliminated_

The eliminated candidates.

This should always be non-empty. It may contain all the candidates (for example, it is always the case when there was only one candidate in the election).

Type

NiceSet

property qualified_

The candidates that are qualified (not eliminated).

Type

NiceSet