From 7d7efe40fb312211719e5eab4d8ad08ed9687407 Mon Sep 17 00:00:00 2001 From: safraeli Date: Wed, 15 May 2019 15:00:22 +0300 Subject: [PATCH] Replacing the termination logic to reduce run-times with marginal effect on quality. --- .../IterationWithoutImprovementTermination.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/termination/IterationWithoutImprovementTermination.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/termination/IterationWithoutImprovementTermination.java index f45046c7..f34fd63c 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/termination/IterationWithoutImprovementTermination.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/termination/IterationWithoutImprovementTermination.java @@ -47,7 +47,7 @@ public class IterationWithoutImprovementTermination implements PrematureAlgorith private List unassignedCount; - private int bestCost = Integer.MAX_VALUE; + private double bestCost = Double.MAX_VALUE; /** * Constructs termination. * @@ -68,8 +68,11 @@ public class IterationWithoutImprovementTermination implements PrematureAlgorith @Override public boolean isPrematureBreak(SearchStrategy.DiscoveredSolution discoveredSolution) { VehicleRoutingProblemSolution sol = discoveredSolution.getSolution(); + double currentCost = sol.getCost(); - costs.add(Math.min(currentCost, bestCost)); + bestCost = Math.min(currentCost, bestCost); + costs.add(bestCost); + int currentUnassigned = sol.getUnassignedJobs().size(); unassignedCount.add(currentUnassigned); @@ -77,11 +80,9 @@ public class IterationWithoutImprovementTermination implements PrematureAlgorith if (i < noIterationWithoutImprovement) return false; - int progressPercentTerminationCondition = 1; // TODO: Move to configuration + double progressPercentTerminationCondition = 0.1; // TODO: Move to configuration boolean unassignedEqual = (currentUnassigned == unassignedCount.get(i-noIterationWithoutImprovement)); boolean progressTooSlow = (100 * Math.abs(currentCost - costs.get(i - noIterationWithoutImprovement))) / currentCost < progressPercentTerminationCondition; - return (unassignedEqual && progressTooSlow); } - }