public void Mutate() { int randNumCitiesToFlip = EvolutionHelper.rand(100); for (int i = 0; i < randNumCitiesToFlip; i++) { int randIndex = EvolutionHelper.rand(100); _genome[randIndex] = EvolutionHelper.randDouble(100); } }
void Shuffle() { int n = solutionList.Count(); while (n > 1) { n--; int k = EvolutionHelper.rand(n + 1); Solution value = solutionList[k]; solutionList[k] = solutionList[n]; solutionList[n] = value; } }
private void Mate(int start) { int cross1 = EvolutionHelper.rand(100); int cross2 = cross1; while (cross1 == cross2) { cross1 = EvolutionHelper.rand(100); } if (cross1 > cross2) { SwapInt(ref cross1, ref cross2); } Solution parent1 = solutionList[start]; Solution parent2 = solutionList[start + 1]; List <double> child1Tour = new List <double>(); List <double> child2Tour = new List <double>(); for (int i = 0; i < 100; i++) { if ((i < cross1) || (i > cross2)) // two point crossover //if (EvolutionHelper.randDouble(1) < .6) // uniform crossover { child1Tour.Add(parent1.Genome[i]); child2Tour.Add(parent2.Genome[i]); } else { child1Tour.Add(parent2.Genome[i]); child2Tour.Add(parent1.Genome[i]); } } solutionList[start + 2].Genome = child1Tour; solutionList[start + 3].Genome = child2Tour; _problem.EvaluateSolution(solutionList[start + 2]); _problem.EvaluateSolution(solutionList[start + 3]); }