Ejemplo n.º 1
0
        public IEnumerable <Individual> CrossPopulation(List <Individual> population, double crossProbability)
        {
            var crossedPopulation = new List <Individual>();

            for (int i = 0; i < population.Count; i += 2)
            {
                if (_randomProvider.GetRandomProbability() < crossProbability)
                {
                    var crossedResult = population[i].Cross(population[i + 1]);
                    crossedPopulation.AddRange(new List <Individual> {
                        crossedResult.First, crossedResult.Second
                    });
                }
                else
                {
                    crossedPopulation.AddRange(new List <Individual> {
                        population[i], population[i + 1]
                    });
                }
            }

            return(crossedPopulation);
        }