Ejemplo n.º 1
0
        public void DetermineCandidateRank(List<Candidate> candidatesByNow, Candidate newCandidate, Random rand)
        {
            int newCandidateIndex = InsertNewCandidate(candidatesByNow, newCandidate);

            var accepted = Decide(candidatesByNow, newCandidateIndex, rand);

            newCandidate.CandidateAccepted = accepted;
        }
Ejemplo n.º 2
0
        private int InsertNewCandidate(List<Candidate> candidatesByNow, Candidate newCandidate)
        {
            int newCandidateIndex = 0;
            foreach (var candidate in candidatesByNow)
            {
                if (candidate.CandidateRank > newCandidate.CandidateRank)
                {
                    break;
                }

                newCandidateIndex++;
            }

            candidatesByNow.Insert(newCandidateIndex, newCandidate);
            return newCandidateIndex;
        }
Ejemplo n.º 3
0
        public static List<Candidate> GenerateCandidatesForPosition()
        {
            var positionCandidates = new List<Candidate>();

            for (var candidateIndex = 0; candidateIndex < RestaurantConstants.TotalCandidates; candidateIndex++)
            {
                var newCandidate = new Candidate()
                {
                    CandidateAccepted = false
                };

                positionCandidates.Add(newCandidate);
            }

            return positionCandidates;
        }
        public static int[] ReadNextVector(StreamReader sr, out bool terminate, ref int vectorNum, Random rand)
        {
            terminate = false;

            var positionNumber = 0;

            int[] accepted = new int[RestaurantConstants.TotalPositions];
            int[] intRanks = new int[RestaurantConstants.TotalCandidates];
            string line = sr.ReadLine();

            if (line == null)
            {
                terminate = true;
                return accepted;
            }

            while (line != null)
            {
                if (line.StartsWith("--") || line == string.Empty)
                {
                    if (line.StartsWith("--"))
                    {
                        vectorNum++;
                    }
                    else
                    {
                        break;
                    }

                    line = sr.ReadLine();
                    positionNumber = 0;
                    continue;
                }

                string[] ranks = line.Split(' ');

                int i = 0;
                bool skipLine = false;
                foreach (string rank in ranks)
                {
                    int intRank;
                    if (rank == string.Empty)
                    {
                        continue;
                    }

                    if (!int.TryParse(rank, out intRank))
                    {
                        line = sr.ReadLine();
                        skipLine = true;
                        break;
                    }

                    intRanks[i] = intRank;
                    i++;
                }

                if (skipLine)
                {
                    continue;
                }

                var candidatesByNow = new List<Candidate>();
                int chosenRank = 0;
                for (i = 0; i < intRanks.Length; i++)
                {
                    var newCandidate = new Candidate() { CandidateRank = intRanks[i] };
                    DecisionMaker.GetInstance().DetermineCandidateRank(candidatesByNow, newCandidate, rand);

                    if (newCandidate.CandidateAccepted)
                    {
                        chosenRank = intRanks[i];
                        accepted[positionNumber] = chosenRank;
                        break;
                    }
                }

                positionNumber++;

                line = sr.ReadLine();
            }

            return accepted;
        }