Esempio n. 1
0
        private static void CompareMethods()
        {
            string s = "problem;method;cost\n";

            foreach (string filename in vrps)
            {
                TSP evaluation = VRPLoader.readTSP(filename);

                List <double> scores = new List <double>();
                for (int i = 0; i < 100; i++)
                {
                    scores.Add(evaluation.Evaluate(GA.GetRandomSolution(evaluation)));
                }
                s += filename + ";random;" + Median(scores).ToString() + "\n";

                scores = new List <double>();
                for (int i = 0; i < evaluation.size; i++)
                {
                    scores.Add(evaluation.Evaluate(GreedyAlgorithm.GenerateGreedySolution(evaluation, i)));
                }
                s += filename + ";greedy;" + scores.Average().ToString() + "\n";

                scores = new List <double>();
                for (int i = 0; i < 10; i++)
                {
                    List <int> solution;
                    (solution, _) = GA.Run(evaluation, 100, 100, 0.6, 0.3, 10);
                    scores.Add(evaluation.Evaluate(solution));
                }
                s += filename + ";genetic;" + Median(scores).ToString() + "\n";
            }
            File.WriteAllText("comparison-test.csv", s);
        }
Esempio n. 2
0
        private static void TestGreedy()
        {
            TSP tsp      = VRPLoader.readTSP(vrps[0]);
            var solution = GreedyAlgorithm.GenerateGreedySolution(tsp, 0);

            Console.WriteLine("Solution: " + ListToString(solution));
            Console.WriteLine("Distance: " + tsp.Evaluate(solution).ToString());
        }
Esempio n. 3
0
        private static void TestGA()
        {
            TSP tsp = VRPLoader.readTSP(vrps[0]);
            List <(double, double, double)> stats;
            List <int> bestSolution;

            (bestSolution, stats) = GA.Run(tsp, 100, 100, 0.7, 0.1, 5);
            Console.WriteLine("Solution: " + ListToString(bestSolution));
            Console.WriteLine("Distance: " + tsp.Evaluate(bestSolution).ToString());
        }
Esempio n. 4
0
        private static void LogStats()
        {
            string s = "problem;generation;best;worst;average\n";

            foreach (string filename in vrps)
            {
                TSP evaluation = VRPLoader.readTSP(filename);
                List <(double, double, double)> stats;
                (_, stats) = GA.Run(evaluation, 100, 100, 0.6, 0.3, 10);
                for (int i = 0; i < stats.Count; i++)
                {
                    s += filename + ";" + i.ToString() + ";" + stats[i].Item1.ToString() + ";" + stats[i].Item2.ToString() + ";" + stats[i].Item3.ToString() + "\n";
                }
            }
            File.WriteAllText("stats-test.csv", s);
        }