Пример #1
0
    void EvolStep()
    {
        //do for a given number of generations
        if (currentGeneration < numGenerations)
        {
            //if there are individuals to evaluate on the current generation
            int evalsThisStep = EvaluationsPerStep < (populationSize - evaluatedIndividuals) ? EvaluationsPerStep : (populationSize - evaluatedIndividuals);
            for (int ind = evaluatedIndividuals; ind < evaluatedIndividuals + evalsThisStep; ind++)
            {
                population[ind].evaluate();
            }
            evaluatedIndividuals += evalsThisStep;

            //if all individuals have been evaluated on the current generation, breed a new population
            if (evaluatedIndividuals == populationSize)
            {
                stats.PostGenLog(population, currentGeneration);

                population           = BreedPopulation();
                evaluatedIndividuals = 0;
                currentGeneration++;
            }
        }
        else
        {
            stats.finalLog();
            evolving = false;
            drawing  = true;
            print("evolution stopped");
        }
    }