@Override public void stepEnded(AbstractStepScope stepScope) { if (stepScope.isBestSolutionCloningDelayed()) { return; } AbstractSolverPhaseScope phaseScope = stepScope.getPhaseScope(); int uninitializedVariableCount = stepScope.getUninitializedVariableCount(); Score score = stepScope.getScore(); DefaultSolverScope solverScope = phaseScope.getSolverScope(); int bestUninitializedVariableCount = solverScope.getBestUninitializedVariableCount(); Score bestScore = solverScope.getBestScore(); boolean bestScoreImproved; if (uninitializedVariableCount == bestUninitializedVariableCount) { bestScoreImproved = score.compareTo(bestScore) > 0; } else { bestScoreImproved = uninitializedVariableCount < bestUninitializedVariableCount; } stepScope.setBestScoreImproved(bestScoreImproved); if (bestScoreImproved) { phaseScope.setBestSolutionStepIndex(stepScope.getStepIndex()); Solution newBestSolution = stepScope.createOrGetClonedSolution(); updateBestSolution(solverScope, newBestSolution, uninitializedVariableCount); } else if (assertBestScoreIsUnmodified) { solverScope.assertScoreFromScratch(solverScope.getBestSolution()); } }
public void processWorkingSolutionDuringMove( int uninitializedVariableCount, Score score, AbstractStepScope stepScope) { AbstractSolverPhaseScope phaseScope = stepScope.getPhaseScope(); DefaultSolverScope solverScope = phaseScope.getSolverScope(); int bestUninitializedVariableCount = solverScope.getBestUninitializedVariableCount(); Score bestScore = solverScope.getBestScore(); boolean bestScoreImproved; if (uninitializedVariableCount == bestUninitializedVariableCount) { bestScoreImproved = score.compareTo(bestScore) > 0; } else { bestScoreImproved = uninitializedVariableCount < bestUninitializedVariableCount; } // The method processWorkingSolutionDuringMove() is called 0..* times // bestScoreImproved is initialized on false before the first call here if (bestScoreImproved) { stepScope.setBestScoreImproved(bestScoreImproved); } if (bestScoreImproved) { phaseScope.setBestSolutionStepIndex(stepScope.getStepIndex()); Solution newBestSolution = solverScope.getScoreDirector().cloneWorkingSolution(); updateBestSolution(solverScope, newBestSolution, uninitializedVariableCount); } else if (assertBestScoreIsUnmodified) { solverScope.assertScoreFromScratch(solverScope.getBestSolution()); } }
public void solvingStarted(DefaultSolverScope solverScope) { if (solverScope.getBestSolution() == null) { throw new IllegalStateException( "The planningProblem must not be null." + " Use Solver.setPlanningProblem(Solution)."); } solverScope.setStartingSystemTimeMillis(System.currentTimeMillis()); solverScope.setScoreDirector(scoreDirectorFactory.buildScoreDirector()); solverScope.setWorkingRandom(randomFactory.createRandom()); solverScope.setWorkingSolutionFromBestSolution(); bestSolutionRecaller.solvingStarted(solverScope); for (SolverPhase solverPhase : solverPhaseList) { solverPhase.solvingStarted(solverScope); } logger.info( "Solving started: time spend ({}), score ({}), new best score ({}), random ({}).", solverScope.calculateTimeMillisSpend(), solverScope.getStartingInitializedScore(), solverScope.getBestScore(), (randomFactory != null ? randomFactory : "not fixed")); }