コード例 #1
0
        public void EvaluatePopulation()
        {
            List <Chromosome> chromosomes = CurrentGeneration.FindAll(x => x.FitnessOutdated);

            if (chromosomes.Count == 0)
            {
                return;
            }

            int evaluations = (int)((double)chromosomes.Count * EvaluationRate);
            List <Chromosome> orderedChromosomes = chromosomes.OrderByDescending(x => x.Priority).ToList();

            for (int i = 0; i < orderedChromosomes.Count; i++)
            {
                Chromosome c = orderedChromosomes[i];

                if (i < evaluations) //Chosen for evaluation
                {
                    c.Fitness         = FitnessFunction.Evaluate(c);
                    c.Priority        = 0;
                    c.FitnessOutdated = false;
                    totalEvaluations++;
                }
                else
                {
                    c.Priority += NonEvaluationWeigth;
                }
                //If the maximum number is reached while evaluating the population, the process is interrupted.
                if (totalEvaluations == MaxEvaluations)
                {
                    break;
                }
            }

            if (EvaluationRate < 1)
            {
                EvaluationRate = EvaluationRate + (1 - EvaluationRate) * 0.001;
            }
            if (EvaluationRate > 1)
            {
                EvaluationRate = 1;
            }
        }