python-vote-core implements various electoral methods, providing the results calculated off a provided set of ballots and options. This fork implements only Python3 compatibility!
This fork implements Python3 functionality by using 2to3 and then cherry-picking fixes from other people's forks. This is certainly not a clean way to do so but 100% of the tests pass on Python3.
This fork exists solely to have a PyPI release under Python3.
Single Winner Methods
Multiple Winner Methods
Ordering Methods
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'}
Copyright (C) 2009, Brad Beattie
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses.
Version | Tag | Published |
---|---|---|
20170329.0 | 6yrs ago |