Exemplo n.º 1
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("----------------------");
            }
        }
Exemplo n.º 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()); 
        }