Exemplo n.º 1
0
        public void Evolve()
        {
            int prevPoplLen;

            prevPoplLen = Genomes.Count();

            Genomes = GenerationGenerator.Generate(Genomes);
            if (!Genomes.Any())
            {
                Populate(prevPoplLen);
            }

            Generation++;
        }
Exemplo n.º 2
0
        public void SetFitness()
        {
            int ageDebt = (Age - LastImprovementAge + 1) - SpeciesParameters.DropOffAge;

            ageDebt = ageDebt == 0 ? 1 : ageDebt;

            Genomes.ForEach(g =>
            {
                if (ageDebt >= 1)
                {
                    g.Fitness *= SpeciesParameters.DropOffAgePenaltyFactor;
                }

                if (Age <= 10)
                {
                    g.Fitness *= SpeciesParameters.AgeSignificance;
                }

                if (g.Fitness < 0)
                {
                    g.Fitness = 0.0001;
                }

                g.Fitness /= Genomes.Count;
            });

            Fitness = Genomes.Any() ? Genomes.Average(g => g.Fitness) : 0;

            if (Fitness > MaxFitness)
            {
                MaxFitness         = Fitness;
                LastImprovementAge = 0;
            }
            else
            {
                LastImprovementAge++;
            }
        }