RuleBucklinInstant¶
-
class
whalrus.
RuleBucklinInstant
(*args, converter: whalrus.converters_ballot.converter_ballot.ConverterBallot = None, scorer: whalrus.scorers.scorer.Scorer = None, default_median: object = 0, **kwargs)[source]¶ Bucklin’s rule (instant version).
For each candidate, its median Borda score m is computed. Let x be the number of voters who give this candidate a Borda score that is greater or equal to m. Then the candidate’s score is (m, x). Scores are compared lexicographically.
When preferences are strict orders, it is equivalent to say that:
The candidate with the lowest median rank is declared the winner.
If several candidates have the lowest median rank, this tie is broken by examining how many voters rank each of them with this rank or better.
For another variant of Bucklin’s rule, cf.
RuleBucklinByRounds
.- Parameters
args – Cf. parent class.
converter (ConverterBallot) – Default:
ConverterBallotToOrder
.scorer (Scorer) – Default:
ScorerBorda
withabsent_give_points=True
,absent_receive_points=None
,unordered_give_points=True
,unordered_receive_points=False
.default_median (object) – The default median of a candidate when it receives no score whatsoever.
kwargs – Cf. parent class.
Examples
>>> rule = RuleBucklinInstant(ballots=['a > b > c', 'b > a > c', 'c > a > b']) >>> rule.scores_ {'a': (1, 3), 'b': (1, 2), 'c': (0, 3)} >>> rule.winner_ 'a'
With the default settings, and when preferences are strict total orders,
RuleBucklinByRounds
andRuleBucklinInstant
have the same winner (although not necessarily the same order over the candidates). Otherwise, the winners may differ:>>> profile = Profile(ballots=['a > b > c > d', 'b > a ~ d > c', 'c > a ~ d > b'], ... weights=[3, 3, 4]) >>> rule_bucklin_by_rounds = RuleBucklinByRounds(profile) >>> rule_bucklin_by_rounds.detailed_scores_[0] {'a': Fraction(3, 10), 'b': Fraction(3, 10), 'c': Fraction(2, 5), 'd': 0} >>> rule_bucklin_by_rounds.detailed_scores_[1] {'a': Fraction(13, 20), 'b': Fraction(3, 5), 'c': Fraction(2, 5), 'd': Fraction(7, 20)} >>> rule_bucklin_by_rounds.winner_ 'a' >>> rule_bucklin_instant = RuleBucklinInstant(profile) >>> rule_bucklin_instant.scores_ {'a': (Fraction(3, 2), 10), 'b': (2, 6), 'c': (1, 7), 'd': (Fraction(3, 2), 7)} >>> RuleBucklinInstant(profile).winner_ 'b'
-
property
best_score_
¶ The best score.
- Type
object
-
compare_scores
(one: tuple, another: tuple) → int[source]¶ Compare two scores.
- Parameters
one (object) – A score.
another (object) – A score.
- Returns
0 if they are equal, a positive number if
one
is greater thananother
, a negative number otherwise.- Return type
int
-
property
n_candidates_
¶ Number of candidates.
- Type
int
-
property
order_
¶ Result of the election as a (weak) order over the candidates. It is a list of
NiceSet
. The first set contains the candidates that have the best score, the second set contains those with the second best score, etc.- Type
list
-
property
scores_as_floats_
¶ Scores as floats. It is the same as
scores_
, but converted to floats.Examples
>>> rule = RuleBucklinInstant(ballots=['a > b > c', 'b > a > c', 'c > a > b']) >>> rule.scores_as_floats_ {'a': (1.0, 3.0), 'b': (1.0, 2.0), 'c': (0.0, 3.0)}
- Type
-
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
-
property
worst_score_
¶ The worst score.
- Type
object