Election

[1]:
import svvamp

Create a population of 9 voters with preferences over 5 candidates, using the Spheroid model (which extends Impartial Culture to utilities):

[2]:
random_profile = svvamp.GeneratorProfileSpheroid(n_v=9, n_c=5)
profile = random_profile()

Preference rankings of the voters:

[3]:
profile.preferences_rk
[3]:
array([[0, 1, 4, 2, 3],
       [3, 0, 4, 1, 2],
       [4, 2, 3, 1, 0],
       [2, 3, 0, 4, 1],
       [0, 1, 4, 3, 2],
       [2, 1, 4, 3, 0],
       [4, 2, 0, 3, 1],
       [4, 2, 0, 1, 3],
       [1, 4, 0, 2, 3]])

Define a voting rule:

[4]:
rule = svvamp.RulePlurality()

Load the profile into the voting rule:

[5]:
rule(profile)
[5]:
<svvamp.rules.rule_plurality.RulePlurality at 0x2061f15e9a0>

Ballots:

[6]:
rule.ballots_
[6]:
array([0, 3, 4, 2, 0, 2, 4, 4, 1])

Scores:

[7]:
rule.scores_
[7]:
array([2, 1, 2, 1, 3])

Order the candidates according to their scores:

[8]:
rule.candidates_by_scores_best_to_worst_
[8]:
array([4, 0, 2, 1, 3], dtype=int64)
[9]:
rule.scores_best_to_worst_
[9]:
array([3, 2, 2, 1, 1])

The winner, her score and her total utility:

[10]:
rule.w_
[10]:
4
[11]:
rule.score_w_
[11]:
3
[12]:
rule.total_utility_w_
[12]:
0.5038515767548695

Decide whether the winner of the election is a Condorcet winner:

[13]:
rule.w_is_condorcet_winner_ut_abs_
[13]:
True