RuleBucklinByRounds¶
-
class
whalrus.
RuleBucklinByRounds
(*args, converter: whalrus.converters_ballot.converter_ballot.ConverterBallot = None, scorer: whalrus.scorers.scorer_bucklin.ScorerBucklin = None, **kwargs)[source]¶ Bucklin’s rule (round by round version).
During the first round, a candidate’s score is the proportion of voters who rank it first. During the second round, its score is the proportion of voters who rank it first or second. Etc. More precisely, at each round, the
scorer
is used withk
equal to the round number; cf.ScorerBucklin
.For another variant of Bucklin’s rule, cf.
RuleBucklinInstant
.Parameters: - args – Cf. parent class.
- converter (ConverterBallot) – Default:
ConverterBallotToOrder
. - scorer (Scorer) – Default:
ScorerBucklin
. - kwargs – Cf. parent class.
Examples
>>> rule = RuleBucklinByRounds(['a > b > c > d', 'b > a > c > d', ... 'c > a > b > d', 'd > a > b > c']) >>> rule.detailed_scores_[0] {'a': Fraction(1, 4), 'b': Fraction(1, 4), 'c': Fraction(1, 4), 'd': Fraction(1, 4)} >>> rule.detailed_scores_[1] {'a': 1, 'b': Fraction(1, 2), 'c': Fraction(1, 4), 'd': Fraction(1, 4)} >>> rule.n_rounds_ 2 >>> rule.scores_ {'a': 1, 'b': Fraction(1, 2), 'c': Fraction(1, 4), 'd': Fraction(1, 4)} >>> rule.winner_ 'a'
-
average_score_
¶ The average score.
Type: Number
-
average_score_as_float_
¶ The average score as a float. It is the same as
average_score_
, but converted to a float.Type: float
-
best_score_as_float_
¶ The best score as a float. It is the same as
RuleScore.best_score_
, but converted to a float.Type: float
-
compare_scores
(one: numbers.Number, another: numbers.Number) → int¶ 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
-
detailed_scores_
¶ Detailed scores. A list of
NiceDict
. The first dictionary gives the scores of the first round, etc.Type: list
-
detailed_scores_as_floats_
¶ Detailed scores, as floats. It is the same as
detailed_scores_
, but converted to floats.Examples
>>> rule = RuleBucklinByRounds(['a > b > c > d', 'b > a > c > d', ... 'c > a > b > d', 'd > a > b > c']) >>> rule.detailed_scores_as_floats_[0] {'a': 0.25, 'b': 0.25, 'c': 0.25, 'd': 0.25} >>> rule.detailed_scores_as_floats_[1] {'a': 1.0, 'b': 0.5, 'c': 0.25, 'd': 0.25}
Type: list
-
n_candidates_
¶ Number of candidates.
Type: int
-
n_rounds_
¶ The number of rounds.
Type: int
-
scores_
¶ The scores. For each candidate, it gives its score during the final round, i.e. the first round where at least one candidate has a score above 1 / 2.
Type: NiceDict
-
scores_as_floats_
¶ Scores as floats. It is the same as
scores_
, but converted to floats.Type: NiceDict
-
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
-
worst_score_as_float_
¶ The worst score as a float. It is the same as
RuleScore.worst_score_
, but converted to a float.Type: float