Esempio n. 1
0
        public void Evolve()
        {
            Stopwatch.Start();

            CreateFirstGeneration();

            while (Generation < NoOfGenerations)
            {
                foreach (var chromosome in Population)
                {
                    if (FittestChromosome == null || chromosome.CompareTo(FittestChromosome) < 0)
                    {
                        FittestChromosome = chromosome;
                    }
                }

                Select();

                Crossover();

                Mutate();

                Generation++;

                GenerationEvolved?.Invoke(this, EventArgs.Empty);
            }

            Stopwatch.Stop();
        }
Esempio n. 2
0
        // main method
        public EvolutionResult <T> Evolve()
        {
            SwitchGenerations();

            // perform evolution
            var naturalSelected = Select(CurrentGeneration);
            var newIndividuals  = Reproduce(naturalSelected);
            var nextPopulation  = Mutate(newIndividuals);

            // prepare next generation
            NextGeneration = new Generation <T>(CurrentGeneration.Number + 1, nextPopulation);

            // result of current generation
            var result = new EvolutionResult <T>(CurrentGeneration);

            GenerationEvolved?.Invoke(result);

            return(result);
        }