Voting Systems in Code


Found this python code, though it’s pretty crap.

INDEX_TO_NAME = {0: 'NDP', 1: 'GREEN', 2: 'LIBERAL', 3: 'CPC'}

def voting_approval(all_ballots):
    results = [0, 0, 0, 0]
    for ballot in all_ballots:
        current_ballot = ballot
        indice = 0
        for candidate in current_ballot:
            if candidate == 'YES':
                results[indice] += 1
                indice += 1
    max = 0
    indice = 0
    winner_name = ''
    for key in results:
        print(INDEX_TO_NAME[indice], 'has a score of', key)
        if(key > max):
            max = key
            winner_name = INDEX_TO_NAME[indice]
        indice += 1
    print(winner_name, results)

ballot1 = ['YES', 'YES', 'YES', 'YES', ]
ballot2 = ['NO', 'NO', 'NO', 'YES', ]
all_ballots = [ballot1, ballot2]

Upload your voting code.


Here’s one that Warren Godone-Maresca setup in Java


A few simple ones:

VSE implements some, too:

Yeah, I wish there were a single canonical open source repository that implements all voting system variants.


Has implementations of a bunch of methods in C, Java, Python

Has implementations in C with a different objective being fast simulation rather than practical running of elections.


You’re it, mate. Here it is.
Thanks to everyone who’s finding these – I saw none of them on my first pass through.


Hi Jameson,

I’d like to try running VSE and test some new methods, but I get errors on my updated Anaconda installation (on Ubuntu 16.04).

Is there somewhere I could get help to debug it?


Hey, Ted. I’ve been able to get it running, if you want some help.

And it looks like some of the “validation” isn’t, well, valid; the code works just fine (for “I’m not certain I trust some of the assumptions…” values of “fine”) if called properly.


Hi Ciaran, yes, I could use some assistance. Mainly, I just want to get around errors like this one:

$ python -m doctest
$ python -m doctest
$ python -m doctest
$ python
File "", line ?, in __main__.CsvBatch.__init__
Failed example:
    csvs = CsvBatch(PolyaModel(), [[Score(), baseRuns], [Mav(), medianRuns]], nvot=5, ncand=4, niter=3)
Expected nothing
    '__init__' ((<__main__.CsvBatch object at 0x7f4e155a0908>, <voterModels.PolyaModel object at 
0x7f4e155a0780>, [[<methods.Score.<locals>.Score0to object at 0x7f4e155a0898>, 
[<stratFunctions.OssChooser object at 0x7f4e15f740b8>, <stratFunctions.ProbChooser object at 
0x7f4e15f740f0>, <stratFunctions.ProbChooser object at 0x7f4e15f74128>, <stratFunctions.ProbChooser 
object at 0x7f4e15f74160>]], [<methods.Mav object at 0x7f4e155a08d0>, [<stratFunctions.OssChooser 
object at 0x7f4e2c118a58>, <stratFunctions.ProbChooser object at 0x7f4e15f66e80>, 
<stratFunctions.ProbChooser object at 0x7f4e15f66eb8>, <stratFunctions.ProbChooser object at 
0x7f4e15f66ef0>, <stratFunctions.ProbChooser object at 0x7f4e15f66f28>, <stratFunctions.ProbChooser 
object at 0x7f4e15f66f60>, <stratFunctions.LazyChooser object at 0x7f4e15f66f98>, 
<stratFunctions.ProbChooser object at 0x7f4e15f66128>]]]), {'nvot': 5, 'ncand': 4, 'niter': 3}) 0.01 sec
1 items had failures:
    1 of   2 in __main__.CsvBatch.__init__
***Test Failed*** 1 failures.


Yup. From what I can tell, that’s largely irrelevant. At least, the code as checked in to GitHub has had those same errors for over a year, since before Jameson most recently updated the charts.

To actually run the code, i just did a from vse import * and then ran the code as shown in the examples on lines 24,25 of


Thanks Ciaran,

What’s the tool to process the SimResults1.csv results file to compare with other methods?

If I add some new methods derived from Mj or Rp, how do I get those into the processing loop?


I’ve just been importing the output CSVs into a database, and taking the average for each of the columns in SQL.

SELECT avg(vse),method,chooser
FROM myTable
GROUP BY method,chooser
ORDER BY method,chooser desc

Lemme just explain what (I understand of) what you see on line 24 of

The first argument for CsvBatch() is the type of model used for the Electorate. My understanding is that PolyaModel is purely random gaussian, KSModel is gaussian clusters. I’m sure if you take a look at, you’ll be able to follow better than I can explain.

The second argument is a list of two element lists, corresponding to [VotingMethod, StrategyTypes]. Methods are described in the eponymous module, and Strategy Types are found in

  • This is where you’d add in Rp or Mj, as for example, changing that argument to, eg,
    [[Score(), baseRuns], [Mav(), medianRuns], [Mj(), medianRuns], [Rp(), medianRuns]]

The module has prebuilt lists of Strategy Sets starting around line 103, and lists of Methods starting at 128.
In my local copy I’ve added “currentMovements” to include Srv(5) (STAR 0-5, EqualVote), Score(5) (Score 0-5, Counted), Approval (CES/Reform Fargo), IRV (FairVote), and Plurality (baseline).

The last three arguments are the number of Voters (nvot), Candidates (ncand), and election simulations (niter) run using that Electorate Model, for each of the elements in list of lists.


here’s the java code i wrote to test my proposed ranked vote tallying algorithm. its flexible enough to also do standard ranked choice, approval voting, allocation voting, etc., and I’ve used it for that.