Exemple #1
0
        private static void Test()
        {
            Graph graph = Graph.Builder.GetRandomPentagram();

            AcoProcessor processor = new AcoProcessor(graph);

            AcoProcessor.AcoParameters parameters = new AcoProcessor.AcoParameters();
            parameters.beta            = 1;
            parameters.alpha           = 1;
            parameters.pheromonMin     = 0.2;
            parameters.q               = 1;
            parameters.tMax            = 10;
            parameters.p               = 0.1;
            parameters.pheromonInitial = 1;

            int[] path;

            double result = processor.GetShortestPath(parameters, out path);

            Console.WriteLine("Graph matrix: ");
            Console.WriteLine(graph.ToString());

            Console.WriteLine("Result: " + result);

            Console.WriteLine("Result path: " + Utils.PathToString(path));

            Console.ReadKey();
        }
Exemple #2
0
        private static void Experiment()
        {
            Bruteforcer bruteforcer = new Bruteforcer(AlphaMin, AlphaMax, C, RoMin, RoMax, TMin, TMax, Iterations);

            AcoProcessor.AcoParameters parameters = new AcoProcessor.AcoParameters();
            parameters.pheromonMin     = 0.2;
            parameters.q               = 1;
            parameters.pheromonInitial = 1;

            AcoProcessor.AcoParameters[] list = bruteforcer.Iterate(parameters);

            List <double> results = new List <double>();

            Graph graph = Graph.Builder.GetRandomPentagram();

            AcoProcessor processor = new AcoProcessor(Graph.Builder.GetRandomPentagram());

            double shortestPath = double.PositiveInfinity;

            AcoProcessor.AcoParameters optimal = new AcoProcessor.AcoParameters();

            foreach (var param in list)
            {
                int[]  path;
                double result = processor.GetShortestPath(param, out path);
                results.Add(result);

                if (result < shortestPath)
                {
                    shortestPath = result;
                    optimal      = param;
                }
            }

            string output = Utils.ParamsToTable(list, results);

            Console.WriteLine(output);

            Console.WriteLine("Graph: ");
            Console.WriteLine(graph);

            File.WriteAllLines("out.txt", output.Split('\n'));

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Optimal: " + optimal.ToString() + ", result: " + shortestPath);
        }