public void mutate() { //Console.WriteLine("Mutating a horrible monster!"); // Randomly relocate a city in the route int randCityIndex = rnd.Next() % this.route.Count; int randCity = this.route[randCityIndex]; this.route.Remove(randCity); int randLocation = rnd.Next() % this.route.Count; this.route.Insert(randLocation, randCity); // construct a new TSPSolution from the mutated route ArrayList solution = new ArrayList(); for (int i = 0; i < route.Count; i++) { solution.Add(Cities[route[i]]); } TSPSolution tspSolution = new TSPSolution(solution); this.solution = tspSolution; // create new mutated child and replace this child for (int i = 0; i < this.route.Count; i++) { if (i + 1 == this.route.Count) { links[this.route[i]] = this.route[0]; } else { links[this.route[i]] = this.route[i + 1]; } } }
public GSCitizen(List <int> route) { GSCitizen.citizenCount++; this.route = route; this.links = new int[Cities.Length]; ArrayList solution = new ArrayList(); for (int i = 0; i < route.Count; i++) { if (i + 1 == route.Count) { links[route[i]] = route[0]; } else { links[route[i]] = route[i + 1]; } solution.Add(Cities[route[i]]); } this.solution = new TSPSolution(solution); }