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);
        }
예제 #2
0
        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);
        }
예제 #3
0
 public CandidateSolution(PathChosen existingPath)
 {
     path   = new PathChosen(existingPath);
     cities = path.Cities;
 }
예제 #4
0
 public CandidateSolution(CityCollection availableCities)
 {
     cities = availableCities;
     path   = new PathChosen(cities);
     path.CreateRandomOrdering();
 }