Exemplo n.º 1
0
        public void Crossover()
        {
            var elitism = GetFittestIndividuals(Individuals, Elitism);

            double crossoverRate = 0.5;

            int newPopulationCount = 0;

            while (newPopulationCount < PopulationCount)
            {
                var parentA = GetRandomGenom();
                var parentB = GetRandomGenom();

                if (_random.NextDouble() > crossoverRate)
                {
                    Individuals.AddRange(OnePointCrossover(parentA, parentB));
                }
                else
                {
                    Individuals.AddRange(TwoPointCrossover(parentA, parentB));
                }

                newPopulationCount += 2;
            }

            CalculateFitness();
            AddEliteFromPreviousGeneration(elitism);
            //CalculateFitness();
        }