示例#1
0
文件: MCE.cs 项目: braindrillmd/TSP2
        static public Tour Run()
        {
            routineOutput = new RoutineOutput[threadsNumber];

            Thread[] threads = new Thread[threadsNumber];

            for (int i = 0; i < threadsNumber; i++)
            {
                threads[i] = new Thread(new ParameterizedThreadStart(_MCERoutine));
                threads[i].Start(i);
            }

            for (int i = 0; i < threadsNumber; i++)
            {
                threads[i].Join();
            }

            int    minElementIndex = 0;
            double minWeight       = graph.GetTourLength(routineOutput[minElementIndex].RoutineTour);

            for (int i = 0; i < threadsNumber; i++)
            {
                if (routineOutput[i].TourWeight < minWeight)
                {
                    minWeight       = routineOutput[i].TourWeight;
                    minElementIndex = i;
                }
            }

            return(routineOutput[minElementIndex].RoutineTour);
        }
示例#2
0
        private static void _GARoutine(object arg)
        {
            //MessageBox.Show("I am thread " + arg.ToString() + "!");

            Population population = new Population(capacity, graph);

            population.InitializeRandom();

            for (int i = 0; i < iterationsNumber; i++)
            {
                population.NextGeneration();
            }

            Tour bestTour = population.GetFittest();

            routineOutput[(int)arg]             = new RoutineOutput();
            routineOutput[(int)arg].RoutineTour = bestTour;
            routineOutput[(int)arg].TourWeight  = graph.GetTourLength(bestTour);
        }
示例#3
0
        private void buttonRandomTour_Click(object sender, EventArgs e)
        {
            _InitCanvas();
            _DrawMap();
            Tour tour = new Tour(graph.VerticesNumber);

            tour.FillRandomData();
            textBoxPathLength.Text = graph.GetTourLength(tour).ToString();
            Painter.DrawTour(tour, graph, pictureBoxCanvas);

            if (drawRegion == true)
            {
                string[] temp = region.Split(',');
                Painter.DrawRegion(Convert.ToInt32(temp[0]),
                                   Convert.ToInt32(temp[1]),
                                   Convert.ToInt32(temp[2]) - 5,
                                   Convert.ToInt32(temp[3]) + 5,
                                   pictureBoxCanvas);
            }
        }
示例#4
0
 public int Compare(Tour x, Tour y)
 {
     return((int)(graph.GetTourLength(x) - graph.GetTourLength(y)));
 }