Ejemplo n.º 1
0
        public Tour GetFittest()
        {
            //TODO: procedure
            TourComparer comparer = new TourComparer(graph);

            Array.Sort(toursPopulation, comparer);

            return(toursPopulation[0]);
        }
Ejemplo n.º 2
0
        public void NextGeneration()
        {
            //MessageBox.Show("Enterng NextGeneration()");

            TourComparer comparer = new TourComparer(graph);

            Array.Sort(toursPopulation, comparer);
            Tour[] newTourPopulation = new Tour[capacity];


            for (int i = 0; i < capacity; i++)
            {
                newTourPopulation[i] = new Tour(graph.VerticesNumber);
                newTourPopulation[i].CopyTour(toursPopulation[i]);
            }

            for (int i = capacity / 2; i < capacity - 1; i++)
            {
                Tour child1 = toursPopulation[i - capacity / 2].CrossingOver(toursPopulation[i - capacity / 2 + 1]);
                Tour child2 = toursPopulation[i - capacity / 2 + 1].CrossingOver(toursPopulation[i - capacity / 2]);
                newTourPopulation[i] = new Tour(graph.VerticesNumber);
                newTourPopulation[i].CopyTour(child1);
                newTourPopulation[i + 1] = new Tour(graph.VerticesNumber);
                newTourPopulation[i + 1].CopyTour(child2);
            }

            for (int i = 0; i < capacity; i++)
            {
                if (random.Next(100) < mutationProbability)
                {
                    newTourPopulation[i].Mutate();
                }
            }

            toursPopulation = newTourPopulation;
        }