/// <summary> /// Initializes a new instance of the <see cref="TspFitness"/> class. /// </summary> /// <param name="numberOfCities">The number of cities.</param> /// <param name="minX">The minimum city x coordinate.</param> /// <param name="maxX">The maximum city x coordinate.</param> /// <param name="minY">The minimum city y coordinate.</param> /// <param name="maxY">The maximum city y coordinate..</param> public TspFitness(int numberOfCities, int minX, int maxX, int minY, int maxY) { Cities = new List <TspCity>(numberOfCities); MinX = minX; MaxX = maxX; MinY = minY; MaxY = maxY; if (maxX >= int.MaxValue) { throw new ArgumentOutOfRangeException("maxX"); } if (maxY >= int.MaxValue) { throw new ArgumentOutOfRangeException("maxY"); } for (int i = 0; i < numberOfCities; i++) { var city = new TspCity(RandomizationProvider.Current.GetInt(MinX, maxX + 1), RandomizationProvider.Current.GetInt(MinY, maxY + 1)); Cities.Add(city); } }
/// <summary> /// Calculates the distance between two cities. /// </summary> /// <returns>The distance two cities.</returns> /// <param name="one">City one.</param> /// <param name="two">City two.</param> private static double CalcDistanceTwoCities(TspCity one, TspCity two) { return(Math.Sqrt(Math.Pow(two.X - one.X, 2) + Math.Pow(two.Y - one.Y, 2))); }