Skip to content

Commit

Permalink
fix: only run local search when there is something to run
Browse files Browse the repository at this point in the history
  • Loading branch information
triceo committed Feb 3, 2025
1 parent 8837b33 commit f3b830c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public String getPhaseTypeString() {

@Override
public void solve(SolverScope<Solution_> solverScope) {
var hasAnythingToImprove = solverScope.getProblemSizeStatistics().approximateProblemSizeLog() != 0.0;
if (!hasAnythingToImprove) {
// Reaching local search means that the solution is already fully initialized.
// Yet the problem size indicates there is only 1 possible solution.
// Therefore, this solution must be it and there is nothing to improve.
logger.info("{}Local Search phase ({}) has no entities or values to move.", logIndentation, phaseIndex);
return;
}

LocalSearchPhaseScope<Solution_> phaseScope = new LocalSearchPhaseScope<>(solverScope, phaseIndex);
phaseStarted(phaseScope);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public void solvingStarted(SolverScope<Solution_> solverScope) {
bestSolutionRecaller.solvingStarted(solverScope);
solverTermination.solvingStarted(solverScope);
phaseLifecycleSupport.fireSolvingStarted(solverScope);
solverScope.setProblemSizeStatistics(
solverScope.getSolutionDescriptor().getProblemSizeStatistics(solverScope.getWorkingSolution()));
for (Phase<Solution_> phase : phaseList) {
phase.solvingStarted(solverScope);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ public void solvingStarted(SolverScope<Solution_> solverScope) {
}

private void registerSolverSpecificMetrics() {
solverScope.setProblemSizeStatistics(
solverScope.getSolutionDescriptor().getProblemSizeStatistics(solverScope.getWorkingSolution()));
solverScope.getSolverMetricSet().forEach(solverMetric -> solverMetric.register(this));
}

Expand Down

0 comments on commit f3b830c

Please sign in to comment.