Expand description

The ranked_voting crate provides a thoroughly tested implementation of the Instant-Runoff Voting algorithm, which is also called ranked-choice voting in the United States, preferential voting in Australia or alternative vote in the United Kingdom.

This library can be used in multiple flavours:

  • as a simple library for most cases (see the run_election1 function)

  • as a command-line utility that provides fast and easy election results that can then be displayed or exported. The section timrcv provides a manual.

  • as a more complex library that can handle all the diversity of implementations. It provides for example multiple ways to deal with blank or absentee ballots, undeclared candidates, etc. If you are attempting to replicate the results of a specific elections, you should carefully check the voting rules and use the configuration accordingly. If you are doing so, you should check run_election and VoteRules

timrcv

timrcv is a command-line program to run an instant runoff election. It can accomodate all common formats from vendors or public offices. This document presents a tutorial on how to use it.

Installation

Download the latest release from the releases page. Pre-compiled versions are available for Windows, MacOS and Linux.

Quick start with existing data

If you are running a poll and are collecting data using Microsoft Forms, Google Form, Qualtrics, look at the quick start using Google Forms.

If you have very simple needs and you can collect data in a small text file, timrcv accepts a simple format of comma-separated values.

To get started, let us say that you have a file with the following records of votes (example.csv). Each line corresponds to a vote, and A,B,C and D are the candidates:

A,B,,D
A,C,B,
B,A,D,C
B,C,A,D
C,A,B,D
D,B,A,C

Each line is a recorded vote. The first line A,B,,D says that this voter preferred candidate A over everyone else (his/her first choice), followed by B as a second choice and finally D as a last choice.

Running a vote with the default options is simply:

timrcv --input example.csv

Output:

[ INFO  ranked_voting] run_voting_stats: Processing 6 votes
[ INFO  ranked_voting] Processing 6 aggregated votes
[ INFO  ranked_voting] Candidate: 1: A
[ INFO  ranked_voting] Candidate: 2: B
[ INFO  ranked_voting] Candidate: 3: C
[ INFO  ranked_voting] Candidate: 4: D
[ INFO  ranked_voting] Round 1 (winning threshold: 4)
[ INFO  ranked_voting]       2 B -> running
[ INFO  ranked_voting]       2 A -> running
[ INFO  ranked_voting]       1 C -> running
[ INFO  ranked_voting]       1 D -> eliminated:1 -> B,
[ INFO  ranked_voting] Round 2 (winning threshold: 4)
[ INFO  ranked_voting]       3 B -> running
[ INFO  ranked_voting]       2 A -> running
[ INFO  ranked_voting]       1 C -> eliminated:1 -> A,
[ INFO  ranked_voting] Round 3 (winning threshold: 4)
[ INFO  ranked_voting]       3 A -> running
[ INFO  ranked_voting]       3 B -> eliminated:3 -> A,
[ INFO  ranked_voting] Round 4 (winning threshold: 4)
[ INFO  ranked_voting]       6 A -> elected

timrcv supports many options (input and output formats, validation of the candidates, configuration of the tabulating process, …). Look at the configuration section of the manual for more details.

Modules

This is the long-form manual for ranked_voting and timrcv.
Quick start with Google Forms

Structs

A ballot submitted by a voter.
A builder for adding votes.
Statistics for the elimination of the candidates.
Statistics for one round
The rules that control the voting process.
The result, in case of a successful election.

Enums

All the possible states corresponding to a choice in a ballot.
Strategy on how to deal with duplicated names.
The elimination algorithm to apply.
Controls how to deal with skipping blank or undervote pieces.
How to deal with overvotes.
The different modes to break a tie in case of multiple counts.
Errors that prevent the algorithm from completing successfully.
The sort of election to run. For now, only elections with a single winner are implemented.

Functions

Runs an election using the instant-runoff voting algorithm.
Runs an election (simple interface) using the instant-runoff voting algorithm.