public boolean isAccepted(LocalSearchMoveScope moveScope) {
   LocalSearchSolverPhaseScope phaseScope = moveScope.getStepScope().getPhaseScope();
   Score lastStepScore = phaseScope.getLastCompletedStepScope().getScore();
   Score moveScore = moveScope.getScore();
   if (moveScore.compareTo(lastStepScore) >= 0) {
     return true;
   }
   Score moveScoreDifference = lastStepScore.subtract(moveScore);
   double[] moveScoreDifferenceLevels = ScoreUtils.extractLevelDoubles(moveScoreDifference);
   double acceptChance = 1.0;
   for (int i = 0; i < levelsLength; i++) {
     double moveScoreDifferenceLevel = moveScoreDifferenceLevels[i];
     double temperatureLevel = temperatureLevels[i];
     double acceptChanceLevel;
     if (moveScoreDifferenceLevel <= 0.0) {
       // In this level, moveScore is better than the lastStepScore, so do not disrupt the
       // acceptChance
       acceptChanceLevel = 1.0;
     } else {
       acceptChanceLevel = Math.exp(-moveScoreDifferenceLevel / temperatureLevel);
     }
     acceptChance *= acceptChanceLevel;
   }
   if (moveScope.getWorkingRandom().nextDouble() < acceptChance) {
     return true;
   } else {
     return false;
   }
 }
 @Override
 public void phaseStarted(LocalSearchSolverPhaseScope phaseScope) {
   super.phaseStarted(phaseScope);
   for (double startingTemperatureLevel : ScoreUtils.extractLevelDoubles(startingTemperature)) {
     if (startingTemperatureLevel < 0.0) {
       throw new IllegalArgumentException(
           "The startingTemperature ("
               + startingTemperature
               + ") cannot have negative level ("
               + startingTemperatureLevel
               + ").");
     }
   }
   startingTemperatureLevels = ScoreUtils.extractLevelDoubles(startingTemperature);
   temperatureLevels = startingTemperatureLevels;
   levelsLength = startingTemperatureLevels.length;
 }
예제 #3
0
 private void writeBestScorePerTimeSpentSummaryChart() {
   // Each scoreLevel has it's own dataset and chartFile
   List<List<XYSeries>> seriesListList = new ArrayList<List<XYSeries>>(CHARTED_SCORE_LEVEL_SIZE);
   int solverBenchmarkIndex = 0;
   for (SolverBenchmarkResult solverBenchmarkResult :
       plannerBenchmarkResult.getSolverBenchmarkResultList()) {
     String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix();
     for (SingleBenchmarkResult singleBenchmarkResult :
         solverBenchmarkResult.getSingleBenchmarkResultList()) {
       if (singleBenchmarkResult.hasAllSuccess()) {
         long timeMillisSpent = singleBenchmarkResult.getTimeMillisSpent();
         double[] levelValues =
             ScoreUtils.extractLevelDoubles(singleBenchmarkResult.getAverageScore());
         for (int i = 0; i < levelValues.length && i < CHARTED_SCORE_LEVEL_SIZE; i++) {
           if (i >= seriesListList.size()) {
             seriesListList.add(
                 new ArrayList<XYSeries>(
                     plannerBenchmarkResult.getSolverBenchmarkResultList().size()));
           }
           List<XYSeries> seriesList = seriesListList.get(i);
           while (solverBenchmarkIndex >= seriesList.size()) {
             seriesList.add(new XYSeries(solverLabel));
           }
           seriesList
               .get(solverBenchmarkIndex)
               .add((Long) timeMillisSpent, (Double) levelValues[i]);
         }
       }
     }
     solverBenchmarkIndex++;
   }
   bestScorePerTimeSpentSummaryChartFileList = new ArrayList<File>(seriesListList.size());
   int scoreLevelIndex = 0;
   for (List<XYSeries> seriesList : seriesListList) {
     XYPlot plot =
         createScalabilityPlot(
             seriesList,
             "Time spent",
             new MillisecondsSpentNumberFormat(locale),
             "Score level " + scoreLevelIndex,
             NumberFormat.getInstance(locale));
     JFreeChart chart =
         new JFreeChart(
             "Best score per time spent level "
                 + scoreLevelIndex
                 + " summary (higher left is better)",
             JFreeChart.DEFAULT_TITLE_FONT,
             plot,
             true);
     bestScorePerTimeSpentSummaryChartFileList.add(
         writeChartToImageFile(chart, "bestScorePerTimeSpentSummaryLevel" + scoreLevelIndex));
     scoreLevelIndex++;
   }
 }
