private Ballot createScoreBallot(List <CandidateRating> candidateRatingList, BallotInstructions ballotInstructions) { Ballot ballot = new Ballot(ballotInstructions); int i = 0; foreach (CandidateRating candidateRating in candidateRatingList.OrderBy(r => r.rating)) { // End the loop if we have already entered the maximum number allowed to list if (i >= ballotInstructions.maximumCandidatesToScore) { break; } // A round nearest in a 0-10 scale would round 0 to .05 down to 0 and .05 to .15 to 1 // This means twice the range rounds to 1 as rounds to 0 // What we want is 0 to .0909 rounds to 0 and .0909 to .1818 rounds to 1 int score = Convert.ToInt32(candidateRating.rating * (ballotInstructions.maximumScore + 1) - .5); if (score < 0) { score = 0; } if (score > ballotInstructions.maximumScore) { score = ballotInstructions.maximumScore; } ballot.candidateScoreList.Add(new CandidateScore(candidateRating.candidate, score)); i++; } return(ballot); }
private Ballot createRankBallot(List <CandidateRating> candidateRatingList, BallotInstructions ballotInstructions) { Ballot ballot = new Ballot(ballotInstructions); int i = 0; foreach (CandidateRating candidateRating in candidateRatingList.OrderBy(r => r.rating)) { // End the loop if we have already entered the maximum number allowed to list if (i >= ballotInstructions.maximumPreferredCandidates) { break; } ballot.preferredCandidateList.Add(candidateRating.candidate); i++; } i = 0; foreach (CandidateRating candidateRating in candidateRatingList.OrderByDescending(r => r.rating)) { // End the loop if we have already listed this candidate as preferred // Or we are not allowed to list any more if (ballot.preferredCandidateList.Contains(candidateRating.candidate) || (i >= ballotInstructions.maximumDispreferredCandidates)) { break; } ballot.dispreferredCandidateList.Add(candidateRating.candidate); i++; } return(ballot); }
public Ballot createBallot(BallotInstructions instructions) { Ballot ballot = viewpoint.createBallot(instructions); ballot.voter = this; if (Tweakables.PRINT_BALLOTS) { System.Console.WriteLine(ToString() + " " + ballot.ToString()); } return(ballot); }
public override Ballot createBallot(BallotInstructions ballotInstructions) { if (ballotInstructions.ballotType == BallotType.Rank) { return(createRankBallot(candidateRatingList, ballotInstructions)); } if (ballotInstructions.ballotType == BallotType.Score) { return(createScoreBallot(candidateRatingList, ballotInstructions)); } throw new Exception("Encountered unhandled ballot type"); }
private List <VotingSystem> getVotingSystemList() { BallotInstructions condorcetBallot = new BallotInstructions(BallotType.Rank); condorcetBallot.setRankInstructions(Tweakables.CANDIDATE_COUNT, 0); BallotInstructions score2Ballot = new BallotInstructions(BallotType.Score); score2Ballot.setScoreInstructions(2, Tweakables.CANDIDATE_COUNT); BallotInstructions score4Ballot = new BallotInstructions(BallotType.Score); score4Ballot.setScoreInstructions(4, Tweakables.CANDIDATE_COUNT); BallotInstructions score6Ballot = new BallotInstructions(BallotType.Score); score6Ballot.setScoreInstructions(6, Tweakables.CANDIDATE_COUNT); BallotInstructions score10Ballot = new BallotInstructions(BallotType.Score); score10Ballot.setScoreInstructions(10, Tweakables.CANDIDATE_COUNT); BallotInstructions score100Ballot = new BallotInstructions(BallotType.Score); score100Ballot.setScoreInstructions(100, Tweakables.CANDIDATE_COUNT); List <VotingSystem> votingSystemList = new List <VotingSystem>(); votingSystemList.Add(new Condorcet(condorcetBallot)); votingSystemList.Add(new FPTP(condorcetBallot)); //votingSystemList.Add(new Score(score2Ballot)); //votingSystemList.Add(new Score(score4Ballot)); //votingSystemList.Add(new Score(score6Ballot)); //votingSystemList.Add(new Score(score10Ballot)); //votingSystemList.Add(new Score(score100Ballot)); return(votingSystemList); }
public Approval(BallotInstructions ballotInstructions) : base("Approval", ballotInstructions) { }
public abstract Ballot createBallot(BallotInstructions ballotInstructions);
public VotingSystem(String name, BallotInstructions ballotInstructions) { this.name = name; this.ballotInstructions = ballotInstructions; }
public Borda(BallotInstructions ballotInstructions) : base("Borda", ballotInstructions) { }
public Condorcet(BallotInstructions ballotInstructions) : base("Condorcet", ballotInstructions) { }
public Score(BallotInstructions ballotInstructions) : base("Score 0-" + ballotInstructions.maximumScore, ballotInstructions) { }
public FPTP(BallotInstructions ballotInstructions) : base("FPTP", ballotInstructions) { }