public static void RunGreedyAlgorithm(double maxVehicleDistance, DataSet set, OutputOptions options = OutputOptions.Console, string outPutFileName = null) { List <string> problems = ReadSet(set); List <FileLine> lines = new List <FileLine>(); foreach (string problem in problems) { Console.WriteLine(set + " " + problem); GreedyAlgorithm greedyAlgorithm = new GreedyAlgorithm(maxVehicleDistance); Problem problemInstance = Reader.ReadProblem(set, problem); greedyAlgorithm.LoadProblemInstance(problemInstance); TimeSpan executionTime = greedyAlgorithm.Solve(); Solution sol = greedyAlgorithm.GetSolution(); string result; switch (options) { case OutputOptions.Console: result = sol != null?sol.Cost.ToString() : "no solution found"; Console.WriteLine(problemInstance.Name + " Perfect Solution: " + problemInstance.Solution.Cost + " GreedyAlgorithm cost: " + result); break; case OutputOptions.File: lines.Add(new FileLine(problemInstance, sol, executionTime, 1)); break; default: break; } } if (options == OutputOptions.File) { WriteToFile(lines, outPutFileName); } }
public void TestMethod1() { Problem problem = Reader.ReadProblem(filepath); GreedyAlgorithm greedyAlgorithm = new GreedyAlgorithm(1000.0); greedyAlgorithm.LoadProblemInstance(problem); greedyAlgorithm.Solve(); Solution solution = greedyAlgorithm.GetSolution(); Assert.IsNotNull(solution); }