Exemplo n.º 1
0
        private void RunBuntton_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (_dGraph == null) //|| _dGraph.Vertices.Any(v => v.Visited))
            {
                MessageBox.Show("Загрузите новый лабиринт!", "Warning", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return;
            }
            //запускаем параллельно все наши алгоритмы
            if (dijkstraButton.Down)
            {
                Task.Run(() => DijkstraAlgorithm.Execute(_dGraph, dijkstraPanel, dijkstraFirst, dijkstraBest));
                return;
            }

            if (bfsButton.Down)
            {
                Task.Run(() => BreadthFirst.Execute(_bGraph, bFirstPanel, bfFirst, bfBest));
                return;
            }

            if (astarButton.Down)
            {
                Task.Run(() => AStar.Execute(_aGraph, aStarPanel, asFirst, asBest));
                return;
            }
            Task.Run(() => DijkstraAlgorithm.Execute(_dGraph, dijkstraPanel, dijkstraFirst, dijkstraBest));
            Task.Run(() => BreadthFirst.Execute(_bGraph, bFirstPanel, bfFirst, bfBest));
            Task.Run(() => AStar.Execute(_aGraph, aStarPanel, asFirst, asBest));
        }
Exemplo n.º 2
0
        public static void Test_Genetic(string mesh_type)
        {
            int[] sizes_mesh = new int[21] {
                10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50
            };
            int[] final_positions = new int[21] {
                99, 143, 195, 255, 323, 399, 483, 575, 675, 783, 899, 1023, 1155, 1295, 1443, 1599, 1763, 1935, 2115, 2303, 2499
            };

            for (int i = 0; i < sizes_mesh.Length; i++)
            {
                string size      = "_" + sizes_mesh[i] + "x" + sizes_mesh[i] + ".txt";
                string file_name = mesh_type + size;

                Console.WriteLine("Init Execution -> " + file_name);

                //-------------------------------------------------------------------
                //Create the mesh environment
                MeshEnvironment env = new MeshEnvironment(_start: 0, _final: final_positions[i], _file_name: file_name, sizes_mesh[i]);
                env.InitEnviroment(type_mesh: mesh_type);

                //-------------------------------------------------------------------
                for (int j = 0; j < num_test; j++)
                {
                    env.FillDistanceMatrix();
                    DijkstraAlgorithm dk1 = new DijkstraAlgorithm();
                    dk1.Execute(ref env);

                    GeneticAlgorithm gn1 = new GeneticAlgorithm();
                    gn1.Execute(ref env);


                    //Insert the obstacle in a middle zone of the current optimal solution
                    InsertSeveralObstacle(ref env, num_obstacle: 2, num_routes: 2);

                    env.FillDistanceMatrix();
                    DijkstraAlgorithm dk2 = new DijkstraAlgorithm();
                    dk2.Execute(ref env);

                    GeneticAlgorithm gn2 = new GeneticAlgorithm();
                    gn2.Execute(ref env);

                    ////Store variables in a txt
                    Console.WriteLine("Execution {0} of " + file_name, j);

                    StoreVariable_Genetic(mesh_type, ref env, ref dk1, ref gn1, ref dk2, ref gn2);

                    env.ClearObstacles();
                }

                Console.WriteLine("End Execution -> " + file_name);
                Console.WriteLine("---------------------------------------------");
            }
        }
Exemplo n.º 3
0
        public static void InsertSeveralObstacle(ref MeshEnvironment env, int num_obstacle, int num_routes)
        {
            for (int i = 0; i < num_routes; i++)
            {
                env.FillDistanceMatrix();
                DijkstraAlgorithm dk = new DijkstraAlgorithm();
                dk.Execute(ref env);

                //Ver bien como poner esto
                env.InsertObstacle(ref dk.final_best_path, num_obstacle);
            }
        }
