diff --git a/core/src/main/java/ai/timefold/solver/core/impl/localsearch/DefaultLocalSearchPhase.java b/core/src/main/java/ai/timefold/solver/core/impl/localsearch/DefaultLocalSearchPhase.java index 8bb5be4f62..c2a53cdbcf 100644 --- a/core/src/main/java/ai/timefold/solver/core/impl/localsearch/DefaultLocalSearchPhase.java +++ b/core/src/main/java/ai/timefold/solver/core/impl/localsearch/DefaultLocalSearchPhase.java @@ -54,6 +54,15 @@ public String getPhaseTypeString() { @Override public void solve(SolverScope 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 phaseScope = new LocalSearchPhaseScope<>(solverScope, phaseIndex); phaseStarted(phaseScope); diff --git a/core/src/main/java/ai/timefold/solver/core/impl/solver/AbstractSolver.java b/core/src/main/java/ai/timefold/solver/core/impl/solver/AbstractSolver.java index d487c7d33e..34d50e7987 100644 --- a/core/src/main/java/ai/timefold/solver/core/impl/solver/AbstractSolver.java +++ b/core/src/main/java/ai/timefold/solver/core/impl/solver/AbstractSolver.java @@ -65,6 +65,8 @@ public void solvingStarted(SolverScope solverScope) { bestSolutionRecaller.solvingStarted(solverScope); solverTermination.solvingStarted(solverScope); phaseLifecycleSupport.fireSolvingStarted(solverScope); + solverScope.setProblemSizeStatistics( + solverScope.getSolutionDescriptor().getProblemSizeStatistics(solverScope.getWorkingSolution())); for (Phase phase : phaseList) { phase.solvingStarted(solverScope); } diff --git a/core/src/main/java/ai/timefold/solver/core/impl/solver/DefaultSolver.java b/core/src/main/java/ai/timefold/solver/core/impl/solver/DefaultSolver.java index 4545e2ee66..66bf660d61 100644 --- a/core/src/main/java/ai/timefold/solver/core/impl/solver/DefaultSolver.java +++ b/core/src/main/java/ai/timefold/solver/core/impl/solver/DefaultSolver.java @@ -245,8 +245,6 @@ public void solvingStarted(SolverScope solverScope) { } private void registerSolverSpecificMetrics() { - solverScope.setProblemSizeStatistics( - solverScope.getSolutionDescriptor().getProblemSizeStatistics(solverScope.getWorkingSolution())); solverScope.getSolverMetricSet().forEach(solverMetric -> solverMetric.register(this)); }