public void TravelingSalesMan() { for (int keer = 0; keer < 1; keer++) { TravelingSalesmanProblem tsp = new TravelingSalesmanProblem(),copy = new TravelingSalesmanProblem(); /* // add city's string[] places = new string[] { "Aartselaar", "Antwerpen", "Arendonk", "Baarle-Hertog", "Balen", "Beerse", "Berlaar", "Boechout", "Bonheiden", "Boom", "Bornem", "Borsbeek", "Brasschaat", "Brecht", "Dessel", "Duffel", "Edegem", "Essen", "Geel", "Grobbendonk", "Heist-op-den-Berg", "Hemiksem", "Herentals", "Herenthout", "Herselt", "Hoogstraten", "Hove", "Hulshout", "Kalmthout", "Kapellen", "Kasterlee", "Kontich", "Laakdal", "Lier", "Lille", "Lint", "Malle", "Mechelen", "Meerhout", "Merksplas", "Mol", "Mortsel", "Niel", "Nijlen", "Olen", "Oud-Turnhout", "Putte", "Puurs", "Ranst", "Ravels", "Retie", "Rijkevorsel", "Rumst", "Schelle", "Schilde", "Schoten", "Sint-Amands", "Sint-Katelijne-Waver", "Stabroek", "Turnhout", "Vorselaar", "Vosselaar", "Westerlo", "Wijnegem", "Willebroek", "Wommelgem", "Wuustwezel", "Zandhoven", "Zoersel", "Zwijndrecht" }; Random r = new Random((int)DateTime.Now.Ticks); // add vertexes for (int i = 0; i < places.Length; i++) { for (int j = 0; j < places.Length; j++) { if (j != i) { int w = r.Next(1, 150); tsp.AddCityConnection(places[i], places[j], w); copy.AddCityConnection(places[i], places[j], w); } } } */ AddTowns(ref tsp); AddTowns(ref copy); //tsp.WriteGraph(); Console.WriteLine(); SimulatedAnnealing sa = new SimulatedAnnealing(tsp, 0.89, 10); sa.Start(); Console.WriteLine("Cost SA: " + tsp.ObjectifFunction()); tsp.WritePath(); IterativeLocalSearch ils = new IterativeLocalSearch(copy, 10); ils.Start(); Console.WriteLine("Cost ILS: " + copy.ObjectifFunction()); copy.WritePath(); System.Threading.Thread.Sleep(100 * 1000); //System.Collections.ArrayList path = null ; /*for (int i = 0; i < places.Length; i++) { tsp.NNA(i, out path); Console.WriteLine("Cost: " + tsp.ObjectifFunction()); foreach (string s in path) { //Console.Write("\t>" + s); } Console.WriteLine(); } */ /* */ System.Threading.Thread.Sleep(20); } }
public void MinMaxProblem() { MinMaxProblem m, m2, m3; uint sec = 5; int min = 0; int max = 1000000; int size = 100000000; m = new MinMaxProblem(size, 0.25, min, max,0.75); m2 = new MinMaxProblem(m); m3 = new MinMaxProblem(m); for (int i = 1; i <= 5; i++) { sec = ((uint)i) * 5; Console.WriteLine("--- " + sec + " seconds ---"); //Console.WriteLine("Basic Iterative Search"); try { IterativeLocalSearch ils = new IterativeLocalSearch(m,sec); //m = (MinMaxProblem)ils.Solve(); double d = ((double)m.GetMax() - (double)m.GetMin()) / ((double)max / 100.0); Console.WriteLine("BIS %: " + d); Console.WriteLine("\tMin: " + m.GetMin()); Console.WriteLine("\tMax: " + m.GetMax()); //Console.WriteLine("\tDuration : " + ils.Duration()); } catch (Exception e) { Console.WriteLine(e.Message); } //Console.WriteLine("\nSimulated annealing"); try { SimulatedAnnealing sa = new SimulatedAnnealing(m2, 0.89,10); //m2 = (MinMaxProblem)sa.Solve(); double d = ((double)m2.GetMax() - (double)m2.GetMin()) / ((double)max / 100.0); Console.WriteLine("SA %: " + d); Console.WriteLine("\tMin: " + m2.GetMin()); Console.WriteLine("\tMax: " + m2.GetMax()); //Console.WriteLine("\tDuration : " + sa.Duration()); } catch (Exception e) { Console.WriteLine(e.Message); } try { TabuSearch ts = new TabuSearch(m3); //m3 = (MinMaxProblem)ts.Solve(); double d = ((double)m3.GetMax() - (double)m3.GetMin()) / ((double)max / 100.0); Console.WriteLine("TS %: " + d); Console.WriteLine("\tMin: " + m3.GetMin()); Console.WriteLine("\tMax: " + m3.GetMax()); //Console.WriteLine("\tDuration : " + ts.Duration()); } catch (Exception e) { Console.WriteLine(e.Message); } //Console.WriteLine("----------------------"); } }
public void ShortestPathProb() { int size = 50; double adjustRate = 0.3; double percentageWalls = 0.3; uint seconds = 20; ShortestPathProblem spp = new ShortestPathProblem(size, percentageWalls, adjustRate, new Point(size - 1, size - 1)), spp1 = new ShortestPathProblem(size, percentageWalls, adjustRate, new Point(size - 1, size - 1)), spp2 = new ShortestPathProblem(size, percentageWalls, adjustRate, new Point(size - 1, size - 1)); TabuSearch ts = new TabuSearch(spp); //spp = (ShortestPathProblem)ts.Solve(); Console.WriteLine("TS -> Afstand: " + spp.distance()); SimulatedAnnealing sa = new SimulatedAnnealing(spp1, 0.89,seconds); //spp1 = (ShortestPathProblem)sa.Solve(); Console.WriteLine("SA -> Afstand: " + spp1.distance()); //Console.WriteLine(" Duration : " + sa.Duration()); IterativeLocalSearch ils = new IterativeLocalSearch(spp2,seconds); //spp2 = (ShortestPathProblem)ils.Solve(); Console.WriteLine("ILS -> Afstand: " + spp2.distance()); }
public void Thread_Run() { int size = 5,mmsize=1500000; double adjustRate = 0.2; double percentageWalls = 0.1; uint seconds = 5; double levelOfCorrectness = 0.9; // Min Max MinMaxProblem mm = new MinMaxProblem(mmsize, 0.5, 0, 900000000, levelOfCorrectness); System.Threading.Thread.Sleep(20); MinMaxProblem mm2 = new MinMaxProblem(mmsize, 0.5, 0, 900000000, levelOfCorrectness); SimulatedAnnealing sa1 = new SimulatedAnnealing(mm, 0.89, seconds), sa2 = new SimulatedAnnealing(mm, 0.89, seconds); // mm.WriteArray(); // mm2.WriteArray(); ShortestPathProblem spp = new ShortestPathProblem(size, percentageWalls, adjustRate, new Point(size - 1, size - 1)); System.Threading.Thread.Sleep(20); ShortestPathProblem spp2 = new ShortestPathProblem(size, percentageWalls, adjustRate, new Point(size - 1, size - 1)); SimulatedAnnealing sa3 = new SimulatedAnnealing(spp, 0.89, seconds), sa4 = new SimulatedAnnealing(spp, 0.89, seconds); TabuSearch tbs1 = new TabuSearch(mm2, seconds), tbs2 = new TabuSearch(mm2,seconds); // Threads ThreadedSearch ts1 = new ThreadedSearch(sa1, "Min Max 1"), ts2 = new ThreadedSearch(sa2, "Min Max 2"); ThreadedSearch ts3 = new ThreadedSearch(sa3, "Spp 1"), ts4 = new ThreadedSearch(sa4, "Spp 2"); ThreadedSearch ts5 = new ThreadedSearch(tbs1, "Tbs 1"), ts6 = new ThreadedSearch(tbs2, "Tbs 2"); ts1.Start(); ts2.Start(); ts3.Start(); ts4.Start(); ts5.Start(); ts6.Start(); while (ts1.IsAlive() || ts2.IsAlive() || ts3.IsAlive() || ts4.IsAlive() || ts5.IsAlive() || ts6.IsAlive()) ; Console.WriteLine("SA " + ts1.Name() + " Time : " + ts1.Duration()); Console.WriteLine("SA " + ts2.Name() + " Time : " + ts2.Duration()); Console.WriteLine("Objective MM : " + mm.ObjectifFunction()); Console.WriteLine("Max - Min : " + mm.GetMax() + " - " + mm.GetMin()+"\n"); Console.WriteLine("TBS " + ts5.Name() + " Time : " + ts5.Duration()); Console.WriteLine("TBS " + ts6.Name() + " Time : " + ts6.Duration()); Console.WriteLine("Objective MM : " + mm2.ObjectifFunction()); Console.WriteLine("Max - Min : " + mm2.GetMax() + " - " + mm2.GetMin() + "\n"); Console.WriteLine("SA "+ts3.Name()+" Time : " + ts3.Duration()); Console.WriteLine("SA "+ts4.Name()+" Time : " + ts4.Duration()); Console.WriteLine("Objective SSP: " + spp.ObjectifFunction()); //Console.WriteLine("Objective 2: " +spp2.ObjectifFunction()); spp.WriteLabyrinth(); //Console.WriteLine("Objective 4: " + mm2.ObjectifFunction()); }