0.0
No commit activity in last 3 years
No release in over 3 years
Implementations of various voting systems.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
 Project Readme

voting_systems

Ruby gem implementing various voting systems.

Each voting system (e.g. borda) takes a set of preferences as input. Each preference is a ranking of alternatives. The output is the winning alternative(s).

Ties and omissions are allowed in the preferences. Omitted alternatives are considered least preferred.

All of the systems are deterministic. There is no random tie-breaking. If the result is a tie, all of the tied alternatives will be returned.

Systems

method name description
baldwin Baldwin method
borda Borda count
bucklin Bucklin voting
coombs Coombs' method
copeland Copeland's method
instant_runoff Instant-runoff voting
ranked_pairs Ranked pairs

Installation

gem install voting_systems

Usage

require 'voting_systems'

There are two input formats. The first looks like:

votes = '4:A>B>C
         5:B>C>A
         2:C=A>B'

This means 4 voters have the preference A>B>C, 5 voters have B>C>A, and 2 voters have C=A>B (meaning that C and A are equally preferred, and both are preferred to B).

The second looks like:

votes = [
  [4, ['A','B','C']],
  [5, ['B','C','A']],
  [2, [['C','A'],'B']],
]

Here, the alternatives need not be strings, but can be any object.

To find the winner(s) for a given system (e.g. borda):

winners = borda votes
=> ["B"]

Author

Tim Smith (timlabs.org)