Paul Lockett

COUNTER FOR ALTERNATIVE VOTE ELECTIONS

Number of Candidates: Number of Votes:
This piece of Javascript will calculate the result of an election conducted using the alternative vote method, also known as instant run-off voting or the single transferable vote for single member constituencies. It produces a verbose output so you can see how it allocates the votes at each stage.

The script can handle up to 20 candidates, although the source code can be amended quite easily to increase the maximum number of candidates. There is no in-built limit on the number of votes the script will handle.

The script will tally the current top preference on each vote and if any candidate has more than half of the current live votes (i.e. those votes which express a preference for one of the candidates who have not been eliminated) it will declare that person the winner. Otherwise, it will eliminate the candidate with the fewest votes, reallocate that candidate's votes and repeat the process. If there are a number of candidates tied in last place, it will eliminate one of them at random.

There is limited validity checking built into the script; you can only select one first preference for each vote, then one second preference, etc. However, it is possible to select one candidate numerous times as, for example, the second and fourth preference. In that instance, only the highest preference expressed for a candidate will be used. If no first preference is expressed, but a second preference is given, the second preference will be treated as the first preference and likewise for lower preferences.


GNU AGPLv3You can re-use the Javascript code in this page under the terms of the GNU AGPL. See the licence notice in the source of the page for more details.