public override VotingSystemResult getResult(Roster roster, List <Ballot> ballotList) { Dictionary <Candidate, int> voteCountDictionary = new Dictionary <Candidate, int>(); foreach (Candidate candidate in roster.candidateList) { voteCountDictionary[candidate] = 0; } foreach (Ballot ballot in ballotList) { Candidate candidate = null; if (ballot.ballotInstructions.ballotType == BallotType.Score && ballot.candidateScoreList.Count > 0) { candidate = ballot.candidateScoreList.OrderByDescending(s => s.score).First().candidate; } else if (ballot.ballotInstructions.ballotType == BallotType.Rank && ballot.preferredCandidateList.Count > 0) { candidate = ballot.preferredCandidateList.First(); } voteCountDictionary[candidate]++; if (Tweakables.PRINT_FPTP) { System.Console.WriteLine(ballot.voter.ToString() + ": " + candidate.ToString()); } } // Create the results VotingSystemResult result = new VotingSystemResult(this); foreach (Candidate candidate in roster.candidateList) { result.addCandidate(candidate, voteCountDictionary[candidate]); } if (Tweakables.PRINT_RESULTS) { System.Console.WriteLine(result.ToString()); } return(result); }
public override VotingSystemResult getResult(Roster roster, List <Ballot> ballotList) { CondorcetTally condorcetTally = new CondorcetTally(roster, ballotList); if (Tweakables.PRINT_CONDORCET) { System.Console.WriteLine(condorcetTally.ToString()); } List <List <Candidate> > candidateLoopList = findCandidateLoops(roster.candidateList, condorcetTally); candidateLoopList = getOrderedCandidateLoopList(candidateLoopList, condorcetTally); VotingSystemResult result = new VotingSystemResult(this); foreach (List <Candidate> candidateLoop in candidateLoopList) { int score = 0; foreach (Candidate candidate in candidateLoop) { score += condorcetTally.getScore(candidate); } score = score / candidateLoop.Count; foreach (Candidate candidate in candidateLoop) { result.addCandidate(candidate, score); } } if (Tweakables.PRINT_RESULTS) { System.Console.WriteLine(result.ToString()); } return(result); }