Pairwise Profiles¶
Pairwise Profile Class¶
- class pref_voting.pairwise_profiles.PairwiseBallot(comparisons, candidates=None, cmap=None)[source]¶
- add_comparison(menu, choice)[source]¶
Add a new comparison to the existing comparisons.
- Parameters:
menu (set) – A set of candidates representing the menu.
choice (set) – A set of candidates representing the choice set.
- Raises:
ValueError – If the new comparison is not coherent with the existing comparisons.
- add_strict_preference(c1, c2)[source]¶
Add a new comparison to the existing comparisons where c1 is strictly preferred to c2.
- Parameters:
c1 (int, str) – A candidate
c2 (int, str) – A candidate.
- Raises:
ValueError – If the new comparison is not coherent with the existing comparisons.
- get_comparison(c1, c2)[source]¶
Get the comparison between two candidates.
- Parameters:
c1 (str or int) – First candidate.
c2 (str or int) – Second candidate.
- Returns:
The comparison between c1 and c2.
- Return type:
tuple
- has_comparison(c1, c2)[source]¶
Check if there is a comparison between two candidates.
- Parameters:
c1 (str or int) – First candidate.
c2 (str or int) – Second candidate.
- Returns:
True if there is a comparison between c1 and c2, False otherwise.
- Return type:
bool
- indiff(c1, c2)[source]¶
Return the revealed indifference of a menu of choices.
- Parameters:
c1 (str or int) – First candidate.
c2 (str or int) – Second candidate.
- Returns:
True if there is indifference between c1 and c2, False otherwise.
- Return type:
bool
- is_coherent()[source]¶
Check if the pairwise comparisons are coherent.
- Returns:
True if the pairwise comparisons are coherent, False otherwise.
- Return type:
bool
- 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