https://github.com/bradbeattie/python-vote-core
Python libraries for various electoral methods
https://github.com/bradbeattie/python-vote-core
Last synced: 21 days ago
JSON representation
Python libraries for various electoral methods
- Host: GitHub
- URL: https://github.com/bradbeattie/python-vote-core
- Owner: bradbeattie
- License: other
- Created: 2009-12-14T07:03:14.000Z (almost 16 years ago)
- Default Branch: master
- Last Pushed: 2021-12-25T02:27:16.000Z (almost 4 years ago)
- Last Synced: 2025-05-07T14:58:47.758Z (6 months ago)
- Language: Python
- Homepage: http://modernballots.com
- Size: 224 KB
- Stars: 141
- Watchers: 13
- Forks: 36
- Open Issues: 14
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
Python Vote Core
================
python-vote-core implements various electoral methods, providing the results
calculated off a provided set of ballots and options.
* Project page: http://github.com/bradbeattie/python-vote-core
* Issue tracker: http://github.com/bradbeattie/python-vote-core/issues
* Example usage: http://modernballots.com
Methods implemented
-------------------
* Single Winner Methods
* Plurality (aka first-past-the-post or fptp)
* Instant-Runoff Voting (aka IRV)
* Schulze Method (aka Beatpath)
* Multiple Winner Methods
* Plurality at large (aka block voting)
* Single Transferable Vote (aka STV)
* Schulze STV
* Ordering Methods
* Schulze Proportional Representation
* Schulze Nonproportional Representation
Basic Usage
-----------
Schulze method example::
>>> from pyvotecore.schulze_method import SchulzeMethod
>>> from pyvotecore.condorcet import CondorcetHelper
>>> ballots = [
... { "count":3, "ballot":[["A"], ["C"], ["D"], ["B"]] },
... { "count":9, "ballot":[["B"], ["A"], ["C"], ["D"]] },
... { "count":8, "ballot":[["C"], ["D"], ["A"], ["B"]] },
... { "count":5, "ballot":[["D"], ["A"], ["B"], ["C"]] },
... { "count":5, "ballot":[["D"], ["B"], ["C"], ["A"]] }
... ]
>>> SchulzeMethod(ballots, ballot_notation = CondorcetHelper.BALLOT_NOTATION_GROUPING).as_dict()
{'actions': [{'edges': {('A', 'B')}},
{'edges': {('A', 'C')}},
{'nodes': {'A'}},
{'edges': {('B', 'C')}},
{'nodes': {'B', 'D'}}],
'candidates': {'A', 'B', 'C', 'D'},
'pairs': {('A', 'B'): 16,
('A', 'C'): 17,
('A', 'D'): 12,
('B', 'A'): 14,
('B', 'C'): 19,
('B', 'D'): 9,
('C', 'A'): 13,
('C', 'B'): 11,
('C', 'D'): 20,
('D', 'A'): 18,
('D', 'B'): 21,
('D', 'C'): 10},
'strong_pairs': {('A', 'B'): 16,
('A', 'C'): 17,
('B', 'C'): 19,
('C', 'D'): 20,
('D', 'A'): 18,
('D', 'B'): 21},
'winner': 'C'}