1
0
Fork 0
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:
Eli Safra 2019-05-23 12:01:46 +03:00 committed by GitHub
parent 8696f5ed25
commit 4102a3d488
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View file

@ -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;
}
}

View file

@ -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);
}
}