RuleKApproval¶
-
class
whalrus.
RuleKApproval
(*args, k: int = 1, **kwargs)[source]¶ K-Approval
The
k
top candidates in a ballot receive 1 point, and the other candidates receive 0 point.Parameters: - args – Cf. parent class.
- k (int) – The number of approved candidates.
- kwargs – Cf. parent class.
Examples
>>> RuleKApproval(['a > b > c', 'b > c > a'], k=2).gross_scores_ {'a': 1, 'b': 2, 'c': 1}
-
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
-
gross_scores_
¶ The gross scores of the candidates. For each candidate, this dictionary gives the sum of its scores, multiplied by the weights of the corresponding voters. This is the numerator in the candidate’s average score.
Type: NiceDict
-
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_
¶ The weights used for the candidates. For each candidate, this dictionary gives the total weight for this candidate, i.e. the total weight of all voters who assign a score to this candidate. This is the denominator in the candidate’s average score.
Type: NiceDict
-
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