Skip to content

Commit

Permalink
chore: fail fast when score corruption detected (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
triceo authored Feb 25, 2025
1 parent 991076d commit e621750
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String getBenchmarkParamName() {
ScoreDirectorFactoryConfig scoreDirectorFactoryConfig, SolutionDescriptor<Solution_> solutionDescriptor) {
ScoreDirectorFactoryFactory<Solution_, ?> scoreDirectorFactoryFactory =
new ScoreDirectorFactoryFactory<>(scoreDirectorFactoryConfig);
return scoreDirectorFactoryFactory.buildScoreDirectorFactory(EnvironmentMode.REPRODUCIBLE, solutionDescriptor);
return scoreDirectorFactoryFactory.buildScoreDirectorFactory(EnvironmentMode.PHASE_ASSERT, solutionDescriptor);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private Solution_ readOriginalSolution() {
protected MoveSelector<Solution_> buildMoveSelector(SolutionDescriptor<Solution_> solutionDescriptor) {
// Build the top-level local search move selector as the solver would've built it.
var solverConfig = new SolverConfig()
.withEnvironmentMode(EnvironmentMode.REPRODUCIBLE)
.withEnvironmentMode(EnvironmentMode.PHASE_ASSERT)
.withSolutionClass(solutionDescriptor.getSolutionClass())
.withEntityClasses(solutionDescriptor.getEntityClassSet().toArray(new Class[0]))
.withEasyScoreCalculatorClass(DummyEasyScoreCalculator.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,25 @@ private List<File> getFilteredSolutionFiles(CommonApp<Solution_> commonApp) {

@Execution(ExecutionMode.CONCURRENT)
@TestFactory
Stream<DynamicTest> runFastAndFullAssert() {
Stream<DynamicTest> runStepAndFullAssert() {
CommonApp<Solution_> commonApp = createCommonApp();
ProblemFactory<Solution_> problemFactory = createProblemFactory(commonApp);
/*
* When run in Github Actions, we are limited by the maximum amount of time that the job can run for.
* This code intends to limit the number of tests so that they can all run within the time limit.
*/
return getFilteredSolutionFiles(commonApp).stream()
.map(solutionFile -> dynamicTest(solutionFile.getName(), () -> runFastAndFullAssert(
.map(solutionFile -> dynamicTest(solutionFile.getName(), () -> runStepAndFullAssert(
buildSolverConfig(commonApp.getSolverConfigResource()),
problemFactory.loadProblem(solutionFile))));
}

public void runFastAndFullAssert(SolverConfig solverConfig, Solution_ problem) {
public void runStepAndFullAssert(SolverConfig solverConfig, Solution_ problem) {
// Specifically use NON_INTRUSIVE_FULL_ASSERT instead of FULL_ASSERT to flush out bugs hidden by intrusiveness
// 1) NON_INTRUSIVE_FULL_ASSERT ASSERT to find CH bugs (but covers little ground)
problem = buildAndSolve(solverConfig, EnvironmentMode.NON_INTRUSIVE_FULL_ASSERT, problem, 2L);
// 2) FAST_ASSERT to run past CH into LS to find easy bugs (but covers much ground)
problem = buildAndSolve(solverConfig, EnvironmentMode.FAST_ASSERT, problem, 5L);
// 2) STEP_ASSERT to run past CH into LS to find easy bugs (but covers much ground)
problem = buildAndSolve(solverConfig, EnvironmentMode.STEP_ASSERT, problem, 5L);
// 3) NON_INTRUSIVE_FULL_ASSERT ASSERT to find LS bugs (but covers little ground)
buildAndSolve(solverConfig, EnvironmentMode.NON_INTRUSIVE_FULL_ASSERT, problem, 3L);
}
Expand All @@ -125,7 +125,7 @@ private Solution_ buildAndSolve(SolverConfig solverConfig, EnvironmentMode envir
solverConfig.getTerminationConfig().setMinutesSpentLimit(maximumMinutesSpent);
solverConfig.setEnvironmentMode(environmentMode);
Class<? extends EasyScoreCalculator> easyScoreCalculatorClass = overwritingEasyScoreCalculatorClass();
if (easyScoreCalculatorClass != null && environmentMode.isAsserted()) {
if (easyScoreCalculatorClass != null && environmentMode.isStepAssertOrMore()) {
ScoreDirectorFactoryConfig assertionScoreDirectorFactoryConfig = new ScoreDirectorFactoryConfig();
assertionScoreDirectorFactoryConfig.setEasyScoreCalculatorClass(easyScoreCalculatorClass);
solverConfig.getScoreDirectorFactoryConfig().setAssertionScoreDirectorFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ Stream<DynamicTest> runSpeedTest() {
.flatMap(testData -> {
Stream.Builder<DynamicTest> streamBuilder = Stream.builder();
streamBuilder.add(createSpeedTest(testData.unsolvedDataFile,
EnvironmentMode.REPRODUCIBLE,
EnvironmentMode.PHASE_ASSERT,
testData.bestScoreLimitForReproducible, moveThreadCount));
if (testData.bestScoreLimitForFastAssert != null) {
streamBuilder.add(createSpeedTest(testData.unsolvedDataFile,
EnvironmentMode.FAST_ASSERT,
EnvironmentMode.STEP_ASSERT,
testData.bestScoreLimitForFastAssert, moveThreadCount));
}
if (testData.bestScoreLimitForFullAssert != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void createUninitializedSolutions() {

SolverConfig solverConfig =
SolverConfig.createFromXmlResource(vehicleRoutingApp.getSolverConfigResource());
solverConfig.withEnvironmentMode(EnvironmentMode.REPRODUCIBLE)
solverConfig.withEnvironmentMode(EnvironmentMode.PHASE_ASSERT)
.withMoveThreadCount(MOVE_THREAD_COUNT);
solverConfig.getPhaseConfigList().forEach(phaseConfig -> {
if (LocalSearchPhaseConfig.class.isAssignableFrom(phaseConfig.getClass())) {
Expand Down

0 comments on commit e621750

Please sign in to comment.