private static void TestResultDrawer() { var result = JsonConvert.DeserializeObject <OptimizationResult>(File.ReadAllText("18-11-10-00-31-22_Dataset_3_ILP.json")); ResultDrawer.DrawResult("debug.gif", result, DatasetFactory.DataSet3().coordinates); }
private static void EvaluateAlgorithm(string[] args) { BigHr(); Console.WriteLine("Program written to evaluate the different optimisation algorithms."); Console.WriteLine(); var algorithmSelection = args.Length == 0 ? QueryAlgorithmSelection() : (Algorithms)Enum.Parse(typeof(Algorithms), args[0]); SmallHr(); Console.WriteLine(); var datasetSelection = args.Length == 0 ? QueryDatasetSelection() : GetDatasetSelection(int.Parse(args[1])); SmallHr(); Console.WriteLine(); var runs = args.Length == 0 ? QueryNumberOfRuns() : int.Parse(args[2]); SmallHr(); Console.WriteLine(); Console.WriteLine("Starting the algorithm now"); BigHr(); for (int i = 0; i < runs; i++) { foreach (var dataset in datasetSelection) { try { var(input, coordinates, timelimit) = GetDataset(dataset); string savepath = $"{DateTime.Now:yy-MM-dd-HH-mm-ss}_DataSet_{dataset}"; ISolver solver = null; var fastFactor = 60; switch (algorithmSelection) { case Algorithms.ILPFast: timelimit /= fastFactor; goto case Algorithms.ILP; case Algorithms.ILP: solver = new ILPSolver(input, new ILPConfig { ClusteringMIPGap = 0, SchedulingMIPGap = 0, ClusteringTimeLimitMiliseconds = (long)(0.7 * timelimit), SchedulingTimeLimitMiliseconds = (long)(0.3 * timelimit), TimeSliceDuration = 120 }); savepath += "_ILP"; break; case Algorithms.LocalSolverFast: timelimit /= fastFactor; goto case Algorithms.LocalSolver; case Algorithms.LocalSolver: solver = new Solver(input, new LocalSolverConfig { VrpTimeLimitFactor = 0.1, VrptwTimeLimitFactor = 0.8, MaxNumberOfAdditionalSantas = 0, }); savepath += "_LocalSolver"; break; case Algorithms.GA: solver = new GenAlgSolver(input, new GenAlgConfig(input)); savepath += "_GA"; break; case Algorithms.GAFast: timelimit /= fastFactor; solver = new GenAlgSolver(input, new GenAlgConfig(input)); savepath += "_GAFast"; break; case Algorithms.ILP2Fast: timelimit /= fastFactor; goto case Algorithms.ILP2; case Algorithms.ILP2: solver = new IRuettae.Core.ILP2.Solver(input, 0.1, dataset.ToString()); savepath += "_ILP2"; break; case Algorithms.ILPIP5GurobiFast: timelimit /= fastFactor; goto case Algorithms.ILPIP5Gurobi; case Algorithms.ILPIP5Gurobi: solver = new ILPIp5GurobiSolver(input, new ILPIp5GurobiConfig { ClusteringMIPGap = 0, SchedulingMIPGap = 0, ClusteringTimeLimitMiliseconds = (long)(0.7 * timelimit), SchedulingTimeLimitMiliseconds = (long)(0.3 * timelimit), TimeSliceDuration = 120 }); savepath += "_ILPIp5Gurobi"; break; case Algorithms.GoogleRoutingFast: timelimit /= fastFactor; solver = new GoogleRoutingSolver(input, GoogleRoutingConfig.GetDefault(input)); savepath += "_GoogleRoutingFast"; break; case Algorithms.GoogleRouting: solver = new GoogleRoutingSolver(input, GoogleRoutingConfig.GetDefault(input)); savepath += "_GoogleRouting"; break; } AddUnavailableBetweenDays(input); OptimizationResult result = null; void WriteConsoleInfo(object sender, string s) { Console.WriteLine($"Info ({DateTime.Now:HH-mm-ss}): {s}"); } void WriteConsoleProgress(object sender, ProgressReport report) { Console.WriteLine($"Progress: {report}"); } #if DEBUG using (var sw = new StreamWriter(savepath + "-log.txt", true)) { result = solver.Solve(timelimit, WriteConsoleProgress, (sender, s) => { WriteConsoleInfo(sender, s); sw.WriteLine(s); }); } #else result = solver.Solve(timelimit, WriteConsoleProgress, WriteConsoleInfo); #endif BigHr(); File.WriteAllText(savepath + ".json", JsonConvert.SerializeObject(result)); var summary = new StringBuilder(); summary.AppendLine($"Solver: {AlgorithmsDictionary[algorithmSelection]}"); summary.AppendLine($"Dataset{dataset}: {DatasetDictionary[dataset]}"); summary.AppendLine($"TimeElapsed [s]: {result.TimeElapsed}"); try { if (!result.IsValid()) { summary.AppendLine( $"IMPORTANT: This result seems to be invalid. The reason is \"{result.Validate()}\""); } } catch { summary.AppendLine("error while checking invalidity"); } summary.AppendLine($"Cost: {result.Cost()}"); summary.AppendLine($"NumberOfNotVisitedFamilies: {result.NumberOfNotVisitedFamilies()}"); summary.AppendLine($"NumberOfMissingBreaks: {result.NumberOfMissingBreaks()}"); summary.AppendLine($"NumberOfAdditionalSantas: {result.NumberOfAdditionalSantas()}"); summary.AppendLine($"AdditionalSantaWorkTime: {result.AdditionalSantaWorkTime()}"); summary.AppendLine($"VisitTimeInUnavailable: {result.VisitTimeInUnavailable()}"); summary.AppendLine($"WayTimeOutsideBusinessHours: {result.WayTimeOutsideBusinessHours()}"); summary.AppendLine($"VisitTimeInDesired: {result.VisitTimeInDesired()}"); summary.AppendLine($"SantaWorkTime: {result.SantaWorkTime()}"); summary.AppendLine($"LongestDay: {result.LongestDay()}"); summary.AppendLine($"NumberOfRoutes: {result.NumberOfRoutes()}"); File.WriteAllText(savepath + ".txt", summary.ToString()); Console.WriteLine(); Console.WriteLine("Done solving"); Console.WriteLine(summary.ToString()); ResultDrawer.DrawResult(savepath, result, coordinates); } catch (Exception e) { Console.WriteLine($"An exception occured: {e.Message}"); } } } }