RulePlurality¶
-
class
whalrus.RulePlurality(*args, converter: whalrus.converters_ballot.converter_ballot.ConverterBallot = None, scorer: whalrus.scorers.scorer.Scorer = None, **kwargs)[source]¶ The plurality rule.
Parameters: - args – Cf. parent class.
- converter (ConverterBallot) – Default:
ConverterBallotToPlurality. - scorer (Scorer) – Default:
ScorerPlurality. - kwargs – Cf. parent class.
Examples
In the most general syntax, firstly, you define the rule:
>>> plurality = RulePlurality(tie_break=Priority.ASCENDING)
Secondly, you use it as a callable to load a particular election (profile, candidates):
>>> plurality(ballots=['a', 'b', 'c'], weights=[2, 2, 1], voters=['Alice', 'Bob', 'Cate'], ... candidates={'a', 'b', 'c', 'd'}) # doctest:+ELLIPSIS <... object at ...>
Finally, you can access the computed variables:
>>> plurality.gross_scores_ {'a': 2, 'b': 2, 'c': 1, 'd': 0} >>> plurality.winner_ 'a'
Later, if you wish, you can load another profile with the same voting rule, and so on.
Optionally, you can specify an election (profile and candidates) as soon as the
Ruleobject is initialized. This allows for one-liners such as:>>> RulePlurality(['a', 'a', 'b', 'c']).winner_ 'a'
Cf.
Rulefor more information about the arguments.-
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
oneis greater thananother, a negative number otherwise.Return type: int
-
gross_scores_as_floats_¶ Gross scores as floats. It is the same as
gross_scores_, but converted to floats.Type: NiceDict
-
n_candidates_¶ Number of candidates.
Type: int
-
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
-
weights_as_floats_¶ Weights as floats. It is the same as
weights_, but converted to floats.Type: NiceDict
-
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