}
/*
* plot search progress of different algorithms
*/
final XYLineChartBuilder chartBuilder = XYLineChartBuilder.newInstance("alpha-sensitivity", "iterations", "costs");
computationalLab.addListener(new CalculationListener() {
@Override
public void calculationStarts(BenchmarkInstance p, final String algorithmName,VehicleRoutingAlgorithm algorithm, int run) {
algorithm.addListener(new IterationStartsListener() {
@Override
public void informIterationStarts(int i, VehicleRoutingProblem problem,Collection<VehicleRoutingProblemSolution> solutions) {
/*
* plot only distance-costs, i.e. without fixed costs
*/
VehicleRoutingProblemSolution bestOf = Solutions.bestOf(solutions);
chartBuilder.addData(algorithmName, i, bestOf.getCost()-bestOf.getRoutes().size()*100.);
}
});
}
@Override
public void calculationEnds(BenchmarkInstance p, String algorithmName,VehicleRoutingAlgorithm algorithm, int run,Collection<VehicleRoutingProblemSolution> solutions) {}
});
/*
* define dataCollector to collect an arbitrary number of indicators as well as solutions
*/
final DataCollector dataCollector = new DataCollector();
computationalLab.addListener(new CalculationListener() {
@Override
public void calculationStarts(BenchmarkInstance p, String algorithmName,VehicleRoutingAlgorithm algorithm, int run) {}
@Override
public void calculationEnds(BenchmarkInstance p, String algorithmName,VehicleRoutingAlgorithm algorithm, int run,Collection<VehicleRoutingProblemSolution> solutions) {
//memorize solution
dataCollector.addSolution(p.name, algorithmName, run, Solutions.bestOf(solutions));
}
});
/*
* determine number of threads to be used
*/
computationalLab.setThreads(2);
/*
* run the experiments
*/
computationalLab.run();
/*
* plot the lineChart
*/
XYLineChartBuilder.saveChartAsPNG(chartBuilder.build(), "output/computationalStudies_alphaSensitivity.png");
/*
* print best solution
*/
SolutionPrinter.print(vrp, Solutions.bestOf(dataCollector.getSolutions()), Print.VERBOSE);