Social Choice Theory in Python
Project description
socialchoice: a library for Social Choice Theory
This library implements social choice mechanisms.
Install
socialchoice is on PyPI, so:
pip3 install socialchoice
A minimal example
Here, we have two pairwise votes submitted, where "a"
beat "b"
, and "c"
lost to "b"
. We want to compute the ranked pairs result for this vote set.
>>> from socialchoice import PairwiseBallotBox, Election
>>> pairwise_ballots = PairwiseBallotBox([("a", "b", "win"), ("c", "b", "loss")])
>>> election = Election(pairwise_ballots)
>>> election.ranking_by_ranked_pairs()
['a', 'b', 'c']
A slightly less minimal example
Let's run a ranked choice election, using ranked pairs again.
>>> from socialchoice import RankedChoiceBallotBox, Election
>>> ranked_ballots = RankedChoiceBallotBox([[1,2,3,4], [1, {2,3}, 4]])
>>> election = Election(ranked_ballots)
>>> election.ranking_by_ranked_pairs()
[1, 2, 3, 4]
Notice that ties are allowed - simply submit a set as one element of your ranking, and each of those will be counted as ties. Ranked choice ballots are converted into pairwise preferences, and then ranked pairs can be run on the result.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
socialchoice-0.0.4.tar.gz
(10.4 kB
view hashes)