Esempio n. 1
0
        //---------------------------------------------------------------------
        public static void TestRandomWalkv2(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;

                //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);

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

                //-------------------------------------------------------------------

                for (int j = 0; j < num_test; j++)
                {
                    RandomWalkv2 rw2 = new RandomWalkv2();
                    rw2.ExecuteRandomWalk(ref env);

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

                    ////Store variables in a txt
                    Console.WriteLine("Execution {0} of " + file_name, j);
                    StoreVariables_RW2(mesh_type, ref env, ref rw2);
                    StoreVariable_RW2_and_ACOv0(mesh_type, ref env, ref acov0, ref rw2);
                    env.InitPheromones(0);
                }

                Console.WriteLine("End Execution -> " + file_name);
                Console.WriteLine("---------------------------------------------");
            }
        }
Esempio n. 2
0
        //--------------------------------------------------------------------
        public static void TestACOv0(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;
                int    j         = 0;
                Console.WriteLine("Execution -> " + file_name);

                while (j < num_test)
                {
                    //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);
                    //-------------------------------------------------------------------

                    //Create and Execute ACOv0
                    AntColonyOptimizationv0 acov0 = new AntColonyOptimizationv0();
                    acov0.ExecuteACO(ref env);

                    //-------------------------------------------------------------------
                    //Store variables in a txt
                    Console.WriteLine("Execution {0}", j);
                    StoreTestingVariablesACOv0(mesh_type, ref env, ref acov0);
                    j++;
                    //}
                }
            }
        }
        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("---------------------------------------------");
            }
        }
        //-------------------------------------------------------------------------------
        public static void StoreVariable_RWv2_ACOv0(string mesh_type, ref MeshEnvironment env, ref DijkstraAlgorithm dk1, ref AntColonyOptimizationv0 aco1, ref DijkstraAlgorithm dk2, ref AntColonyOptimizationv0 aco2)
        {
            string separator = " ";
            string method    = "rw2_acov0";

            Double d2  = aco2.best_cost < dk2.final_best_cost ? dk2.final_best_cost : aco2.best_cost;
            Double ac1 = (dk1.final_best_cost / aco1.best_cost) * 100;
            Double ac2 = (dk2.final_best_cost / d2) * 100;

            string line = mesh_type + separator;

            line += env.size + separator;
            line += dk1.final_best_cost + separator;
            line += aco1.best_cost + separator;
            line += ac1 + separator;
            line += aco1.execution_time + separator;
            line += dk2.final_best_cost + separator;
            line += d2 + separator;
            line += ac2 + separator;
            line += aco2.execution_time;


            string path2           = @"data_sets/results/several_methods/";
            string variables_file2 = method + "_" + mesh_type + ".txt";

            using (StreamWriter file =
                       File.AppendText(path2 + variables_file2))
            {
                file.WriteLine(line);
            }

            string path           = @"data_sets/results/several_methods/" + mesh_type + "/";
            string variables_file = method + "_" + mesh_type + "_" + env.size + "x" + env.size + ".txt";

            using (StreamWriter file =
                       File.AppendText(path + variables_file))
            {
                file.WriteLine(line);
            }
        }
Esempio n. 5
0
        //--------------------------------------------------------------------
        public static void StoreTestingVariablesACOv0(string mesh_type, ref MeshEnvironment env, ref AntColonyOptimizationv0 aco)
        {
            env.FillDistanceMatrix();
            DijkstraJustCost dijkstra  = new DijkstraJustCost();
            Double           best_cost = dijkstra.DijkstraAlgo(graph: env.distances, source: env.start_node, verticesCount: env.final_node + 1);


            Double percentage_learning = MeasureFunctions.CalculatePercentageLearning(ref env);
            string separator           = " ";
            string line = mesh_type + separator;

            line += env.world.Count + separator;
            line += env.edges.Count + separator;
            line += best_cost + separator;
            line += aco.max_ants + separator;
            line += aco.alpha + separator;
            line += aco.beta + separator;
            line += aco.tau_0 + separator;
            line += aco.evaporation_factor + separator;
            line += aco.percentage_convergence + separator;
            line += aco.episode_counter + separator;
            line += aco.execution_time + separator;
            line += aco.stuck_roads + separator;
            line += MeasureFunctions.GetVisitedNodes(ref env) + separator;
            line += MeasureFunctions.GetVisitedEdges(ref env) + separator;
            line += Math.Round(aco.best_cost, 2) + separator;
            line += percentage_learning;

            string path           = @"data_sets/results/acov0/";
            string variables_file = "variables_acov0" + "_" + mesh_type + "_" + env.size + "x" + env.size + ".txt";

            using (StreamWriter file =
                       File.AppendText(path + variables_file))
            {
                file.WriteLine(line);
            }
        }