Pairwise Profiles

Pairwise Profile Class

class pref_voting.pairwise_profiles.PairwiseProfile(pairwise_comparisons, candidates=None, rcounts=None, cmap=None)[source]

An anonymous profile of pairwise comparisons.

Parameters:

pairwise_comparisons – List of comparisons or PairwiseBallot instances.

property comparisons_counts

Returns the submitted rankings and the list of counts.

condorcet_loser(curr_cands=None)[source]

Returns the Condorcet loser in the profile restricted to curr_cands if one exists, otherwise return None.

Parameters:

curr_cands (list, optional) – List of candidates to consider. Defaults to None.

Returns:

Condorcet loser if one exists, otherwise None.

Return type:

str or int

condorcet_winner(curr_cands=None)[source]

Returns the Condorcet winner in the profile restricted to curr_cands if one exists, otherwise return None.

Parameters:

curr_cands (list, optional) – List of candidates to consider. Defaults to None.

Returns:

Condorcet winner if one exists, otherwise None.

Return type:

str or int

copeland_scores(curr_cands=None, scores=(1, 0, -1))[source]

The Copeland scores in the profile restricted to the candidates in curr_cands.

Parameters:
  • curr_cands (list, optional) – List of candidates to consider. Defaults to None.

  • scores (tuple, optional) – Scores for win, tie, and loss. Defaults to (1, 0, -1).

Returns:

Dictionary associating each candidate in curr_cands with its Copeland score.

Return type:

dict

display(cmap=None, style='pretty', curr_cands=None)[source]

Display the profile (restricted to curr_cands) as an ASCII table.

Parameters:
  • cmap (dict, optional) – Mapping of candidates to their names. Defaults to None.

  • style (str, optional) – Style of the display. Defaults to “pretty”.

  • curr_cands (list, optional) – List of candidates to consider. Defaults to None.

dominates(cand, curr_cands=None)[source]

Returns the list of candidates that cand is majority preferred to in the profile restricted to curr_cands.

Parameters:
  • cand (str or int) – The candidate.

  • curr_cands (list, optional) – List of candidates to consider. Defaults to None.

Returns:

List of candidates that cand is majority preferred to.

Return type:

list

dominators(cand, curr_cands=None)[source]

Returns the list of candidates that are majority preferred to cand in the profile restricted to the candidates in curr_cands.

Parameters:
  • cand (str or int) – The candidate.

  • curr_cands (list, optional) – List of candidates to consider. Defaults to None.

Returns:

List of candidates that are majority preferred to cand.

Return type:

list

is_tied(c1, c2)[source]

Returns True if c1 is tied with c2.

Parameters:
  • c1 (str or int) – The first candidate.

  • c2 (str or int) – The second candidate.

Returns:

True if c1 is tied with c2, False otherwise.

Return type:

bool

majority_graph()[source]

Returns the margin graph of the profile.

Returns:

Margin graph of the profile.

Return type:

dict

majority_prefers(c1, c2)[source]

Returns true if more voters rank c1 over c2 than c2 over c1.

Parameters:
  • c1 (str or int) – The first candidate.

  • c2 (str or int) – The second candidate.

Returns:

True if c1 is majority preferred over c2, False otherwise.

Return type:

bool

margin(c1, c2)[source]

The number of voters that rank c1 above c2 minus the number of voters that rank c2 above c1.

Parameters:
  • c1 (str or int) – The first candidate.

  • c2 (str or int) – The second candidate.

Returns:

Margin of votes.

Return type:

int

margin_graph()[source]

Returns the margin graph of the profile.

Returns:

Margin graph of the profile.

Return type:

dict

num_voters

The number of voters in the election.

strict_maj_size()[source]

Returns the strict majority of the number of voters.

Returns:

Size of the strict majority.

Return type:

int

support(c1, c2)[source]

The number of voters that rank c1 above c2.

Parameters:
  • c1 (str or int) – The first candidate.

  • c2 (str or int) – The second candidate.

Returns:

Number of voters that rank c1 above c2.

Return type:

int

weak_condorcet_winner(curr_cands=None)[source]

Returns a list of the weak Condorcet winners in the profile restricted to curr_cands.

Parameters:

curr_cands (list, optional) – List of candidates to consider. Defaults to None.

Returns:

List of weak Condorcet winners.

Return type:

list