mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Opti 644 correct best cost (#86)
* Fix the condition to use bestCost as this is what we are traceing. Added log to debug to state the termination * Fix the condition to use bestCost as this is what we are traceing. Added log to debug to state the termination * Fix the condition to use bestCost as this is what we are traceing. Added log to debug to state the termination * Fix the condition to use bestCost as this is what we are traceing. Added log to debug to state the termination * Fix the condition to use bestCost as this is what we are traceing. Added log to debug to state the termination * Fix the condition to use bestCost as this is what we are traceing. Added log to debug to state the termination * Fix the condition to use bestCost as this is what we are traceing. Added log to debug to state the termination
This commit is contained in:
parent
8696f5ed25
commit
4102a3d488
2 changed files with 27 additions and 2 deletions
|
|
@ -107,7 +107,11 @@ public class IterationWithoutImprovementTermination implements PrematureAlgorith
|
|||
return false;
|
||||
|
||||
boolean unassignedJobsEqual = (currentJobsUnassigned == unassignedJobsCount.get(i - noIterationWithoutImprovement));
|
||||
boolean progressTooSlow = 100 * ((costs.get(i - noIterationWithoutImprovement) - currentCost) / currentCost) <= terminationByCostPercentage;
|
||||
return (unassignedJobsEqual && progressTooSlow);
|
||||
boolean progressTooSlow = 100 * ((costs.get(i - noIterationWithoutImprovement) - bestCost) / bestCost) <= terminationByCostPercentage;
|
||||
if (unassignedJobsEqual && progressTooSlow){
|
||||
log.debug("Termination condition by percentage reached after " + Integer.toString(i) + " iterations.");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,4 +150,25 @@ public class IterationsWithoutImprovementTest {
|
|||
Assert.assertEquals(60, terminatedAfter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPrematureBreakLastCostIsWorstShouldNotBreak() {
|
||||
int maxIterations = 7;
|
||||
IterationWithoutImprovementTermination termination = new IterationWithoutImprovementTermination(5, 1.0);
|
||||
SearchStrategy.DiscoveredSolution discoveredSolution = mock(SearchStrategy.DiscoveredSolution.class);
|
||||
VehicleRoutingProblemSolution solution = mock(VehicleRoutingProblemSolution.class);
|
||||
when(discoveredSolution.getSolution()).thenReturn(solution);
|
||||
when(solution.getUnassignedJobs()).thenReturn(new ArrayList<Job>());
|
||||
|
||||
boolean isTerminate = false;
|
||||
for (int i = 0; i < maxIterations; i++) {
|
||||
|
||||
when(solution.getCost()).thenReturn(i < 6.0 ? 10.0-i : 12);
|
||||
boolean terminate = termination.isPrematureBreak(discoveredSolution);
|
||||
if (terminate) {
|
||||
isTerminate= true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.assertFalse(isTerminate);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue