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); }
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); }
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); } }
public int Compare(Tour x, Tour y) { return((int)(graph.GetTourLength(x) - graph.GetTourLength(y))); }