internal async Task RunImprovement(Algorithm algorithm, ToSolution solution, AlgorithmType typeToRestart) { Algorithm improvementAlgorithm = default; switch (algorithm) { case HybridCustomUpdate hcu: improvementAlgorithm = hcu; hcu.StartingSolution = solution; // hcu.CanContinueToRelaxConstraints = ??; TODO break; case HybridCustomInsertion hci: improvementAlgorithm = hci; hci.StartingSolution = solution; break; case LinKernighan lk: improvementAlgorithm = lk; lk.CurrentBestSolution = solution; break; } await StartImprovementAlgorithm(improvementAlgorithm, typeToRestart); }
internal override void OnTerminating() { base.OnTerminating(); Solver.BestSolution = CurrentBestSolution; Console.ForegroundColor = ConsoleColor.Yellow; SendMessage(MessageCode.LocalSearchImprovementsPerformed, ImprovementsCount); SendMessage(MessageCode.LocalSearchStop, CurrentBestSolution.Id, CurrentBestSolution.Cost); Console.ForegroundColor = ConsoleColor.Gray; SendMessage(ToSolution.SolutionCollectionToString(_solutionsHistory)); }
internal override void OnTerminating() { base.OnTerminating(); var validSolutions = SolutionsHistory.Where(solution => solution.IsValid); if (validSolutions.Any()) { Solver.BestSolution = validSolutions.MaxBy(solution => solution.Cost); SendMessage(ToSolution.SolutionCollectionToString(SolutionsHistory)); return; } Solver.BestSolution = SolutionsHistory.MaxBy(solution => solution.Cost); Console.ForegroundColor = ConsoleColor.Green; SendMessage(MessageCode.GreedyNotFoundValidSolutions, Type); Console.ForegroundColor = ConsoleColor.Gray; }