Overview#

The pref_voting package provides a number of classes that represent different types of elections.

  1. A Profile represents an election where each voter submits a linear order of the candidates.

  2. A ProfileWithTies represents an election where each voter submits a (truncated) ranking of the candidates.

  3. A GradeProfile represents an election where each voter submits a assignment of grades to each candidate.

  4. A UtilityProfile represents a situation where each voter submits a utility function mapping each candidate (or alternative) to a real number.

  5. A SpatialProfile represents a situation where each voter and each candidate are assigned an \(n\)-tuple of numbers from some \(n\)-dimensional space where each dimension represents different issues.

In addition, there are a number of classes that represent different types of (weighted) directed graphs that are used when analyzing elections.

  1. MajorityGraph: a directed asymmetric graph in which the nodes are the candidates and an edge from \(a\) to \(b\) means that \(a\) is majority preferred to \(b\) (i.e., more voters rank \(a\) strictly above \(b\) than rank \(b\) strictly above \(a\)).

  2. MarginGraph: a directed asymmetric graph in which the nodes are the candidates, an edge from \(a\) to \(b\) means that \(a\) is majority preferred to \(b\), and the weight of the edge is the margin of \(a\) over \(b\) (i.e., the number of voters who rank \(a\) strictly above \(b\) minus the number of voters who rank \(b\) strictly above \(a\)).

  3. SupportGraph: a directed asymmetric graph in which the nodes are the candidates, an edge from \(a\) to \(b\) means that \(a\) is majority preferred to \(b\), and the weight of the edge is the number of voters who rank \(a\) strictly above \(b\).

Helper Function: Creating Elections#

pref_voting.helper.create_election(ranking_list, rcounts=None, using_extended_strict_preference=None, candidates=None)[source]#

Creates an election from a list of rankings.

Parameters:
  • ranking_list (list) – A list of rankings, which may be a list of tuples of candidates, a list of dictionaries or a list of Ranking objects.

  • using_extended_strict_preference (bool, optional) – Whether to use extended strict preference after creating a ProfileWithTies. Defaults to None.

  • candidates (list, optional) – A list of candidates. Only used for creating a ProfileWithTies. Defaults to None (by default the candidates are all the candidates that are ranked by at least on voter).

Returns:

The election profile.

Return type:

Profile or ProfileWithTies