elections module

Below is a simple Python script that will read in a .blt file, compute various bound, and then print the results. Note that computing the Condorcet winner and lower bound requires the numpy package and computing the IRV margin exactly requires the CPLEX library and Python wrapper.

The documentation for the elections module can be found here.

#!/usr/bin/env python

import sys

from elections import blt, irv, condorcet

if len(sys.argv) != 2:
    print 'Usage: %s election.blt' % sys.argv[0]
    sys.exit(1)

election = blt.read_blt(sys.argv[1])
winner, _, elim_order = irv.irv(election)
slb = irv.irv_simple_lb(election, rules=irv.COMPLETE_IRV_RULES)
lb = irv.irv_lb(election)
ub = irv.irv_ub(election, winner=winner, elim_order=elim_order)
margin = irv.irv_margin(election, winner=winner, elim_order=elim_order, ub=ub)
m = condorcet.build_condorcet(election)
cwinner = condorcet.condorcet_winner(m)
clb = condorcet.condorcet_lb(m, winner=cwinner)

print 'IRV: %d; %d <= %d <= %d <= %d' % (winner, slb, lb, margin, ub)
print 'Condorcet: %d; %d' % (cwinner, clb)

# vim: set sw=4 sts=4 tw=0 expandtab: