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); }
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()); }