Beispiel #1
0
        public void run()
        {
            Stopwatch calculationTime = new Stopwatch();

            if (continueExecution)
            {
                generation++;

                calculationTime.Start();
                population.runGeneration();
                calculationTime.Stop();

                updateInformation["GenerationNumber"]     = generation.ToString();
                updateInformation["MaxPopulationFitness"] = population.maxFitness.ToString();
                float[] vars = population.bestIndividual.DNA;
                for (int i = 0; i < Fitness.nInputVars; i++)
                {
                    updateInformation["Var" + (i + 1)] = vars[i].ToString();
                }
                float customFitness = population.bestIndividual.fitness;

                if (generation == 1)
                {
                    previousMaxFitness = population.maxFitness;
                }
                else
                {
                    if (previousMaxFitness == population.maxFitness)
                    {
                        nStalls++;
                    }
                    else
                    {
                        nStalls            = 0;
                        previousMaxFitness = population.maxFitness;
                    }
                }


                if (options.StopCriteria.Condition == StoppingCriteria.NUMBER_OF_GENERATIONS && generation >= options.StopCriteria.Value)
                {
                    continueExecution = false;
                }
                if (options.StopCriteria.Condition == StoppingCriteria.MINIMUM_FITNESS && population.maxFitness >= options.StopCriteria.Value)
                {
                    continueExecution = false;
                }
                if (options.StopCriteria.Condition == StoppingCriteria.NUMBER_OF_STALLS && nStalls >= options.StopCriteria.Value)
                {
                    continueExecution = false;
                }

                calculationTime.Restart();
                if (continueExecution)
                {
                    population.evolve();
                }
                else
                {
                    population.relaseGpuMemory();
                }
                calculationTime.Stop();
            }
        }