public void NextGeneration(ISelection selectionScheme) { var selected = selectionScheme.Select(Chromosomes, 5).OrderByDescending(s => s.Cost).ToList(); Chromosomes.Remove(selected[0]); Chromosomes.Remove(selected[1]); // fill the remaining empty space with children generated from selected chromosomes Chromosome parent1 = selected[3]; Chromosome parent2 = selected[4]; Chromosome child1 = OrderedCrossover.MakeChild(parent1, parent2); Chromosome child2 = OrderedCrossover.MakeChild(parent2, parent1); if (ThreadSafeRandom.CurrentThreadRandom.Next(100) < 3) { child1.Mutate(); } if (ThreadSafeRandom.CurrentThreadRandom.Next(100) < 3) { child2.Mutate(); } Chromosomes.Add(child1); Chromosomes.Add(child2); double currentTour = Chromosomes.Where(c => c.Cost > 0).Min(c => c.Cost); if (currentTour < BestTour) { BestTour = currentTour; Console.WriteLine("Generation " + currentGeneration + " Best: " + BestTour); } currentGeneration++; }
public void RemoveChromosome(T chromosome) { Chromosomes.Remove(chromosome); }
public void RemoveChromosome(Chromosome <T> chromosome) { Contract.Requires <ArgumentNullException>(chromosome != null, "Chromosome cannot be null."); Chromosomes.Remove(chromosome); }