Skip to content

Commit

Permalink
PLANNER-1394 Better error message than ArrayIndexOutOfBoundsException…
Browse files Browse the repository at this point in the history
… due to difference Bendable score levels in benchmarker
  • Loading branch information
ge0ffrey committed Jan 25, 2019
1 parent eaabfdc commit 7629910
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Expand Up @@ -239,6 +239,10 @@ public int getMaximumSubSingleCount() {

public String findScoreLevelLabel(int scoreLevel) {
String[] levelLabels = solverBenchmarkResultList.get(0).getScoreDefinition().getLevelLabels();
if (scoreLevel >= levelLabels.length) {
// Occurs when mixing multiple examples in the same benchmark run, such as GeneralOptaPlannerBenchmarkApp
return "Unknown-" + (scoreLevel - levelLabels.length);
}
return levelLabels[scoreLevel];
}

Expand Down
Expand Up @@ -43,8 +43,10 @@
import org.optaplanner.benchmark.impl.report.ReportHelper;
import org.optaplanner.benchmark.impl.statistic.ProblemStatistic;
import org.optaplanner.benchmark.impl.statistic.PureSubSingleStatistic;
import org.optaplanner.core.api.domain.solution.PlanningScore;
import org.optaplanner.core.api.solver.Solver;
import org.optaplanner.core.config.util.ConfigUtils;
import org.optaplanner.core.impl.score.definition.ScoreDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -196,7 +198,13 @@ public String getAnchorId() {
}

public String findScoreLevelLabel(int scoreLevel) {
String[] levelLabels = singleBenchmarkResultList.get(0).getSolverBenchmarkResult().getScoreDefinition().getLevelLabels();
ScoreDefinition scoreDefinition = singleBenchmarkResultList.get(0).getSolverBenchmarkResult().getScoreDefinition();
String[] levelLabels = scoreDefinition.getLevelLabels();
if (scoreLevel >= levelLabels.length) {
throw new IllegalArgumentException("The scoreLevel (" + scoreLevel
+ ") isn't lower than the scoreLevelsSize (" + scoreDefinition.getLevelsSize()
+ ") implied by the @" + PlanningScore.class.getSimpleName() + " on the planning solution class.");
}
return levelLabels[scoreLevel];
}

Expand Down

0 comments on commit 7629910

Please sign in to comment.