예제 #4
0
 private void determineDefaultShownScoreLevelIndex() {
   defaultShownScoreLevelIndex = Integer.MAX_VALUE;
   for (ProblemBenchmarkResult problemBenchmarkResult :
       plannerBenchmarkResult.getUnifiedProblemBenchmarkResultList()) {
     if (problemBenchmarkResult.hasAnySuccess()) {
       double[] winningScoreLevels =
           ScoreUtils.extractLevelDoubles(
               problemBenchmarkResult.getWinningSingleBenchmarkResult().getAverageScore());
       int[] differenceCount = new int[winningScoreLevels.length];
       for (int i = 0; i < differenceCount.length; i++) {
         differenceCount[i] = 0;
       }
       for (SingleBenchmarkResult singleBenchmarkResult :
           problemBenchmarkResult.getSingleBenchmarkResultList()) {
         if (singleBenchmarkResult.hasAllSuccess()) {
           double[] scoreLevels =
               ScoreUtils.extractLevelDoubles(singleBenchmarkResult.getAverageScore());
           for (int i = 0; i < scoreLevels.length; i++) {
             if (scoreLevels[i] != winningScoreLevels[i]) {
               differenceCount[i] = differenceCount[i] + 1;
             }
           }
         }
       }
       int firstInterestingLevel = differenceCount.length - 1;
       for (int i = 0; i < differenceCount.length; i++) {
         if (differenceCount[i] > 0) {
           firstInterestingLevel = i;
           break;
         }
       }
       if (defaultShownScoreLevelIndex > firstInterestingLevel) {
         defaultShownScoreLevelIndex = firstInterestingLevel;
       }
     }
   }
 }
예제 #5
0
 private void writeWinningScoreDifferenceSummaryChart() {
   // Each scoreLevel has it's own dataset and chartFile
   List<DefaultCategoryDataset> datasetList =
       new ArrayList<DefaultCategoryDataset>(CHARTED_SCORE_LEVEL_SIZE);
   for (SolverBenchmarkResult solverBenchmarkResult :
       plannerBenchmarkResult.getSolverBenchmarkResultList()) {
     String solverLabel = solverBenchmarkResult.getNameWithFavoriteSuffix();
     for (SingleBenchmarkResult singleBenchmarkResult :
         solverBenchmarkResult.getSingleBenchmarkResultList()) {
       String planningProblemLabel = singleBenchmarkResult.getProblemBenchmarkResult().getName();
       if (singleBenchmarkResult.hasAllSuccess()) {
         double[] levelValues =
             ScoreUtils.extractLevelDoubles(singleBenchmarkResult.getWinningScoreDifference());
         for (int i = 0; i < levelValues.length && i < CHARTED_SCORE_LEVEL_SIZE; i++) {
           if (i >= datasetList.size()) {
             datasetList.add(new DefaultCategoryDataset());
           }
           datasetList.get(i).addValue(levelValues[i], solverLabel, planningProblemLabel);
         }
       }
     }
   }
   winningScoreDifferenceSummaryChartFileList = new ArrayList<File>(datasetList.size());
   int scoreLevelIndex = 0;
   for (DefaultCategoryDataset dataset : datasetList) {
     CategoryPlot plot =
         createBarChartPlot(
             dataset,
             "Winning score difference level " + scoreLevelIndex,
             NumberFormat.getInstance(locale));
     JFreeChart chart =
         new JFreeChart(
             "Winning score difference level " + scoreLevelIndex + " summary (higher is better)",
             JFreeChart.DEFAULT_TITLE_FONT,
             plot,
             true);
     winningScoreDifferenceSummaryChartFileList.add(
         writeChartToImageFile(chart, "winningScoreDifferenceSummaryLevel" + scoreLevelIndex));
     scoreLevelIndex++;
   }
 }
