|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.bolson.vote.VotingSystem
public abstract class VotingSystem
Top level abstract class for ranked or rated voting systems. Most implementations will subclass either RankedVotingSystem or RatedVotingSystem.
RankedVotingSystem,
RatedVotingSystem,
Serialized Form| Field Summary | |
|---|---|
boolean |
debug
Debug info collecting flag. |
static int |
NO_VOTE
This value represents that the voter made no action on some choice. |
protected int |
numc
number of candidates |
| Constructor Summary | |
|---|---|
VotingSystem(int numCandidates)
In addition to interfaced methods, there shall be a constructor taking the integer number N of choices to be voted on. |
|
| Method Summary | |
|---|---|
boolean |
checkRatedVote(int[] rating,
int min,
int max)
squash (sum of absolute value of vote) to (max - min) |
java.lang.String |
getDebugHTML(java.lang.String[] names)
Return HTML representation of debug data. |
java.lang.String |
getDebugText(java.lang.String[] names)
Return textual representation of debug data. |
int |
getNumberOfCandidates()
accessor to read only variable |
abstract int[] |
getWinners()
Do processing if necessary, return winners. |
int[] |
getWinners(int numSeats)
Do processing if necessary, return winners. |
int[] |
getWinners(java.io.PrintWriter out)
Deprecated. use getWinners(), debug, and getDebugText() or getDebugHTML() |
int[] |
getWinners(java.io.PrintWriter out,
int numSeats)
Deprecated. use getWinners(int), debug, and getDebugText() or getDebugHTML() |
abstract java.lang.String |
htmlSummary(java.lang.String[] names)
A fancy html representation. |
VotingSystem |
init(java.lang.String[] argv)
Arguments to modify behavior of VotingSystem |
boolean |
isValidRankedVote(int[] ranking)
Checks that ranking is valid. |
boolean |
isValidRatedVote(int[] rating,
int min,
int max)
Checks that rating is valid. |
java.lang.String |
name()
Return name of this voting system. |
static void |
normalize(double[] ratings)
Divide values by their average |
static void |
normalize(double[] dest,
double[] src)
Divide values by their average |
static void |
normalize(double[] dest,
int[] src)
Divide values by their average |
static void |
normalize(float[] ratings)
Divide values by their average |
static void |
normalize(float[] dest,
float[] src)
|
static void |
normalizeL2(double[] ratings)
Calculate "L2" norm. |
static void |
normalizeL2(double[] dest,
double[] src)
Calculate "L2" norm. |
static void |
normalizeL2(double[] dest,
int[] src)
Calculate "L2" norm. |
static void |
normalizeL2(float[] ratings)
Calculate "L2" norm. |
static void |
normalizeL2(float[] dest,
float[] src)
Calculate "L2" norm. |
static void |
stretch(double[] vote,
float tmin,
float tmax)
Maximize a vote between bounds. |
abstract java.lang.String |
toString(java.lang.String[] names)
A more interesting representation. |
abstract int |
voteRanking(int[] ranking)
|
abstract int |
voteRating(double[] rating)
|
abstract int |
voteRating(float[] rating)
|
abstract int |
voteRating(int[] rating)
|
int |
voteRating(java.lang.Object rating)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected int numc
public boolean debug
getDebugText(String[]),
getDebugHTML(String[])public static final int NO_VOTE
| Constructor Detail |
|---|
public VotingSystem(int numCandidates)
| Method Detail |
|---|
public java.lang.String getDebugText(java.lang.String[] names)
names - Symbolic names for the choices makes human debugging easier. May be null.
debugpublic java.lang.String getDebugHTML(java.lang.String[] names)
names - Symbolic names for the choices makes human debugging easier. May be null.
debugpublic VotingSystem init(java.lang.String[] argv)
vs = (new VS(numc)).init( new String[]{"blah", "grunt"} );public int getNumberOfCandidates()
public abstract int voteRating(int[] rating)
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.
public abstract int voteRating(float[] rating)
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.
public abstract int voteRating(double[] rating)
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.
public int voteRating(java.lang.Object rating)
throws java.lang.ClassCastException
rating - An array of int, float or double
java.lang.ClassCastExceptionvoteRating(int[]),
voteRating(float[]),
voteRating(double[])public abstract int voteRanking(int[] ranking)
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.
public boolean checkRatedVote(int[] rating,
int min,
int max)
rating - vote to checkmin - minimum (inclusive) value allowed for ratingmax - maximum (inclusive) value allowed for rating
public static void normalize(double[] ratings)
ratings - take average, then devide each element by the average
public static void normalize(double[] dest,
double[] src)
src - values to normalizedest - receives normalized version of srcpublic static void normalize(float[] ratings)
ratings - take average, then devide each element by the average
public static void normalize(float[] dest,
float[] src)
public static void normalize(double[] dest,
int[] src)
src - values to normalizedest - receives normalized version of srcpublic static void normalizeL2(double[] ratings)
ratings - take sqrt of the sum of squares, then devide each element by the that
public static void normalizeL2(double[] dest,
double[] src)
src - values to normalizedest - receives normalized version of srcpublic static void normalizeL2(float[] ratings)
ratings - take sqrt of the sum of squares, then devide each element by the that
public static void normalizeL2(float[] dest,
float[] src)
src - values to normalizedest - receives normalized version of src
public static void normalizeL2(double[] dest,
int[] src)
src - values to normalizedest - receives normalized version of src
public boolean isValidRatedVote(int[] rating,
int min,
int max)
rating - vote to checkmin - minimum (inclusive) value allowed for ratingmax - maximum (inclusive) value allowed for rating
public boolean isValidRankedVote(int[] ranking)
ranking - vote to check
public static void stretch(double[] vote,
float tmin,
float tmax)
vote - ratingstmin - target minimum valuetmax - target maximum valuepublic abstract int[] getWinners()
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.
public int[] getWinners(java.io.PrintWriter out)
out - where to print
getWinners(),
debug,
getDebugText(String[]),
getDebugHTML(String[])
public int[] getWinners(java.io.PrintWriter out,
int numSeats)
out - where to print news and diagnosticsnumSeats - the number of seats available.
getWinners(int),
debug,
getDebugText(String[]),
getDebugHTML(String[])public int[] getWinners(int numSeats)
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.
numSeats - the number of seats available.
public abstract java.lang.String toString(java.lang.String[] names)
names - The names of the choices.
public abstract java.lang.String htmlSummary(java.lang.String[] names)
names - The names of the choices. May be null.
public java.lang.String name()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||