RuleSimplifiedDodgson

class whalrus.RuleSimplifiedDodgson(*args, converter: whalrus.converters_ballot.converter_ballot.ConverterBallot = None, matrix_weighted_majority: whalrus.matrices.matrix.Matrix = None, **kwargs)[source]

Simplified Dodgson rule.

The score of a candidate is the sum of the negative non-diagonal coefficient on its raw of matrix_weighted_majority_.

Parameters

Examples

>>> rule = RuleSimplifiedDodgson(ballots=['a > b > c', 'b > a > c', 'c > a > b'],
...                              weights=[3, 3, 2])
>>> rule.matrix_weighted_majority_.as_array_
array([[0, Fraction(1, 4), Fraction(1, 2)],
       [Fraction(-1, 4), 0, Fraction(1, 2)],
       [Fraction(-1, 2), Fraction(-1, 2), 0]], dtype=object)
>>> rule.scores_
{'a': 0, 'b': Fraction(-1, 4), 'c': -1}
>>> rule.winner_
'a'
property average_score_

The average score.

Type

Number

property average_score_as_float_

The average score as a float. It is the same as average_score_, but converted to a float.

Type

float

property 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 than another, a negative number otherwise.

Return type

int

property cotrailers_

“Cotrailers”. The set of candidates with the worst score.

Type

NiceSet

property cowinners_

Cowinners. The set of candidates with the best score.

Type

NiceSet

property matrix_weighted_majority_

The weighted majority matrix (once computed with the given profile).

Type

Matrix

property n_candidates_

Number of candidates.

Type

int

property scores_as_floats_

Scores as floats. It is the same as scores_, but converted to floats.

Type

NiceDict

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 in cotrailers_.

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 in cowinners_.

Type

object

property 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