Skip to content

Commit

Permalink
Introduce BestSolutionRecaller.updateBestSolution(solverScope);
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0ffrey committed Nov 17, 2016
1 parent 44f8995 commit 1c65fd8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
Expand Up @@ -132,8 +132,7 @@ public void stepEnded(ConstructionHeuristicStepScope<Solution_> stepScope) {


public void phaseEnded(ConstructionHeuristicPhaseScope<Solution_> phaseScope) { public void phaseEnded(ConstructionHeuristicPhaseScope<Solution_> phaseScope) {
super.phaseEnded(phaseScope); super.phaseEnded(phaseScope);
Solution_ newBestSolution = phaseScope.getScoreDirector().cloneWorkingSolution(); bestSolutionRecaller.updateBestSolution(phaseScope.getSolverScope());
bestSolutionRecaller.updateBestSolution(phaseScope.getSolverScope(), newBestSolution);
entityPlacer.phaseEnded(phaseScope); entityPlacer.phaseEnded(phaseScope);
decider.phaseEnded(phaseScope); decider.phaseEnded(phaseScope);
phaseScope.endingNow(); phaseScope.endingNow();
Expand Down
Expand Up @@ -29,7 +29,7 @@ public class ConstructionHeuristicPhaseScope<Solution_> extends AbstractPhaseSco


public ConstructionHeuristicPhaseScope(DefaultSolverScope<Solution_> solverScope) { public ConstructionHeuristicPhaseScope(DefaultSolverScope<Solution_> solverScope) {
super(solverScope); super(solverScope);
lastCompletedStepScope = new ConstructionHeuristicStepScope(this, -1); lastCompletedStepScope = new ConstructionHeuristicStepScope<>(this, -1);
} }


@Override @Override
Expand Down
Expand Up @@ -101,9 +101,7 @@ public void stepEnded(CustomStepScope<Solution_> stepScope) {
super.stepEnded(stepScope); super.stepEnded(stepScope);
boolean bestScoreImproved = stepScope.getBestScoreImproved(); boolean bestScoreImproved = stepScope.getBestScoreImproved();
if (forceUpdateBestSolution && !bestScoreImproved) { if (forceUpdateBestSolution && !bestScoreImproved) {
DefaultSolverScope<Solution_> solverScope = stepScope.getPhaseScope().getSolverScope(); bestSolutionRecaller.updateBestSolution(stepScope.getPhaseScope().getSolverScope());
Solution_ newBestSolution = solverScope.getScoreDirector().cloneWorkingSolution();
bestSolutionRecaller.updateBestSolution(solverScope, newBestSolution);
} }
CustomPhaseScope<Solution_> phaseScope = stepScope.getPhaseScope(); CustomPhaseScope<Solution_> phaseScope = stepScope.getPhaseScope();
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
Expand Down
Expand Up @@ -232,8 +232,7 @@ private boolean checkProblemFactChanges() {
problemFactChange = problemFactChangeQueue.poll(); problemFactChange = problemFactChangeQueue.poll();
} }
basicPlumbingTermination.endProblemFactChangesProcessing(); basicPlumbingTermination.endProblemFactChangesProcessing();
Solution_ newBestSolution = solverScope.getScoreDirector().cloneWorkingSolution(); bestSolutionRecaller.updateBestSolution(solverScope);
bestSolutionRecaller.updateBestSolution(solverScope, newBestSolution);
logger.info("Real-time problem fact changes done: step total ({}), new best score ({}).", logger.info("Real-time problem fact changes done: step total ({}), new best score ({}).",
stepIndex, score); stepIndex, score);
return true; return true;
Expand Down
Expand Up @@ -121,17 +121,22 @@ public void processWorkingSolutionDuringMove(Score score, AbstractStepScope<Solu
} }
} }


public void updateBestSolution(DefaultSolverScope<Solution_> solverScope, Solution_ solution) { public void updateBestSolution(DefaultSolverScope<Solution_> solverScope) {
Score score = solverScope.getSolutionDescriptor().getScore(solution); Solution_ newBestSolution = solverScope.getScoreDirector().cloneWorkingSolution();
updateBestSolution(solverScope, newBestSolution);
}

public void updateBestSolution(DefaultSolverScope<Solution_> solverScope, Solution_ newBestSolution) {
Score score = solverScope.getSolutionDescriptor().getScore(newBestSolution);
if (score.isSolutionInitialized()) { if (score.isSolutionInitialized()) {
if (!solverScope.isBestSolutionInitialized()) { if (!solverScope.isBestSolutionInitialized()) {
solverScope.setStartingInitializedScore(score); solverScope.setStartingInitializedScore(score);
} }
} }
solverScope.setBestSolution(solution); solverScope.setBestSolution(newBestSolution);
solverScope.setBestScore(score); solverScope.setBestScore(score);
solverScope.setBestSolutionTimeMillis(System.currentTimeMillis()); solverScope.setBestSolutionTimeMillis(System.currentTimeMillis());
solverEventSupport.fireBestSolutionChanged(solverScope, solution); solverEventSupport.fireBestSolutionChanged(solverScope, newBestSolution);
} }


} }

0 comments on commit 1c65fd8

Please sign in to comment.