public static PathChosen NearestNeighbor(CityCollection cities) { PathChosen result = new PathChosen(cities); int numAvailable = cities.Count - 1; List <City> usedCities = new List <City>(); // initialize empty City currentCity = cities[0]; usedCities.Add(currentCity); while (numAvailable > 0) { // find the next closest City closest = cities.NearestTo(currentCity.X, currentCity.Y, usedCities); // add to our path result.AddNextCity(closest); currentCity = closest; // remember that we've seen this usedCities.Add(closest); numAvailable--; } return(result); }
public PathChosen(PathChosen path) { // keep a reference to the cities Cities = path.Cities; // and copy an existing list of indexes that specifies the path to take CityIndexes = new List <int>(path.CityIndexes); }
public CandidateSolution(PathChosen existingPath) { path = new PathChosen(existingPath); cities = path.Cities; }
public CandidateSolution(CityCollection availableCities) { cities = availableCities; path = new PathChosen(cities); path.CreateRandomOrdering(); }