Ejemplo n.º 1
0
        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());
            


        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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("----------------------");
            }
        }