public void GenerateNewGeneration() { nextGeneration = new Population(_populationSize, _citiesAmount, _xRange, _yRange, isEmpty: true); parentsList = p.SelectParents(_selectionOp); Int32 count = parentsList.Count(); while (nextGeneration.Chromosomes.Count != count) { if (RandomExtension.Instance.NextDouble() < _pCrossover) { ChromosomePair parents = new ChromosomePair { Individual1 = parentsList[RandomExtension.Instance.Next(count)], Individual2 = parentsList[RandomExtension.Instance.Next(count)] }; ChromosomePair parentsCrossed = parents.CrossOver(); parentsCrossed.MutatePair(_pMutate); ChromosomePair offspring = new ChromosomePair { //Individual1 = parents.Individual1.RouteLength < parents.Individual2.RouteLength ? parents.Individual1 : parents.Individual2, //Individual2 = parentsCrossed.Individual1.RouteLength < parentsCrossed.Individual2.RouteLength ? parentsCrossed.Individual1 : parentsCrossed.Individual2 Individual1 = parentsCrossed.Individual1, Individual2 = RandomExtension.Instance.NextDouble() < 0.1 ? new Chromosome(parentsCrossed.Individual2) : parentsCrossed.Individual2 }; nextGeneration.AddToNextGeneration(offspring); } } p = nextGeneration; }