예제 #6
0
 private List<? extends BoxAndWhiskerCategoryDataset> generateSubSingleBenchmarkScoreSummary(
     ProblemBenchmarkResult problemBenchmarkResult) {
   List<DefaultBoxAndWhiskerCategoryDataset> datasetList =
       new ArrayList<DefaultBoxAndWhiskerCategoryDataset>(CHARTED_SCORE_LEVEL_SIZE);
   for (SingleBenchmarkResult singleBenchmarkResult :
       problemBenchmarkResult.getSingleBenchmarkResultList()) {
     List<List<Double>> valueListList = new ArrayList<List<Double>>(CHARTED_SCORE_LEVEL_SIZE);
     for (SubSingleBenchmarkResult subSingleBenchmarkResult :
         singleBenchmarkResult.getSubSingleBenchmarkResultList()) {
       if (subSingleBenchmarkResult.hasAllSuccess() && subSingleBenchmarkResult.isInitialized()) {
         double[] levelValues =
             ScoreUtils.extractLevelDoubles(subSingleBenchmarkResult.getAverageScore());
         for (int i = 0; i < levelValues.length && i < CHARTED_SCORE_LEVEL_SIZE; i++) {
           if (i >= valueListList.size()) {
             valueListList.add(new ArrayList<Double>(singleBenchmarkResult.getSuccessCount()));
           }
           valueListList.get(i).add(levelValues[i]);
         }
       }
     }
     for (int i = 0; i < valueListList.size() && i < CHARTED_SCORE_LEVEL_SIZE; i++) {
       if (i >= datasetList.size()) {
         datasetList.add(new DefaultBoxAndWhiskerCategoryDataset());
       }
       SolverBenchmarkResult solverBenchmarkResult =
           singleBenchmarkResult.getSolverBenchmarkResult();
       datasetList
           .get(i)
           .add(
               valueListList.get(i),
               solverBenchmarkResult.getName(),
               solverBenchmarkResult
                   + " - "
                   + solverBenchmarkResult.getSubSingleCount()
                   + " run(s)");
     }
   }
   return datasetList;
 }
 @Override
 public void writeGraphFiles(BenchmarkReport benchmarkReport) {
   List<XYPlot> plotList = new ArrayList<XYPlot>(BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE);
   int seriesIndex = 0;
   for (SingleBenchmarkResult singleBenchmarkResult :
       problemBenchmarkResult.getSingleBenchmarkResultList()) {
     List<XYSeries> seriesList = new ArrayList<XYSeries>(BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE);
     // No direct ascending lines between 2 points, but a stepping line instead
     XYItemRenderer renderer = new XYStepRenderer();
     if (singleBenchmarkResult.isSuccess()) {
       BestScoreSingleStatistic singleStatistic =
           (BestScoreSingleStatistic)
               singleBenchmarkResult.getSingleStatistic(problemStatisticType);
       for (BestScoreStatisticPoint point : singleStatistic.getPointList()) {
         long timeMillisSpent = point.getTimeMillisSpent();
         double[] levelValues = ScoreUtils.extractLevelDoubles(point.getScore());
         for (int i = 0;
             i < levelValues.length && i < BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE;
             i++) {
           if (i >= seriesList.size()) {
             seriesList.add(
                 new XYSeries(
                     singleBenchmarkResult
                         .getSolverBenchmarkResult()
                         .getNameWithFavoriteSuffix()));
           }
           seriesList.get(i).add(timeMillisSpent, levelValues[i]);
         }
       }
       // TODO if startingSolution is initialized and no improvement is made, a horizontal line
       // should be shown
       // Draw a horizontal line from the last new best step to how long the solver actually ran
       long timeMillisSpent = singleBenchmarkResult.getTimeMillisSpent();
       double[] bestScoreLevels = ScoreUtils.extractLevelDoubles(singleBenchmarkResult.getScore());
       for (int i = 0;
           i < bestScoreLevels.length && i < BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE;
           i++) {
         if (i >= seriesList.size()) {
           seriesList.add(
               new XYSeries(
                   singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix()));
         }
         seriesList.get(i).add(timeMillisSpent, bestScoreLevels[i]);
       }
       if (singleStatistic.getPointList().size() <= 1) {
         // Workaround for
         // https://sourceforge.net/tracker/?func=detail&aid=3387330&group_id=15494&atid=115494
         renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
       }
     }
     if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) {
       // Make the favorite more obvious
       renderer.setSeriesStroke(0, new BasicStroke(2.0f));
     }
     for (int i = 0; i < seriesList.size(); i++) {
       if (i >= plotList.size()) {
         plotList.add(createPlot(benchmarkReport, i));
       }
       plotList.get(i).setDataset(seriesIndex, new XYSeriesCollection(seriesList.get(i)));
       plotList.get(i).setRenderer(seriesIndex, renderer);
     }
     seriesIndex++;
   }
   graphFileList = new ArrayList<File>(plotList.size());
   for (int scoreLevelIndex = 0; scoreLevelIndex < plotList.size(); scoreLevelIndex++) {
     JFreeChart chart =
         new JFreeChart(
             problemBenchmarkResult.getName()
                 + " best score level "
                 + scoreLevelIndex
                 + " statistic",
             JFreeChart.DEFAULT_TITLE_FONT,
             plotList.get(scoreLevelIndex),
             true);
     graphFileList.add(
         writeChartToImageFile(
             chart,
             problemBenchmarkResult.getName() + "BestScoreStatisticLevel" + scoreLevelIndex));
   }
 }
예제 #8
0
 public String getBestScoreWithUninitializedPrefix() {
   return ScoreUtils.getScoreWithUninitializedPrefix(bestUninitializedVariableCount, bestScore);
 }