コード例 #1
0
        public static TSPCity[] RandomCities(int Count, int MaxX, int MaxY)
        {
            TSPCity[] cities = new TSPCity[Count];
            Random    rand   = new Random();

            for (int i = 0; i < Count; i++)
            {
                TSPCity city = new TSPCity();
                city.x    = rand.Next(MaxX);
                city.y    = rand.Next(MaxY);
                cities[i] = city;
            }
            return(cities);
        }
コード例 #2
0
 private void DrawPath(Graphics g, TSPCity From, TSPCity To)
 {
     g.DrawLine(new Pen(PATH_BRUSH), From.x, From.y, To.x, To.y);
 }
コード例 #3
0
 private void DrawCity(Graphics g, TSPCity City)
 {
     g.FillEllipse(CITY_BRUSH, City.x - CITY_RADIUS, City.y - CITY_RADIUS, CITY_RADIUS * 2, CITY_RADIUS * 2);
 }
コード例 #4
0
 public double Distance(TSPCity other)
 {
     return(Math.Sqrt(
                Math.Pow(this.x - other.x, 2) +
                Math.Pow(this.y - other.y, 2)));
 }