Exemplo n.º 4
0
        public void ExecuteTest()
        {
            IGraph <string, string> graph = new AdjacencyMapGraph <string, string>();
            IVertex <string>        A     = graph.addVertex("A");
            IVertex <string>        B     = graph.addVertex("B");
            IVertex <string>        C     = graph.addVertex("C");
            IVertex <string>        D     = graph.addVertex("D");
            IVertex <string>        E     = graph.addVertex("E");
            IVertex <string>        F     = graph.addVertex("F");
            IVertex <string>        G     = graph.addVertex("G");
            IVertex <string>        H     = graph.addVertex("H");
            IVertex <string>        I     = graph.addVertex("I");
            IVertex <string>        J     = graph.addVertex("J");
            IVertex <string>        K     = graph.addVertex("K");
            IVertex <string>        L     = graph.addVertex("L");
            IVertex <string>        M     = graph.addVertex("M");
            IVertex <string>        N     = graph.addVertex("N");

            graph.addEdge(A, B, "1", 3);
            graph.addEdge(C, B, "2", 3);
            graph.addEdge(A, E, "3", 2);
            graph.addEdge(A, I, "4", 5);
            graph.addEdge(I, E, "5", 3);
            graph.addEdge(E, D, "6", 4);
            graph.addEdge(D, C, "7", 2);
            graph.addEdge(C, G, "8", 5);
            graph.addEdge(D, F, "9", 3);
            graph.addEdge(F, G, "10", 3);
            graph.addEdge(G, H, "11", 4);
            graph.addEdge(H, F, "12", 2);
            graph.addEdge(E, M, "13", 1);
            graph.addEdge(E, J, "14", 5);
            graph.addEdge(M, N, "15", 5);
            graph.addEdge(M, J, "16", 2);
            graph.addEdge(M, F, "17", 3);
            graph.addEdge(M, K, "18", 2);
            graph.addEdge(J, K, "19", 3);
            graph.addEdge(K, L, "20", 1);

            DijkstraAlgorithm <string, string> d = new DijkstraAlgorithm <string, string>(graph);

            d.Execute(A);

            StringBuilder sb = new StringBuilder();

            foreach (IVertex <string> v in d.getPredecessors().Keys)
            {
                sb.Append(v.ToString() + " from " + d.getPredecessors()[v].ToString() + Environment.NewLine);
            }

            MessageBox.Show(sb.ToString());
        }
Exemplo n.º 5
0
        public static void Test_RWv2_ACOv0(string mesh_type)
        {
            int[] sizes_mesh = new int[21] {
                10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50
            };
            int[] final_positions = new int[21] {
                99, 143, 195, 255, 323, 399, 483, 575, 675, 783, 899, 1023, 1155, 1295, 1443, 1599, 1763, 1935, 2115, 2303, 2499
            };

            for (int i = 0; i < sizes_mesh.Length; i++)
            {
                string size      = "_" + sizes_mesh[i] + "x" + sizes_mesh[i] + ".txt";
                string file_name = mesh_type + size;

                Console.WriteLine("Init Execution -> " + file_name);

                //-------------------------------------------------------------------
                //Create the mesh environment
                MeshEnvironment env = new MeshEnvironment(_start: 0, _final: final_positions[i], _file_name: file_name, sizes_mesh[i]);
                env.InitEnviroment(type_mesh: mesh_type);

                //-------------------------------------------------------------------
                for (int j = 0; j < num_test; j++)
                {
                    //............................................................................
                    // ROUTE 1
                    env.FillDistanceMatrix();
                    DijkstraAlgorithm dk1 = new DijkstraAlgorithm();
                    dk1.Execute(ref env);

                    RandomWalkv2 rw1 = new RandomWalkv2();
                    rw1.ExecuteRandomWalk(ref env);

                    AntColonyOptimizationv0 aco1 = new AntColonyOptimizationv0(_random_walk: true);
                    aco1.ExecuteACO(ref env);

                    //............................................................................
                    //Insert the obstacle in a middle zone of the current optimal solution
                    InsertSeveralObstacle(ref env, num_obstacle: 2, num_routes: 2);
                    //............................................................................
                    // ROUTE 2 - REROUTING

                    env.FillDistanceMatrix();
                    DijkstraAlgorithm dk2 = new DijkstraAlgorithm();
                    dk2.Execute(ref env);

                    RandomWalkv2 rw2 = new RandomWalkv2();
                    rw2.ExecuteRandomWalk(ref env);

                    AntColonyOptimizationv0 aco2 = new AntColonyOptimizationv0(_random_walk: true);
                    aco2.ExecuteACO(ref env);

                    //............................................................................
                    ////Store variables in a txt
                    Console.WriteLine("Execution {0} of " + file_name, j);
                    StoreVariable_RWv2_ACOv0(mesh_type, ref env, ref dk1, ref aco1, ref dk2, ref aco2);

                    //............................................................................
                    //Reset environment
                    env.InitPheromones(0);
                    env.ClearObstacles();
                }

                Console.WriteLine("End Execution -> " + file_name);
                Console.WriteLine("---------------------------------------------");
            }
        }