Esempio n. 1
0
        public TspFitness(int numberOfCities, float minX, float maxX, float minY, float 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 p    = GetCityRandomPosition();
                var city = new TspCity(p.x, p.y);
                Cities.Add(city);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeneticSharp.Extensions.Tsp.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;

            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);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeneticSharp.Extensions.Tsp.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;

            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);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeneticSharp.Extensions.Tsp.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);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeneticSharp.Extensions.Tsp.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);
            }
        }
Esempio n. 6
0
 /// <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)));
 }
Esempio n. 7
0
 /// <summary>
 /// Calculates the distance between two cities.
 /// </summary>
 /// <returns>The distance two cities.</returns>
 /// <param name="one">One.</param>
 /// <param name="two">Two.</param>
 private double CalcDistanceTwoCities(TspCity one, TspCity two)
 {
     return Math.Sqrt(Math.Pow(two.X - one.X, 2) + Math.Pow(two.Y - one.Y, 2));
 }