1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

Replacing the termination logic to reduce run-times with marginal effect on quality.

This commit is contained in:
safraeli 2019-05-15 15:00:22 +03:00
parent 51fe971d6d
commit 7d7efe40fb

View file

@ -47,7 +47,7 @@ public class IterationWithoutImprovementTermination implements PrematureAlgorith
private List<Integer> 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);
}
}