Esempio n. 1
0
        private void GenerateNewBtn_Click(object sender, EventArgs e)
        {
            Cities = CityModel.GetCitiesCoordinate(CityAmount: CityAmount, MapSize: Map.Size);
            DrawMap();

            // Population
            salesmen = new Population(PopulationSize: PopulationTrackBar.Value,
                                      ChildrenAmount: ChildrenTrackBar.Value,
                                      MutationRate: MutationTrackBar.Value,
                                      CitiesMap: Cities);

            isGenerated = true;
        }
Esempio n. 2
0
        // Calculate tour cost as a sum of distances between cities
        public static double Cost(int[] tour, CityModel.City[] cities)
        {
            double Length = 0;

            for (int i = 0; i < tour.Length - 1; ++i)
            {
                int CurrentCity = tour[i];
                int NextCity    = tour[i + 1];
                Length += CityModel.distance(cities[CurrentCity], cities[NextCity]);
            }
            // dont forget to calculate path from last city to first
            // we need to return to our home
            Length += CityModel.distance(cities[tour.First()], cities[tour.Last()]);
            return(Length);
        }