Skip to content

Commit

Permalink
PLANNER-401: Moved SubSingleStats from BenchmarkReport to SubSingleBR
Browse files Browse the repository at this point in the history
  • Loading branch information
oskopek committed Sep 23, 2015
1 parent 5a9041a commit 9270144
Show file tree
Hide file tree
Showing 23 changed files with 96 additions and 96 deletions.
Expand Up @@ -17,8 +17,8 @@
package org.optaplanner.benchmark.config.statistic;

import org.optaplanner.benchmark.impl.report.ReportHelper;
import org.optaplanner.benchmark.impl.result.SubSingleBenchmarkResult;
import org.optaplanner.benchmark.impl.statistic.PureSubSingleStatistic;
import org.optaplanner.benchmark.impl.result.BenchmarkResult;
import org.optaplanner.benchmark.impl.statistic.StatisticType;
import org.optaplanner.benchmark.impl.statistic.subsingle.constraintmatchtotalbestscore.ConstraintMatchTotalBestScoreSubSingleStatistic;
import org.optaplanner.benchmark.impl.statistic.subsingle.constraintmatchtotalstepscore.ConstraintMatchTotalStepScoreSubSingleStatistic;
Expand All @@ -31,17 +31,17 @@ public enum SubSingleStatisticType implements StatisticType {
PICKED_MOVE_TYPE_BEST_SCORE_DIFF,
PICKED_MOVE_TYPE_STEP_SCORE_DIFF;

public PureSubSingleStatistic buildPureSubSingleStatistic(BenchmarkResult benchmarkResult) {
public PureSubSingleStatistic buildPureSubSingleStatistic(SubSingleBenchmarkResult subSingleBenchmarkResult) {
// Keep in sync with ProblemStatistic XStreamInclude list
switch (this) {
case CONSTRAINT_MATCH_TOTAL_BEST_SCORE:
return new ConstraintMatchTotalBestScoreSubSingleStatistic(benchmarkResult);
return new ConstraintMatchTotalBestScoreSubSingleStatistic(subSingleBenchmarkResult);
case CONSTRAINT_MATCH_TOTAL_STEP_SCORE:
return new ConstraintMatchTotalStepScoreSubSingleStatistic(benchmarkResult);
return new ConstraintMatchTotalStepScoreSubSingleStatistic(subSingleBenchmarkResult);
case PICKED_MOVE_TYPE_BEST_SCORE_DIFF:
return new PickedMoveTypeBestScoreDiffSubSingleStatistic(benchmarkResult);
return new PickedMoveTypeBestScoreDiffSubSingleStatistic(subSingleBenchmarkResult);
case PICKED_MOVE_TYPE_STEP_SCORE_DIFF:
return new PickedMoveTypeStepScoreDiffSubSingleStatistic(benchmarkResult);
return new PickedMoveTypeStepScoreDiffSubSingleStatistic(subSingleBenchmarkResult);
default:
throw new IllegalStateException("The subSingleStatisticType (" + this + ") is not implemented.");
}
Expand Down
Expand Up @@ -146,7 +146,7 @@ private void restoreOmittedBidirectionalFields(PlannerBenchmarkResult plannerBen
}
for (SubSingleBenchmarkResult subSingleBenchmarkResult : singleBenchmarkResult.getSubSingleBenchmarkResultList()) {
for (PureSubSingleStatistic pureSubSingleStatistic : subSingleBenchmarkResult.getPureSubSingleStatisticList()) {
pureSubSingleStatistic.setBenchmarkResult(subSingleBenchmarkResult);
pureSubSingleStatistic.setSubSingleBenchmarkResult(subSingleBenchmarkResult);
}
}
}
Expand Down
Expand Up @@ -17,15 +17,15 @@
package org.optaplanner.benchmark.impl.statistic;

import org.optaplanner.benchmark.config.statistic.ProblemStatisticType;
import org.optaplanner.benchmark.impl.result.BenchmarkResult;
import org.optaplanner.benchmark.impl.result.SubSingleBenchmarkResult;

public abstract class ProblemBasedSubSingleStatistic<P extends StatisticPoint> extends SubSingleStatistic<P> {

protected final ProblemStatisticType problemStatisticType;

protected ProblemBasedSubSingleStatistic(BenchmarkResult benchmarkResult,
protected ProblemBasedSubSingleStatistic(SubSingleBenchmarkResult subSingleBenchmarkResult,
ProblemStatisticType problemStatisticType) {
super(benchmarkResult);
super(subSingleBenchmarkResult);
this.problemStatisticType = problemStatisticType;
}

Expand All @@ -36,7 +36,7 @@ public ProblemStatisticType getStatisticType() {

@Override
public String toString() {
return benchmarkResult + "_" + problemStatisticType;
return subSingleBenchmarkResult + "_" + problemStatisticType;
}

}
Expand Up @@ -28,7 +28,7 @@
import org.optaplanner.benchmark.impl.report.ReportHelper;
import org.optaplanner.benchmark.impl.result.ProblemBenchmarkResult;
import org.optaplanner.benchmark.impl.result.SingleBenchmarkResult;
import org.optaplanner.benchmark.impl.result.BenchmarkResult;
import org.optaplanner.benchmark.impl.result.SubSingleBenchmarkResult;
import org.optaplanner.benchmark.impl.statistic.bestscore.BestScoreProblemStatistic;
import org.optaplanner.benchmark.impl.statistic.bestsolutionmutation.BestSolutionMutationProblemStatistic;
import org.optaplanner.benchmark.impl.statistic.calculatecount.CalculateCountProblemStatistic;
Expand Down Expand Up @@ -103,7 +103,7 @@ public List<SubSingleStatistic> getSubSingleStatisticList() {
return subSingleStatisticList;
}

public abstract SubSingleStatistic createSubSingleStatistic(BenchmarkResult benchmarkResult);
public abstract SubSingleStatistic createSubSingleStatistic(SubSingleBenchmarkResult subSingleBenchmarkResult);

// ************************************************************************
// Write methods
Expand Down
Expand Up @@ -23,7 +23,7 @@
import org.jfree.chart.JFreeChart;
import org.optaplanner.benchmark.config.statistic.SubSingleStatisticType;
import org.optaplanner.benchmark.impl.report.BenchmarkReport;
import org.optaplanner.benchmark.impl.result.BenchmarkResult;
import org.optaplanner.benchmark.impl.result.SubSingleBenchmarkResult;
import org.optaplanner.benchmark.impl.statistic.common.GraphSupport;
import org.optaplanner.benchmark.impl.statistic.subsingle.constraintmatchtotalbestscore.ConstraintMatchTotalBestScoreSubSingleStatistic;
import org.optaplanner.benchmark.impl.statistic.subsingle.constraintmatchtotalstepscore.ConstraintMatchTotalStepScoreSubSingleStatistic;
Expand All @@ -43,8 +43,8 @@ public abstract class PureSubSingleStatistic<P extends StatisticPoint> extends S

protected final SubSingleStatisticType subSingleStatisticType;

protected PureSubSingleStatistic(BenchmarkResult benchmarkResult, SubSingleStatisticType subSingleStatisticType) {
super(benchmarkResult);
protected PureSubSingleStatistic(SubSingleBenchmarkResult subSingleBenchmarkResult, SubSingleStatisticType subSingleStatisticType) {
super(subSingleBenchmarkResult);
this.subSingleStatisticType = subSingleStatisticType;
}

Expand All @@ -60,7 +60,7 @@ public SubSingleStatisticType getStatisticType() {
public abstract void writeGraphFiles(BenchmarkReport benchmarkReport);

protected File writeChartToImageFile(JFreeChart chart, String fileNameBase) {
File chartFile = new File(benchmarkResult.getResultDirectory(), fileNameBase + ".png");
File chartFile = new File(subSingleBenchmarkResult.getResultDirectory(), fileNameBase + ".png");
GraphSupport.writeChartToImageFile(chart, chartFile);
return chartFile;
}
Expand All @@ -82,7 +82,7 @@ public File getGraphFile() {

@Override
public String toString() {
return benchmarkResult + "_" + subSingleStatisticType;
return subSingleBenchmarkResult + "_" + subSingleStatisticType;
}

}
Expand Up @@ -30,7 +30,7 @@ public class StatisticUtils {
* @return standard deviation double values
*/
public static double[] determineStandardDeviationDoubles(
List<? extends BenchmarkResult> solverProblemBenchmarkResultList, Score averageScore, int successCount) {
List<? extends BenchmarkResult> benchmarkResultList, Score averageScore, int successCount) {
if (successCount <= 0) {
return null;
}
Expand All @@ -39,7 +39,7 @@ public static double[] determineStandardDeviationDoubles(
}
// averageScore can no longer be null
double[] differenceSquaredTotalDoubles = null;
for (BenchmarkResult benchmarkResult : solverProblemBenchmarkResultList) {
for (BenchmarkResult benchmarkResult : benchmarkResultList) {
if (benchmarkResult.hasAnySuccess()) {
Score difference = benchmarkResult.getAverageScore().subtract(averageScore);
// Calculations done on doubles to avoid common overflow when executing with an int score > 500 000
Expand Down
Expand Up @@ -35,14 +35,14 @@
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import org.apache.commons.io.IOUtils;
import org.optaplanner.benchmark.impl.report.ReportHelper;
import org.optaplanner.benchmark.impl.result.BenchmarkResult;
import org.optaplanner.benchmark.impl.result.SubSingleBenchmarkResult;
import org.optaplanner.core.api.solver.Solver;
import org.optaplanner.core.impl.score.definition.ScoreDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* 1 statistic of {@link SubSingleBenchmarkResult}.
* 1 statistic of {@link SubSinglesubSingleBenchmarkResult}.
*/
@XStreamInclude({
PureSubSingleStatistic.class
Expand All @@ -51,22 +51,22 @@ public abstract class SubSingleStatistic<P extends StatisticPoint> {

protected final transient Logger logger = LoggerFactory.getLogger(getClass());

@XStreamOmitField // Bi-directional relationship restored through BenchmarkResultIO
protected BenchmarkResult benchmarkResult;
@XStreamOmitField // Bi-directional relationship restored through subSingleBenchmarkResultIO
protected SubSingleBenchmarkResult subSingleBenchmarkResult;

@XStreamOmitField
protected List<P> pointList;

protected SubSingleStatistic(BenchmarkResult benchmarkResult) {
this.benchmarkResult = benchmarkResult;
protected SubSingleStatistic(SubSingleBenchmarkResult subSingleBenchmarkResult) {
this.subSingleBenchmarkResult = subSingleBenchmarkResult;
}

public BenchmarkResult getBenchmarkResult() {
return benchmarkResult;
public SubSingleBenchmarkResult getSubSingleBenchmarkResult() {
return subSingleBenchmarkResult;
}

public void setBenchmarkResult(BenchmarkResult benchmarkResult) {
this.benchmarkResult = benchmarkResult;
public void setSubSingleBenchmarkResult(SubSingleBenchmarkResult subSingleBenchmarkResult) {
this.subSingleBenchmarkResult = subSingleBenchmarkResult;
}

public abstract StatisticType getStatisticType();
Expand All @@ -83,9 +83,9 @@ public void setPointList(List<P> pointList) {
* @return the path to the csv file from report root
*/
public String getRelativeCsvFilePath() {
return new StringBuilder().append(benchmarkResult.getProblemBenchmarkResult().getProblemReportDirectoryPath())
return new StringBuilder().append(subSingleBenchmarkResult.getSingleBenchmarkResult().getProblemBenchmarkResult().getProblemReportDirectoryPath())
.append(File.separator)
.append(benchmarkResult.getResultDirectoryPath())
.append(subSingleBenchmarkResult.getResultDirectoryPath())
.append(File.separator)
.append(getCsvFilePath())
.toString();
Expand All @@ -96,7 +96,7 @@ public String getCsvFilePath() {
}

public File getCsvFile() {
return new File(benchmarkResult.getResultDirectory(), getCsvFilePath());
return new File(subSingleBenchmarkResult.getResultDirectory(), getCsvFilePath());
}

// ************************************************************************
Expand Down Expand Up @@ -126,7 +126,7 @@ private void writeCsvStatisticFile() {
for (StatisticPoint point : getPointList()) {
writer.append(point.toCsvLine()).append("\n");
}
if (benchmarkResult.hasAnyFailure()) {
if (subSingleBenchmarkResult.hasAnyFailure()) {
writer.append("Failed\n");
}
} catch (IOException e) {
Expand All @@ -138,13 +138,13 @@ private void writeCsvStatisticFile() {

private void readCsvStatisticFile() {
File csvFile = getCsvFile();
ScoreDefinition scoreDefinition = benchmarkResult.getSolverBenchmarkResult().getSolverConfig()
ScoreDefinition scoreDefinition = subSingleBenchmarkResult.getSingleBenchmarkResult().getSolverBenchmarkResult().getSolverConfig()
.getScoreDirectorFactoryConfig().buildScoreDefinition();
if (!pointList.isEmpty()) {
throw new IllegalStateException("The pointList with size (" + pointList.size() + ") should be empty.");
}
if (!csvFile.exists()) {
if (benchmarkResult.hasAnyFailure()) {
if (subSingleBenchmarkResult.hasAnyFailure()) {
pointList = Collections.emptyList();
return;
} else {
Expand All @@ -163,11 +163,11 @@ private void readCsvStatisticFile() {
Map<String, String> stringDuplicationRemovalMap = new HashMap<String, String>(1024);
for (line = reader.readLine(); line != null && !line.isEmpty(); line = reader.readLine()) {
if (line.equals("Failed")) {
if (benchmarkResult.hasAnyFailure()) {
if (subSingleBenchmarkResult.hasAnyFailure()) {
continue;
}
throw new IllegalStateException("SubSingleStatistic ( " + this + " ) failed even though the "
+ "corresponding SingleBenchmarkResult ( " + benchmarkResult + " ) is a success.");
+ "corresponding SinglesubSingleBenchmarkResult ( " + subSingleBenchmarkResult + " ) is a success.");
}
List<String> csvLine = StatisticPoint.parseCsvLine(line);
// HACK
Expand Down Expand Up @@ -200,10 +200,10 @@ private void readCsvStatisticFile() {
public void unhibernatePointList() {
if (!getCsvFile().exists()) {
throw new IllegalStateException("The csvFile ( " + getCsvFile() + " ) of the statistic ( " + getStatisticType()
+ " ) of the single benchmark ( " + benchmarkResult + " ) doesn't exist.");
+ " ) of the single benchmark ( " + subSingleBenchmarkResult + " ) doesn't exist.");
} else if (pointList != null) {
throw new IllegalStateException("The pointList ( " + pointList + " ) of the statistic ( " + getStatisticType()
+ " ) of the single benchmark ( " + benchmarkResult + " ) should be null when unhibernating.");
+ " ) of the single benchmark ( " + subSingleBenchmarkResult + " ) should be null when unhibernating.");
}
initPointList();
readCsvStatisticFile();
Expand All @@ -221,7 +221,7 @@ public void hibernatePointList() {
// ************************************************************************

public String getAnchorId() {
return ReportHelper.escapeHtmlId(benchmarkResult.getName() + "_" + getStatisticType().name());
return ReportHelper.escapeHtmlId(subSingleBenchmarkResult.getName() + "_" + getStatisticType().name());
}

}
Expand Up @@ -37,9 +37,9 @@
import org.optaplanner.benchmark.impl.report.BenchmarkReport;
import org.optaplanner.benchmark.impl.result.ProblemBenchmarkResult;
import org.optaplanner.benchmark.impl.result.SingleBenchmarkResult;
import org.optaplanner.benchmark.impl.result.SubSingleBenchmarkResult;
import org.optaplanner.benchmark.impl.statistic.ProblemStatistic;
import org.optaplanner.benchmark.impl.statistic.SubSingleStatistic;
import org.optaplanner.benchmark.impl.result.BenchmarkResult;
import org.optaplanner.benchmark.impl.statistic.common.MillisecondsSpentNumberFormat;
import org.optaplanner.core.impl.score.ScoreUtils;

Expand All @@ -53,8 +53,8 @@ public BestScoreProblemStatistic(ProblemBenchmarkResult problemBenchmarkResult)
}

@Override
public SubSingleStatistic createSubSingleStatistic(BenchmarkResult benchmarkResult) {
return new BestScoreSubSingleStatistic(benchmarkResult);
public SubSingleStatistic createSubSingleStatistic(SubSingleBenchmarkResult subSingleBenchmarkResult) {
return new BestScoreSubSingleStatistic(subSingleBenchmarkResult);
}

/**
Expand Down
Expand Up @@ -19,8 +19,8 @@
import java.util.List;

import org.optaplanner.benchmark.config.statistic.ProblemStatisticType;
import org.optaplanner.benchmark.impl.result.SubSingleBenchmarkResult;
import org.optaplanner.benchmark.impl.statistic.ProblemBasedSubSingleStatistic;
import org.optaplanner.benchmark.impl.result.BenchmarkResult;
import org.optaplanner.core.api.domain.solution.Solution;
import org.optaplanner.core.api.solver.Solver;
import org.optaplanner.core.api.solver.event.BestSolutionChangedEvent;
Expand All @@ -31,8 +31,8 @@ public class BestScoreSubSingleStatistic extends ProblemBasedSubSingleStatistic<

private final BestScoreSubSingleStatisticListener listener;

public BestScoreSubSingleStatistic(BenchmarkResult benchmarkResult) {
super(benchmarkResult, ProblemStatisticType.BEST_SCORE);
public BestScoreSubSingleStatistic(SubSingleBenchmarkResult subSingleBenchmarkResult) {
super(subSingleBenchmarkResult, ProblemStatisticType.BEST_SCORE);
listener = new BestScoreSubSingleStatisticListener();
}

Expand Down
Expand Up @@ -36,9 +36,9 @@
import org.optaplanner.benchmark.impl.report.BenchmarkReport;
import org.optaplanner.benchmark.impl.result.ProblemBenchmarkResult;
import org.optaplanner.benchmark.impl.result.SingleBenchmarkResult;
import org.optaplanner.benchmark.impl.result.SubSingleBenchmarkResult;
import org.optaplanner.benchmark.impl.statistic.ProblemStatistic;
import org.optaplanner.benchmark.impl.statistic.SubSingleStatistic;
import org.optaplanner.benchmark.impl.result.BenchmarkResult;
import org.optaplanner.benchmark.impl.statistic.common.MillisecondsSpentNumberFormat;

@XStreamAlias("bestSolutionMutationProblemStatistic")
Expand All @@ -51,8 +51,8 @@ public BestSolutionMutationProblemStatistic(ProblemBenchmarkResult problemBenchm
}

@Override
public SubSingleStatistic createSubSingleStatistic(BenchmarkResult benchmarkResult) {
return new BestSolutionMutationSubSingleStatistic(benchmarkResult);
public SubSingleStatistic createSubSingleStatistic(SubSingleBenchmarkResult subSingleBenchmarkResult) {
return new BestSolutionMutationSubSingleStatistic(subSingleBenchmarkResult);
}

/**
Expand Down
Expand Up @@ -19,8 +19,8 @@
import java.util.List;

import org.optaplanner.benchmark.config.statistic.ProblemStatisticType;
import org.optaplanner.benchmark.impl.result.SubSingleBenchmarkResult;
import org.optaplanner.benchmark.impl.statistic.ProblemBasedSubSingleStatistic;
import org.optaplanner.benchmark.impl.result.BenchmarkResult;
import org.optaplanner.core.api.domain.solution.Solution;
import org.optaplanner.core.api.solver.Solver;
import org.optaplanner.core.api.solver.event.BestSolutionChangedEvent;
Expand All @@ -34,8 +34,8 @@ public class BestSolutionMutationSubSingleStatistic extends ProblemBasedSubSingl

private BestSolutionMutationSubSingleStatisticListener listener;

public BestSolutionMutationSubSingleStatistic(BenchmarkResult benchmarkResult) {
super(benchmarkResult, ProblemStatisticType.BEST_SOLUTION_MUTATION);
public BestSolutionMutationSubSingleStatistic(SubSingleBenchmarkResult subSingleBenchmarkResult) {
super(subSingleBenchmarkResult, ProblemStatisticType.BEST_SOLUTION_MUTATION);
listener = new BestSolutionMutationSubSingleStatisticListener();
}

Expand Down

0 comments on commit 9270144

Please sign in to comment.