Esempio n. 1
0
        private List <Candidate> findTopCandidateLoop(List <List <Candidate> > candidateLoopList, CondorcetTally condorcetTally)
        {
            foreach (List <Candidate> subjectCandidateLoop in candidateLoopList)
            {
                Candidate subjectCandidate  = subjectCandidateLoop.First();
                bool      subjectLoopBeaten = false;

                foreach (List <Candidate> objectCandidateLoop in candidateLoopList)
                {
                    if (subjectCandidateLoop == objectCandidateLoop)
                    {
                        continue;
                    }

                    Candidate objectCandidate = subjectCandidateLoop.First();

                    if (condorcetTally.getVoteDifference(subjectCandidate, objectCandidate) < 0)
                    {
                        subjectLoopBeaten = true;
                        break;
                    }
                }

                if (!subjectLoopBeaten)
                {
                    return(subjectCandidateLoop);
                }
            }

            throw new Exception("Unable to find a top Condorcet loop");
        }
Esempio n. 2
0
        private List <Candidate> findCandidateLoop(Candidate currentCandidate, Candidate originalCandidate, List <Candidate> remainingCandidateList, List <Candidate> exploredCandidateList, CondorcetTally condorcetTally)
        {
            //System.Console.WriteLine("Finding loop from " + currentCandidate.ToString() + " to candidate " + originalCandidate.ToString());
            List <Candidate> currentEquivelantCandidateList = new List <Candidate>();

            currentEquivelantCandidateList.Add(currentCandidate);

            // Any candidated tied with the current candidate is functionally the same for any loop
            foreach (Candidate remainingCandidate in remainingCandidateList)
            {
                if (exploredCandidateList.Contains(remainingCandidate))
                {
                    continue;
                }

                if (condorcetTally.getVoteDifference(currentCandidate, remainingCandidate) == 0)
                {
                    //System.Console.WriteLine(remainingCandidate.ToString() + " is tied with our current one");
                    currentEquivelantCandidateList.Add(remainingCandidate);
                }
            }

            List <Candidate> defeatedCandidateList = new List <Candidate>();

            // Find all the non-explored, remaining candidates the passed canidate beats
            foreach (Candidate equivelantCandidate in currentEquivelantCandidateList)
            {
                foreach (Candidate remainingCandidate in remainingCandidateList)
                {
                    // If we have a candidate that has been explored or we have already beaten, continue
                    if (exploredCandidateList.Contains(remainingCandidate) || defeatedCandidateList.Contains(remainingCandidate))
                    {
                        continue;
                    }

                    if (condorcetTally.getVoteDifference(equivelantCandidate, remainingCandidate) > 0)
                    {
                        // See if we beat our original candidate.  If so, return our equivelant candidate list
                        return(currentEquivelantCandidateList);
                    }

                    defeatedCandidateList.Add(remainingCandidate);
                }
            }

            if (defeatedCandidateList.Count == 0)
            {
                return(null);
            }

            // We will look at all the found candidates, so consider them explored
            exploredCandidateList.AddRange(defeatedCandidateList);

            // Explore each candidate
            foreach (Candidate beatenCandidate in defeatedCandidateList)
            {
                List <Candidate> loopList = findCandidateLoop(beatenCandidate, originalCandidate, remainingCandidateList, exploredCandidateList, condorcetTally);

                if (loopList != null)
                {
                    loopList.AddRange(currentEquivelantCandidateList);
                    return(loopList);
                }
            }

            return(null);
        }