RuleBlack¶
-
class
whalrus.RuleBlack(*args, rule_condorcet: whalrus.rules.rule.Rule = None, rule_borda: whalrus.rules.rule.Rule = None, **kwargs)[source]¶ Black’s rule.
- Parameters
args – Cf. parent class.
rule_condorcet (Rule) – Used as the main victory criterion. Default:
RuleCondorcet.rule_borda (Rule) – Used as the secondary victory criterion. Default:
RuleBorda.kwargs – Cf. parent class.
Examples
As a main victory criterion, the Condorcet winner is elected (even if it does not have the highest Borda score):
>>> rule = RuleBlack(ballots=['a > b > c', 'b > c > a'], weights=[3, 2]) >>> rule.rule_condorcet_.matrix_majority_.matrix_weighted_majority_.as_array_ array([[0, Fraction(3, 5), Fraction(3, 5)], [Fraction(2, 5), 0, 1], [Fraction(2, 5), 0, 0]], dtype=object) >>> rule.order_ [{'a'}, {'b'}, {'c'}]
When there is no Condorcet winner, candidates are sorted according to their Borda scores:
>>> rule = RuleBlack(ballots=['a > b > c', 'b > c > a', 'c > a > b'], weights=[3, 2, 2]) >>> rule.rule_condorcet_.matrix_majority_.matrix_weighted_majority_.as_array_ array([[0, Fraction(5, 7), Fraction(3, 7)], [Fraction(2, 7), 0, Fraction(5, 7)], [Fraction(4, 7), Fraction(2, 7), 0]], dtype=object) >>> rule.order_ [{'a'}, {'b'}, {'c'}]
-
property
cotrailers_¶ “Cotrailers” of the election, i.e. the candidates that fare worst in the election. This is the last equivalence class in
order_. For example, inRuleScoreNum, it is the candidates that are tied for the worst score.- Type
-
property
cowinners_¶ Cowinners of the election, i.e. the candidates that fare best in the election.. This is the first equivalence class in
order_. For example, inRuleScoreNum, it is the candidates that are tied for the best score.- Type
-
property
n_candidates_¶ Number of candidates.
- Type
int
-
property
rule_borda_¶ The Borda rule (once applied to the profile).
Examples
>>> rule = RuleBlack(ballots=['a > b > c', 'b > c > a'], weights=[3, 2]) >>> rule.rule_borda_.scores_ {'a': Fraction(6, 5), 'b': Fraction(7, 5), 'c': Fraction(2, 5)}
- Type
-
property
rule_condorcet_¶ The Condorcet rule (once applied to the profile).
Examples
>>> rule = RuleBlack(ballots=['a > b > c', 'b > c > a'], weights=[3, 2]) >>> rule.rule_condorcet_.matrix_majority_.as_array_ array([[Fraction(1, 2), 1, 1], [0, Fraction(1, 2), 1], [0, 0, Fraction(1, 2)]], dtype=object)
- Type
-
property
rules_¶ The rules (once applied to the profile).
- Type
list
-
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