I would like to understand how the condorcet winner is elected in a ranked-choice election.
There is an example on wikipedia - under the sub-heading "Pairwise counting and matrices" under the heading "Basic procedure", in which the pairwise comparison matrix is constructed for candidates A, B, C, and D in an election. The matrix looks like:
From this matrix, it is concluded that A is the condorcet winner. I can see that the result is correct, but do not understand how to algorithmically approach this problem.
`
[[0, 2, 2, 2],
[1, 0, 1, 2],
[1, 2, 0, 2],
[1, 1, 1, 0]]
`
A more complicated example can be found on table 2-a at accuratedemocracy; when considering a different election with candidates A, B, C, and D; they find that C is the winner, but one can click cells C and D to verify that they earn the same number of votes in the pairwise comparison matrix. Why is C the winner and not D?
Suppose one has constructed the pair-wise comparison matrix. How can one select the condorcet winner from this matrix?
An example, one can construct the pairwise comparison matrix in python using the following code:
`
import numpy as np
unranked_choices = ["A", "B", "C", "D"]
def generate_preference_matrix(ranked_choices):
num_candidates = len(ranked_choices)
preference_matrix = np.zeros((num_candidates, num_candidates))
for i, candidate_i in enumerate(unranked_choices):
for j, candidate_j in enumerate(unranked_choices):
if i != j:
if ranked_choices.index(candidate_i) < ranked_choices.index(candidate_j):
preference_matrix[i, j] += 1 # Candidate_i is preferred over candidate_j
# else:
# preference_matrix[i, j] = 0 # No preference or candidate_j is preferred over candidate_i
return preference_matrix
# Test with example ranked choices
ranked_choices = ['B', 'C', 'A', 'D'] # Ranked choices in order of preference
preference_matrix = generate_preference_matrix(ranked_choices)
print(preference_matrix)
ranked_choices = ['A', 'D', 'B', 'C'] # Ranked choices in order of preference
preference_matrix = generate_preference_matrix(ranked_choices)
print(preference_matrix)
`
You need to sum the preference matrices in order to calculate the ranking. The candidate with the highest total is the declared the winner.
Using the data from the example on the Wikipedia page:
Result: