Subversion Repositories Remote Hare Voting

Rev

Rev 64 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 64 Rev 71
Line 1... Line 1...
1
## Compute Hare Ballot
1
# Compute Hare Ballot
2
##
2
#
3
## Tim Korb (jtk@cs.purdue.edu), May 2007
3
# Tim Korb (jtk@cs.purdue.edu), May 2007
4
##
4
#
5
## A few definitions and notes...
5
# A few definitions and notes...
6
##
6
#
7
## tally: dictionary in which the keys are candidate names and the
7
# tally: dictionary in which the keys are candidate names and the
8
## values are lists of ballots currently assigned to that candidate
8
# values are lists of ballots currently assigned to that candidate
9
##
9
#
10
## ballot: list of candidates in the order determined by the voter
10
# ballot: list of candidates in the order determined by the voter
11
##
11
#
12
## winners: list of candidates that have reached the quota of ballots
12
# winners: list of candidates that have reached the quota of ballots
13
## or have remained in the running long enough to be declared a winner
13
# or have remained in the running long enough to be declared a winner
14
##
14
#
15
## losers: list of candidates that have been eliminated from the running
15
# losers: list of candidates that have been eliminated from the running
16
##
16
#
17
## Note that plurals are generally used to indicate lists of other
17
# Note that plurals are generally used to indicate lists of other
18
## items, e.g., ballots is a list of ballot items.
18
# items, e.g., ballots is a list of ballot items.
19
##
19
#
20
## To download the complete source distribution, use Subversion:
20
# To download the complete source distribution, use Subversion:
21
##
21
#
22
##      % svn co http://www.bikmort.com/hare
22
#      % svn co http://www.bikmort.com/hare
23
##
23
#
24
## $Id: tally.py 64 2007-10-15 15:48:23Z jtkorb $
24
# $Id: tally.py 71 2009-01-08 16:33:44Z jtkorb $
25
 
25
 
26
import sys
26
import sys
27
import math 
27
import math 
28
import copy
28
import copy
29
import random
29
import random
Line 135... Line 135...
135
                cWin = len(u.tally[c])
135
                cWin = len(u.tally[c])
136
    if len(lWin) > 0:
136
    if len(lWin) > 0:
137
        return u.forkPendingWinners(lWin)
137
        return u.forkPendingWinners(lWin)
138
 
138
 
139
    # Check to see if only enough candidates remain
139
    # Check to see if only enough candidates remain
140
    ## TODO: sort by len(tally[c]) to choose larger winners first
140
    # TODO: sort by len(tally[c]) to choose larger winners first
141
    ## create multiple universes if some have equal votes
141
    # create multiple universes if some have equal votes
142
    n = 0
142
    n = 0
143
    last = ""
143
    last = ""
144
    for c in u.tally.keys():
144
    for c in u.tally.keys():
145
        if c not in u.winners and c not in u.losers:
145
        if c not in u.winners and c not in u.losers:
146
            last = c
146
            last = c