org.bolson.vote
Class Condorcet

java.lang.Object
  extended by org.bolson.vote.VotingSystem
      extended by org.bolson.vote.RatedVotingSystem
          extended by org.bolson.vote.Condorcet
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
CondorcetRTB, RankedPairs

public class Condorcet
extends RatedVotingSystem

Implements the Condorcet method of ranked voting tabulation and beatpath tie resolution. See electionmethods.org. Several variations are contained in this based on options submitted to init().

See Also:
CondorcetRTB, Serialized Form

Field Summary
protected  int[] talley
           
 
Fields inherited from class org.bolson.vote.VotingSystem
debug, NO_VOTE, numc
 
Constructor Summary
Condorcet(int numCandidates)
           
 
Method Summary
static void countDefeats(int numc, int[] tally, int[] defeatCount)
           
 java.lang.String getDebugText(java.lang.String[] names)
          Return textual representation of debug data.
 int[] getSchwartzSet()
          return the set of choices that are only beaten by each other.
 int[] getSchwartzSet(int[] defeatCount)
          return the set of choices that are only beaten by each other.
static int[] getSchwartzSet(int numc, int[] tally, int[] defeatCount)
           
static int[] getSchwartzSet(int numc, int[] tally, int[] defeatCount, java.lang.StringBuffer debugsb)
           
 int[] getWinners()
          Do processing if necessary, return winners.
 int[] getWinnersCSSD()
           
 int[] getWinnersOldBPM()
           
 int[] getWinnersSchwartzEqOne()
           
 int[] getWinnersSimpleIfOne()
           
 java.lang.String htmlSummary(java.lang.String[] names)
          A fancy html representation.
static java.lang.StringBuffer htmlTable(java.lang.StringBuffer sb, int numc, int[] arr, java.lang.String title, java.lang.String[] names)
           
 VotingSystem init(java.lang.String[] argv)
          Arguments to modify behavior of VotingSystem
 java.lang.String name()
          Return name of this voting system.
 java.lang.String toString()
           
 java.lang.String toString(java.lang.String[] names)
          A more interesting representation.
 boolean verifySchwartzSet(int[] ss)
          Verify set to have Schwartz Set properties.
static boolean verifySchwartzSet(int numc, int[] tally, int[] ss)
           
static boolean verifySchwartzSet(int numc, int[] tally, int[] ss, java.lang.StringBuffer debugsb)
           
 int voteRating(double[] rating)
           
 int voteRating(float[] rating)
           
 int voteRating(int[] rating)
           
 
Methods inherited from class org.bolson.vote.RatedVotingSystem
voteRanking
 
Methods inherited from class org.bolson.vote.VotingSystem
checkRatedVote, getDebugHTML, getNumberOfCandidates, getWinners, 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

talley

protected int[] talley
Constructor Detail

Condorcet

public Condorcet(int numCandidates)
Method Detail

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

init

public VotingSystem init(java.lang.String[] argv)
Description copied from class: VotingSystem
Arguments to modify behavior of VotingSystem

Overrides:
init in class VotingSystem
Parameters:
argv - -minpref|-avgpref|-margins|-wv|-both -minpref "no vote" indicates minimal preference -avgpref "no vote" assigned average preference not otherwise assigned -margins tie breakers consider marginal votes (A_Over_B - B_Over_A) -wv tie breakers consider winning votes (A_Over_B) -both add to both on tie (otherwise add to neither on tie). can change outcome with -wv "winning votes".
Returns:
this

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

voteRating

public int voteRating(int[] rating)
Overrides:
voteRating in class RatedVotingSystem
Parameters:
rating - An array int[numc]. rating[i] is the rating of choice i. A rating can be any int value. Higher means more preferred. NO_VOTE for unrated.
Returns:
0 on success

voteRating

public int voteRating(float[] rating)
Specified by:
voteRating in class VotingSystem
Parameters:
rating - An array int[N]. rating[i] is the rating of choice i. A rating can be any int value. Higher means more preferred. NO_VOTE for unrated.
Returns:
0 on success

voteRating

public int voteRating(double[] rating)
Overrides:
voteRating in class RatedVotingSystem
Parameters:
rating - An array int[N]. rating[i] is the rating of choice i. A rating can be any int value. Higher means more preferred. NO_VOTE for unrated.
Returns:
0 on success

getSchwartzSet

public int[] getSchwartzSet()
return the set of choices that are only beaten by each other.

Returns:
the "Schwartz Set"

getSchwartzSet

public int[] getSchwartzSet(int[] defeatCount)
return the set of choices that are only beaten by each other.

Parameters:
defeatCount - must be int[numc] by the reference property of java arrays, the defeatCount will be returned in this property.
Returns:
the "Schwartz Set"

countDefeats

public static void countDefeats(int numc,
                                int[] tally,
                                int[] defeatCount)

getSchwartzSet

public static int[] getSchwartzSet(int numc,
                                   int[] tally,
                                   int[] defeatCount)

getSchwartzSet

public static int[] getSchwartzSet(int numc,
                                   int[] tally,
                                   int[] defeatCount,
                                   java.lang.StringBuffer debugsb)

verifySchwartzSet

public boolean verifySchwartzSet(int[] ss)
Verify set to have Schwartz Set properties.
  1. every member of the set beats every choice not in the set
  2. no member of the set is beaten by every other member of the set

Parameters:
ss - a candidate Schwartz Set
Returns:
true if ss is a Schwartz Set

verifySchwartzSet

public static boolean verifySchwartzSet(int numc,
                                        int[] tally,
                                        int[] ss)

verifySchwartzSet

public static boolean verifySchwartzSet(int numc,
                                        int[] tally,
                                        int[] ss,
                                        java.lang.StringBuffer debugsb)

getWinnersSchwartzEqOne

public int[] getWinnersSchwartzEqOne()

getWinnersSimpleIfOne

public int[] getWinnersSimpleIfOne()

getWinnersOldBPM

public int[] getWinnersOldBPM()

getWinnersCSSD

public int[] getWinnersCSSD()

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)

toString

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

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!

htmlTable

public static java.lang.StringBuffer htmlTable(java.lang.StringBuffer sb,
                                               int numc,
                                               int[] arr,
                                               java.lang.String title,
                                               java.lang.String[] names)

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!