org.bolson.vote
Class IRV

java.lang.Object
  extended by org.bolson.vote.VotingSystem
      extended by org.bolson.vote.RankedVotingSystem
          extended by org.bolson.vote.IRV
All Implemented Interfaces:
java.io.Serializable

public class IRV
extends RankedVotingSystem

Implements the Instant Runoff Voting, also known as Single Transferrable Vote. There's wide debate about the flaws and virtues of this system.

See Also:
Condorcet, IRNR, Serialized Form

Field Summary
protected  java.util.Vector votes
           
protected  java.util.Vector[] winnerBuckets
           
 
Fields inherited from class org.bolson.vote.VotingSystem
debug, NO_VOTE, numc
 
Constructor Summary
IRV(int numCandidates)
           
 
Method Summary
 java.lang.String getDebugText(java.lang.String[] names)
          Return textual representation of debug data.
 int[] getWinners()
          Do processing if necessary, return winners.
 int[] getWinners(java.io.PrintWriter out, int numSeats)
          Multi-seat IRV, aka STV.
 java.lang.String htmlSummary(java.lang.String[] names)
          A fancy html representation.
 VotingSystem init(java.lang.String[] argv)
          Set what happens when a vote has a duplicate rating (among active choices) -split|-dup|-dq
protected  void intoBucket(int[] ranking)
           
protected  void myInit()
           
 java.lang.String name()
          Return name of this voting system.
 void resetBuckets()
           
 java.lang.String toString()
           
 java.lang.String toString(java.lang.String[] names)
          A more interesting representation.
 int voteRanking(int[] ranking)
           
 
Methods inherited from class org.bolson.vote.RankedVotingSystem
voteRating, voteRating, voteRating
 
Methods inherited from class org.bolson.vote.VotingSystem
checkRatedVote, getDebugHTML, getNumberOfCandidates, getWinners, getWinners, isValidRankedVote, isValidRatedVote, normalize, normalize, normalize, normalize, normalize, normalizeL2, normalizeL2, normalizeL2, normalizeL2, normalizeL2, stretch, voteRating
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

votes

protected java.util.Vector votes

winnerBuckets

protected java.util.Vector[] winnerBuckets
Constructor Detail

IRV

public IRV(int numCandidates)
Method Detail

myInit

protected void myInit()

name

public java.lang.String name()
Description copied from class: VotingSystem
Return name of this voting system. This is a function so that it can potentially construct a detailed name based on options set in init().

Overrides:
name in class VotingSystem
Returns:
a descriptive name

intoBucket

protected void intoBucket(int[] ranking)

voteRanking

public int voteRanking(int[] ranking)
Specified by:
voteRanking in class VotingSystem
Parameters:
ranking - An array int[N]. ranking[i] is the ranking of choice i. rankings are 1 (most preferred) through N (least). INT_MAX, N, or NO_VOTE for unspecified.
Returns:
0 on success

resetBuckets

public void resetBuckets()

getWinners

public int[] getWinners()
Description copied from class: VotingSystem
Do processing if necessary, return winners.

It is recommended to cache the return value in such a way that calling this function again does not do complex recalculation. That cache should be cleared if voteRating or voteRanking is called.

Specified by:
getWinners in class VotingSystem
Returns:
indecies of winners (hopefully 1 of them)

getDebugText

public java.lang.String getDebugText(java.lang.String[] names)
Description copied from class: VotingSystem
Return textual representation of debug data. Default implementation returns null.

Overrides:
getDebugText in class VotingSystem
Parameters:
names - Symbolic names for the choices makes human debugging easier. May be null.
Returns:
debug text (default=null)
See Also:
VotingSystem.debug

getWinners

public int[] getWinners(java.io.PrintWriter out,
                        int numSeats)
Multi-seat IRV, aka STV. In this case, "-split" refers to the overvote. With -split, votes for a winner maintain a fraction of their voting power proportional to the number of votes beyond the droop quota. By default a random set of ballots beyond the droop quota are transferred in whole to their remaining choices.

Overrides:
getWinners in class VotingSystem
Parameters:
out - where to print news and diagnostics
numSeats - the number of seats available.
Returns:
indecies of winners, hopefully numSeats of them but in case of ties there may be more and in case of some internal schism there may be fewer. Check .length to be sure.
See Also:
VotingSystem.getWinners(int), VotingSystem.debug, VotingSystem.getDebugText(String[]), VotingSystem.getDebugHTML(String[])

htmlSummary

public java.lang.String htmlSummary(java.lang.String[] names)
Description copied from class: VotingSystem
A fancy html representation. Include the names of the choices voted upon in the representation.

Specified by:
htmlSummary in class VotingSystem
Parameters:
names - The names of the choices. May be null.
Returns:
state, with names!

toString

public java.lang.String toString(java.lang.String[] names)
Description copied from class: VotingSystem
A more interesting representation. Include the names of the choices voted upon in the representation.

Specified by:
toString in class VotingSystem
Parameters:
names - The names of the choices.
Returns:
state, with names!

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

init

public VotingSystem init(java.lang.String[] argv)
Set what happens when a vote has a duplicate rating (among active choices) -split|-dup|-dq

Overrides:
init in class VotingSystem
Returns:
this so that you can do
vs = (new VS(numc)).init( new String[]{"blah", "grunt"} );