Skip to content

Commit 28a147e

Browse files
committed
chore: minor improvements
1 parent ea11cbd commit 28a147e

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

core/src/main/java/ai/timefold/solver/core/impl/evolutionaryalgorithm/DefaultEvolutionaryAlgorithmPhaseFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,9 @@ private static <Solution_> Phase<Solution_> buildLocalSearchPhase(HeuristicConfi
405405
}
406406
if (updatedLocalSearchPhaseConfig.getTerminationConfig() == null) {
407407
var terminationConfig = new TerminationConfig();
408-
var windowTime = isComplex ? 20L : 1L;
408+
var windowTime = isComplex ? 30L : 1L;
409409
terminationConfig.setDiminishedReturnsConfig(new DiminishedReturnsTerminationConfig()
410-
.withMinimumImprovementRatio(0.01).withSlidingWindowSeconds(windowTime));
410+
.withMinimumImprovementRatio(0.001).withSlidingWindowSeconds(windowTime));
411411
updatedLocalSearchPhaseConfig.setTerminationConfig(terminationConfig);
412412
}
413413
var clearNearbyClass = updatedLocalSearchPhaseConfig.getMoveSelectorConfig() == null;

core/src/main/java/ai/timefold/solver/core/impl/evolutionaryalgorithm/decider/HybridGeneticSearchDecider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ public void phaseStarted(EvolutionaryAlgorithmPhaseScope<Solution_> phaseScope)
141141
if (exploratoryRate == -1) { // Not set by the user
142142
var scaleLog = phaseScope.getSolverScope().getScoreDirector().getValueRangeManager().getProblemSizeStatistics()
143143
.approximateProblemSizeLog();
144-
// It is expected that the conservative profile will be called 90% of the time for complex problems
145-
exploratoryRate = scaleLog < 427.0 ? 0.9 : 0.1;
144+
// It is expected that the conservative profile will be called 95% of the time for complex problems
145+
exploratoryRate = scaleLog < 427.0 ? 0.95 : 0.05;
146146
}
147147
this.worker = new HybridGeneticSearchWorker<>(HybridGeneticSearchWorkerContext.of(exploratoryRate, context),
148148
bestSolutionUpdater, (DelegatingSplittableRandomGenerator) workerSolverScope.getWorkingRandom(),

core/src/main/java/ai/timefold/solver/core/impl/evolutionaryalgorithm/population/individual/generator/basic/BasicRuinRecreateIndividualStrategy.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ void applyRuinRecreate(InnerScoreDirector<Solution_, Score_> scoreDirector,
102102
EvolutionaryAlgorithmPhaseScope<Solution_> phaseScope, Individual<Solution_, Score_> bestIndividual) {
103103
var bestSolutionState = solutionStateManager.saveSolutionState(scoreDirector, bestIndividual);
104104
solutionStateManager.restoreSolutionState(scoreDirector, bestSolutionState);
105+
if (workingRandom.nextBoolean()) {
106+
// The method can also maintain the current best solution and restart the search from it
107+
return;
108+
}
105109
applyRuinPhase(scoreDirector, workingRandom, bestIndividual);
106110
updateScope(phaseScope);
107111
applyPhases(phaseScope, shuffledFirstFitConstructionPhase);

core/src/main/java/ai/timefold/solver/core/impl/evolutionaryalgorithm/population/individual/generator/list/ListRuinRecreateIndividualStrategy.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public Phase<Solution_> getLocalSearchPhase() {
104104
void applyRuinRecreate(InnerScoreDirector<Solution_, Score_> scoreDirector, Individual<Solution_, Score_> bestIndividual) {
105105
var bestSolutionState = solutionStateManager.saveSolutionState(scoreDirector, bestIndividual);
106106
solutionStateManager.restoreSolutionState(scoreDirector, bestSolutionState);
107+
if (workingRandom.nextBoolean()) {
108+
// The method can also maintain the current best solution and restart the search from it
109+
return;
110+
}
107111
var listVariableDescriptor = Objects.requireNonNull(scoreDirector.getSolutionDescriptor().getListVariableDescriptor());
108112
var listVariableMetaModel = listVariableDescriptor.getVariableMetaModel();
109113
var valueRangeManager = scoreDirector.getValueRangeManager();

0 commit comments

Comments
 (0)