Skip to content

Commit

Permalink
PLANNER-491 Revert back to old best solution recaller behavior to fix…
Browse files Browse the repository at this point in the history
… tests + ignore uninitialized solutions in statistics for scores
  • Loading branch information
ge0ffrey committed Nov 17, 2016
1 parent ed6fba8 commit d1d2c8b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
Expand Up @@ -82,6 +82,9 @@ public void writeGraphFiles(BenchmarkReport benchmarkReport) {
singleBenchmarkResult.getSubSingleStatistic(problemStatisticType); singleBenchmarkResult.getSubSingleStatistic(problemStatisticType);
List<BestScoreStatisticPoint> points = subSingleStatistic.getPointList(); List<BestScoreStatisticPoint> points = subSingleStatistic.getPointList();
for (BestScoreStatisticPoint point : points) { for (BestScoreStatisticPoint point : points) {
if (!point.getScore().isSolutionInitialized()) {
continue;
}
long timeMillisSpent = point.getTimeMillisSpent(); long timeMillisSpent = point.getTimeMillisSpent();
double[] levelValues = ScoreUtils.extractLevelDoubles(point.getScore()); double[] levelValues = ScoreUtils.extractLevelDoubles(point.getScore());
for (int i = 0; i < levelValues.length && i < BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE; i++) { for (int i = 0; i < levelValues.length && i < BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE; i++) {
Expand Down
Expand Up @@ -82,6 +82,9 @@ public void writeGraphFiles(BenchmarkReport benchmarkReport) {
singleBenchmarkResult.getSubSingleStatistic(problemStatisticType); singleBenchmarkResult.getSubSingleStatistic(problemStatisticType);
List<StepScoreStatisticPoint> points = subSingleStatistic.getPointList(); List<StepScoreStatisticPoint> points = subSingleStatistic.getPointList();
for (StepScoreStatisticPoint point : points) { for (StepScoreStatisticPoint point : points) {
if (!point.getScore().isSolutionInitialized()) {
continue;
}
long timeMillisSpent = point.getTimeMillisSpent(); long timeMillisSpent = point.getTimeMillisSpent();
double[] levelValues = ScoreUtils.extractLevelDoubles(point.getScore()); double[] levelValues = ScoreUtils.extractLevelDoubles(point.getScore());
for (int i = 0; i < levelValues.length && i < BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE; i++) { for (int i = 0; i < levelValues.length && i < BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE; i++) {
Expand Down
Expand Up @@ -36,6 +36,8 @@ public class DefaultConstructionHeuristicPhase<Solution_> extends AbstractPhase<
protected EntityPlacer entityPlacer; protected EntityPlacer entityPlacer;
protected ConstructionHeuristicDecider decider; protected ConstructionHeuristicDecider decider;


protected final boolean skipBestSolutionCloningInSteps = true;

public void setEntityPlacer(EntityPlacer entityPlacer) { public void setEntityPlacer(EntityPlacer entityPlacer) {
this.entityPlacer = entityPlacer; this.entityPlacer = entityPlacer;
} }
Expand Down Expand Up @@ -94,7 +96,11 @@ private void doStep(ConstructionHeuristicStepScope<Solution_> stepScope) {
Move nextStep = stepScope.getStep(); Move nextStep = stepScope.getStep();
nextStep.doMove(stepScope.getScoreDirector()); nextStep.doMove(stepScope.getScoreDirector());
predictWorkingStepScore(stepScope, nextStep); predictWorkingStepScore(stepScope, nextStep);
bestSolutionRecaller.processWorkingSolutionDuringStep(stepScope); if (!skipBestSolutionCloningInSteps) {
// Causes a planning clone, which is expensive
// For example, on cloud balancing 1200c-4800p this reduces performance by 18%
bestSolutionRecaller.processWorkingSolutionDuringStep(stepScope);
}
} }


@Override @Override
Expand Down Expand Up @@ -133,7 +139,9 @@ public void stepEnded(ConstructionHeuristicStepScope<Solution_> stepScope) {


public void phaseEnded(ConstructionHeuristicPhaseScope<Solution_> phaseScope) { public void phaseEnded(ConstructionHeuristicPhaseScope<Solution_> phaseScope) {
super.phaseEnded(phaseScope); super.phaseEnded(phaseScope);
bestSolutionRecaller.updateBestSolution(phaseScope.getSolverScope()); if (skipBestSolutionCloningInSteps) {
bestSolutionRecaller.updateBestSolution(phaseScope.getSolverScope());
}
entityPlacer.phaseEnded(phaseScope); entityPlacer.phaseEnded(phaseScope);
decider.phaseEnded(phaseScope); decider.phaseEnded(phaseScope);
phaseScope.endingNow(); phaseScope.endingNow();
Expand Down
Expand Up @@ -94,7 +94,8 @@ public void processWorkingSolutionDuringStep(AbstractStepScope<Solution_> stepSc
stepScope.setBestScoreImproved(bestScoreImproved); stepScope.setBestScoreImproved(bestScoreImproved);
if (bestScoreImproved) { if (bestScoreImproved) {
phaseScope.setBestSolutionStepIndex(stepScope.getStepIndex()); phaseScope.setBestSolutionStepIndex(stepScope.getStepIndex());
updateBestSolution(solverScope, score, () -> stepScope.createOrGetClonedSolution()); Solution_ newBestSolution = stepScope.createOrGetClonedSolution();
updateBestSolution(solverScope, score, newBestSolution);
} else if (assertBestScoreIsUnmodified) { } else if (assertBestScoreIsUnmodified) {
solverScope.assertScoreFromScratch(solverScope.getBestSolution()); solverScope.assertScoreFromScratch(solverScope.getBestSolution());
} }
Expand All @@ -111,7 +112,8 @@ public void processWorkingSolutionDuringMove(Score score, AbstractStepScope<Solu
} }
if (bestScoreImproved) { if (bestScoreImproved) {
phaseScope.setBestSolutionStepIndex(stepScope.getStepIndex()); phaseScope.setBestSolutionStepIndex(stepScope.getStepIndex());
updateBestSolution(solverScope, score, () -> solverScope.getScoreDirector().cloneWorkingSolution()); Solution_ newBestSolution = solverScope.getScoreDirector().cloneWorkingSolution();
updateBestSolution(solverScope, score, newBestSolution);
} else if (assertBestScoreIsUnmodified) { } else if (assertBestScoreIsUnmodified) {
solverScope.assertScoreFromScratch(solverScope.getBestSolution()); solverScope.assertScoreFromScratch(solverScope.getBestSolution());
} }
Expand All @@ -120,21 +122,20 @@ public void processWorkingSolutionDuringMove(Score score, AbstractStepScope<Solu
public void updateBestSolution(DefaultSolverScope<Solution_> solverScope) { public void updateBestSolution(DefaultSolverScope<Solution_> solverScope) {
Solution_ newBestSolution = solverScope.getScoreDirector().cloneWorkingSolution(); Solution_ newBestSolution = solverScope.getScoreDirector().cloneWorkingSolution();
Score newBestScore = solverScope.getSolutionDescriptor().getScore(newBestSolution); Score newBestScore = solverScope.getSolutionDescriptor().getScore(newBestSolution);
updateBestSolution(solverScope, newBestScore, () -> newBestSolution); updateBestSolution(solverScope, newBestScore, newBestSolution);
} }


public void updateBestSolution(DefaultSolverScope<Solution_> solverScope, Score bestScore, protected void updateBestSolution(DefaultSolverScope<Solution_> solverScope, Score bestScore,
Supplier<Solution_> bestSolutionCloneSupplier) { Solution_ bestSolution) {
solverScope.setBestScore(bestScore);
solverScope.setBestSolutionTimeMillis(System.currentTimeMillis());
if (bestScore.isSolutionInitialized()) { if (bestScore.isSolutionInitialized()) {
if (!solverScope.isBestSolutionInitialized()) { if (!solverScope.isBestSolutionInitialized()) {
solverScope.setStartingInitializedScore(bestScore); solverScope.setStartingInitializedScore(bestScore);
} }
Solution_ bestSolution = bestSolutionCloneSupplier.get();
solverScope.setBestSolution(bestSolution);
solverEventSupport.fireBestSolutionChanged(solverScope, bestSolution);
} }
solverScope.setBestSolution(bestSolution);
solverScope.setBestScore(bestScore);
solverScope.setBestSolutionTimeMillis(System.currentTimeMillis());
solverEventSupport.fireBestSolutionChanged(solverScope, bestSolution);
} }


} }

0 comments on commit d1d2c8b

Please sign in to comment.