コード例 #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());
            


        }
コード例 #2
0
        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()); 
        }