mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge branch 'restructureAPIinPreparationForV0.1.1'
Conflicts: CHANGELOG.md
This commit is contained in:
commit
a0ad012768
369 changed files with 75965 additions and 6728 deletions
|
|
@ -1,90 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package analysis;
|
||||
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.route.DefaultVehicleRouteCostCalculator;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
/**
|
||||
* Printer to print the details of a vehicle-routing-problem solution.
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
public class SolutionPrinter {
|
||||
|
||||
/**
|
||||
* Enum to indicate verbose-level.
|
||||
*
|
||||
* <p> Print.CONCISE and Print.VERBOSE are available.
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
public enum Print {
|
||||
|
||||
CONCISE,VERBOSE
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints costs and #vehicles to stdout (System.out.println).
|
||||
*
|
||||
* @param solution
|
||||
*/
|
||||
public static void print(VehicleRoutingProblemSolution solution){
|
||||
System.out.println("[costs="+solution.getCost() + "]");
|
||||
System.out.println("[#vehicles="+solution.getRoutes().size() + "]");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the details of the solution according to a print-level, i.e. Print.CONCISE or PRINT.VERBOSE.
|
||||
*
|
||||
* <p>CONCISE prints total-costs and #vehicles.
|
||||
* <p>VERBOSE prints the route-details additionally. If the DefaultVehicleRouteCostCalculator (which is the standard-calculator)
|
||||
* is used in VehicleRoute, then route-costs are differentiated further between transport, activity, vehicle, driver and other-costs.
|
||||
*
|
||||
* @param solution
|
||||
* @param level
|
||||
*
|
||||
* @deprecated is not going to work anymore
|
||||
*/
|
||||
@Deprecated
|
||||
public static void print(VehicleRoutingProblemSolution solution, Print level){
|
||||
if(level.equals(Print.CONCISE)){
|
||||
print(solution);
|
||||
}
|
||||
else{
|
||||
print(solution);
|
||||
System.out.println("routes");
|
||||
int routeCount = 1;
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
System.out.println("[route="+routeCount+"][departureTime="+route.getStart().getEndTime()+"[total=" + route.getCost() + "]");
|
||||
if(route.getVehicleRouteCostCalculator() instanceof DefaultVehicleRouteCostCalculator){
|
||||
DefaultVehicleRouteCostCalculator defaultCalc = (DefaultVehicleRouteCostCalculator) route.getVehicleRouteCostCalculator();
|
||||
System.out.println("[transport=" + defaultCalc.getTpCosts() + "][activity=" + defaultCalc.getActCosts() +
|
||||
"][vehicle=" + defaultCalc.getVehicleCosts() + "][driver=" + defaultCalc.getDriverCosts() + "][other=" + defaultCalc.getOther() + "]");
|
||||
}
|
||||
routeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package analysis;
|
||||
package jsprit.analysis.toolbox;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
|
@ -22,24 +22,24 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.listener.AlgorithmEndsListener;
|
||||
import jsprit.core.algorithm.listener.AlgorithmStartsListener;
|
||||
import jsprit.core.algorithm.listener.IterationEndsListener;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jfree.chart.ChartFactory;
|
||||
import org.jfree.chart.ChartUtilities;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.chart.axis.NumberAxis;
|
||||
import org.jfree.chart.axis.NumberTickUnit;
|
||||
import org.jfree.chart.plot.PlotOrientation;
|
||||
import org.jfree.chart.plot.XYPlot;
|
||||
import org.jfree.data.Range;
|
||||
import org.jfree.data.xy.XYSeries;
|
||||
import org.jfree.data.xy.XYSeriesCollection;
|
||||
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.algo.AlgorithmEndsListener;
|
||||
import basics.algo.AlgorithmStartsListener;
|
||||
import basics.algo.IterationEndsListener;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -77,6 +77,9 @@ public class AlgorithmSearchProgressChartListener implements IterationEndsListen
|
|||
public AlgorithmSearchProgressChartListener(String pngFileName) {
|
||||
super();
|
||||
this.filename = pngFileName;
|
||||
if(!this.filename.endsWith("png")){
|
||||
this.filename += ".png";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -118,8 +121,10 @@ public class AlgorithmSearchProgressChartListener implements IterationEndsListen
|
|||
XYPlot plot = chart.getXYPlot();
|
||||
|
||||
NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
|
||||
Range rangeY = new Range(minValue-0.05*minValue,maxValue + 0.05*maxValue);
|
||||
yAxis.setRange(rangeY);
|
||||
Range rangeBounds = coll.getRangeBounds(true);
|
||||
double upper = Math.min(rangeBounds.getUpperBound(), rangeBounds.getLowerBound()*5);
|
||||
if(upper == 0.0){ upper = 10000; }
|
||||
yAxis.setRangeWithMargins(rangeBounds.getLowerBound(),upper);
|
||||
|
||||
try {
|
||||
ChartUtilities.saveChartAsJPEG(new File(filename), chart, 1000, 600);
|
||||
|
|
@ -143,9 +148,9 @@ public class AlgorithmSearchProgressChartListener implements IterationEndsListen
|
|||
double best = Double.MAX_VALUE;
|
||||
double sum = 0.0;
|
||||
for(VehicleRoutingProblemSolution sol : solutions){
|
||||
if(sol.getCost() > worst) worst = sol.getCost();
|
||||
if(sol.getCost() > worst) worst = Math.min(sol.getCost(),Double.MAX_VALUE);
|
||||
if(sol.getCost() < best) best = sol.getCost();
|
||||
sum += sol.getCost();
|
||||
sum += Math.min(sol.getCost(),Double.MAX_VALUE);
|
||||
}
|
||||
bestResultList.add(best);
|
||||
worstResultList.add(worst);
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package analysis;
|
||||
package jsprit.analysis.toolbox;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -25,19 +25,21 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import jsprit.analysis.util.BenchmarkWriter;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithmFactory;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.Priority;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.util.BenchmarkInstance;
|
||||
import jsprit.core.util.BenchmarkResult;
|
||||
import jsprit.core.util.Solutions;
|
||||
|
||||
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.BenchmarkInstance;
|
||||
import util.BenchmarkResult;
|
||||
import util.BenchmarkWriter;
|
||||
import util.Solutions;
|
||||
import algorithms.VehicleRoutingAlgorithms;
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.algo.VehicleRoutingAlgorithmListeners.Priority;
|
||||
|
||||
public class ConcurrentBenchmarker {
|
||||
|
||||
|
|
@ -47,7 +49,7 @@ public class ConcurrentBenchmarker {
|
|||
|
||||
|
||||
|
||||
private String algorithmConfig;
|
||||
private String algorithmConfig = null;
|
||||
|
||||
private List<BenchmarkInstance> benchmarkInstances = new ArrayList<BenchmarkInstance>();
|
||||
|
||||
|
|
@ -65,6 +67,8 @@ public class ConcurrentBenchmarker {
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
private VehicleRoutingAlgorithmFactory algorithmFactory;
|
||||
|
||||
public void setCost(Cost cost){ this.cost = cost; }
|
||||
|
||||
|
|
@ -74,6 +78,10 @@ public class ConcurrentBenchmarker {
|
|||
Logger.getRootLogger().setLevel(Level.ERROR);
|
||||
}
|
||||
|
||||
public ConcurrentBenchmarker(VehicleRoutingAlgorithmFactory algorithmFactory){
|
||||
this.algorithmFactory = algorithmFactory;
|
||||
}
|
||||
|
||||
public void addBenchmarkWriter(BenchmarkWriter writer){
|
||||
writers.add(writer);
|
||||
}
|
||||
|
|
@ -94,6 +102,12 @@ public class ConcurrentBenchmarker {
|
|||
benchmarkInstances.add(new BenchmarkInstance(name,problem,bestKnownResult,bestKnownVehicles));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets nuOfRuns with same algorithm on same instance.
|
||||
* <p>Default is 1
|
||||
*
|
||||
* @param runs
|
||||
*/
|
||||
public void setNuOfRuns(int runs){
|
||||
this.runs = runs;
|
||||
}
|
||||
|
|
@ -142,11 +156,11 @@ public class ConcurrentBenchmarker {
|
|||
double[] times = new double[runs];
|
||||
|
||||
for(int run=0;run<runs;run++){
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(p.vrp, algorithmConfig);
|
||||
VehicleRoutingAlgorithm vra = createAlgorithm(p);
|
||||
StopWatch stopwatch = new StopWatch();
|
||||
vra.getAlgorithmListeners().addListener(stopwatch,Priority.HIGH);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
VehicleRoutingProblemSolution best = Solutions.getBest(solutions);
|
||||
VehicleRoutingProblemSolution best = Solutions.bestOf(solutions);
|
||||
vehicles[run] = best.getRoutes().size();
|
||||
results[run] = cost.getCost(best);
|
||||
times[run] = stopwatch.getCompTimeInSeconds();
|
||||
|
|
@ -155,6 +169,16 @@ public class ConcurrentBenchmarker {
|
|||
return new BenchmarkResult(p, runs, results, times, vehicles);
|
||||
}
|
||||
|
||||
private VehicleRoutingAlgorithm createAlgorithm(BenchmarkInstance p) {
|
||||
if(algorithmConfig != null){
|
||||
return VehicleRoutingAlgorithms.readAndCreateAlgorithm(p.vrp, algorithmConfig);
|
||||
}
|
||||
else{
|
||||
return algorithmFactory.createAlgorithm(p.vrp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void print(Collection<BenchmarkResult> results) {
|
||||
double sumTime=0.0;
|
||||
double sumResult=0.0;
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package analysis;
|
||||
package jsprit.analysis.toolbox;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
|
|
@ -23,35 +23,39 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.Locations;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jfree.chart.ChartUtilities;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.chart.LegendItemCollection;
|
||||
import org.jfree.chart.LegendItemSource;
|
||||
import org.jfree.chart.annotations.XYShapeAnnotation;
|
||||
import org.jfree.chart.axis.NumberAxis;
|
||||
import org.jfree.chart.labels.XYItemLabelGenerator;
|
||||
import org.jfree.chart.plot.XYPlot;
|
||||
import org.jfree.chart.renderer.xy.XYItemRenderer;
|
||||
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
|
||||
import org.jfree.chart.title.LegendTitle;
|
||||
import org.jfree.data.xy.XYDataItem;
|
||||
import org.jfree.data.xy.XYDataset;
|
||||
import org.jfree.data.xy.XYSeries;
|
||||
import org.jfree.data.xy.XYSeriesCollection;
|
||||
import org.jfree.ui.RectangleEdge;
|
||||
|
||||
import util.Coordinate;
|
||||
import util.Locations;
|
||||
import basics.Delivery;
|
||||
import basics.Job;
|
||||
import basics.Pickup;
|
||||
import basics.Service;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
public class Plotter {
|
||||
|
||||
|
|
@ -77,9 +81,11 @@ public class Plotter {
|
|||
|
||||
private VehicleRoutingProblem vrp;
|
||||
|
||||
private VehicleRoutingProblemSolution solution;
|
||||
|
||||
private boolean plotSolutionAsWell = false;
|
||||
|
||||
private boolean plotShipments = true;
|
||||
|
||||
private Collection<VehicleRoute> routes;
|
||||
|
||||
public void setShowFirstActivity(boolean show){
|
||||
showFirstActivity = show;
|
||||
|
|
@ -97,53 +103,102 @@ public class Plotter {
|
|||
public Plotter(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution) {
|
||||
super();
|
||||
this.vrp = vrp;
|
||||
this.solution = solution;
|
||||
this.routes = solution.getRoutes();
|
||||
plotSolutionAsWell = true;
|
||||
}
|
||||
|
||||
public Plotter(VehicleRoutingProblem vrp, Collection<VehicleRoute> routes) {
|
||||
super();
|
||||
this.vrp = vrp;
|
||||
this.routes = routes;
|
||||
plotSolutionAsWell = true;
|
||||
}
|
||||
|
||||
public void plot(String pngFileName, String plotTitle){
|
||||
String filename = pngFileName;
|
||||
if(!pngFileName.endsWith(".png")) filename += ".png";
|
||||
if(plotSolutionAsWell){
|
||||
plotSolutionAsPNG(vrp, solution, pngFileName, plotTitle);
|
||||
plotSolutionAsPNG(vrp, routes, filename, plotTitle);
|
||||
}
|
||||
else{
|
||||
plotVrpAsPNG(vrp, pngFileName, plotTitle);
|
||||
plotVrpAsPNG(vrp, filename, plotTitle);
|
||||
}
|
||||
}
|
||||
|
||||
private void plotVrpAsPNG(VehicleRoutingProblem vrp, String pngFile, String title){
|
||||
log.info("plot routes to " + pngFile);
|
||||
XYSeriesCollection problem;
|
||||
final XYSeriesCollection shipments;
|
||||
Map<XYDataItem,String> labels = new HashMap<XYDataItem, String>();
|
||||
try {
|
||||
problem = makeVrpSeries(vrp, labels);
|
||||
shipments = makeShipmentSeries(vrp.getJobs().values(), null);
|
||||
} catch (NoLocationFoundException e) {
|
||||
log.warn("cannot plot vrp, since coord is missing");
|
||||
return;
|
||||
}
|
||||
XYPlot plot = createPlot(problem, labels);
|
||||
final XYPlot plot = createProblemPlot(problem, shipments, labels);
|
||||
LegendItemSource lis = new LegendItemSource() {
|
||||
|
||||
@Override
|
||||
public LegendItemCollection getLegendItems() {
|
||||
LegendItemCollection lic = new LegendItemCollection();
|
||||
lic.addAll(plot.getRenderer(0).getLegendItems());
|
||||
if(!shipments.getSeries().isEmpty()){
|
||||
lic.add(plot.getRenderer(1).getLegendItem(1, 0));
|
||||
}
|
||||
return lic;
|
||||
}
|
||||
};
|
||||
|
||||
JFreeChart chart = new JFreeChart(title, plot);
|
||||
chart.removeLegend();
|
||||
LegendTitle legend = new LegendTitle(lis);
|
||||
legend.setPosition(RectangleEdge.BOTTOM);
|
||||
chart.addLegend(legend);
|
||||
save(chart,pngFile);
|
||||
}
|
||||
|
||||
private void plotSolutionAsPNG(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution, String pngFile, String title){
|
||||
private void plotSolutionAsPNG(VehicleRoutingProblem vrp, Collection<VehicleRoute> routes, String pngFile, String title){
|
||||
log.info("plot solution to " + pngFile);
|
||||
XYSeriesCollection problem;
|
||||
XYSeriesCollection solutionColl;
|
||||
final XYSeriesCollection shipments;
|
||||
Map<XYDataItem,String> labels = new HashMap<XYDataItem, String>();
|
||||
try {
|
||||
problem = makeVrpSeries(vrp, labels);
|
||||
solutionColl = makeSolutionSeries(vrp, solution);
|
||||
shipments = makeShipmentSeries(vrp.getJobs().values(), null);
|
||||
solutionColl = makeSolutionSeries(vrp, routes);
|
||||
} catch (NoLocationFoundException e) {
|
||||
log.warn("cannot plot vrp, since coord is missing");
|
||||
return;
|
||||
}
|
||||
XYPlot plot = createPlot(problem, solutionColl, labels);
|
||||
final XYPlot plot = createProblemSolutionPlot(problem, shipments, solutionColl, labels);
|
||||
JFreeChart chart = new JFreeChart(title, plot);
|
||||
LegendItemSource lis = new LegendItemSource() {
|
||||
|
||||
@Override
|
||||
public LegendItemCollection getLegendItems() {
|
||||
LegendItemCollection lic = new LegendItemCollection();
|
||||
lic.addAll(plot.getRenderer(0).getLegendItems());
|
||||
lic.addAll(plot.getRenderer(2).getLegendItems());
|
||||
if(!shipments.getSeries().isEmpty()){
|
||||
lic.add(plot.getRenderer(1).getLegendItem(1, 0));
|
||||
}
|
||||
return lic;
|
||||
}
|
||||
};
|
||||
|
||||
chart.removeLegend();
|
||||
LegendTitle legend = new LegendTitle(lis);
|
||||
legend.setPosition(RectangleEdge.BOTTOM);
|
||||
chart.addLegend(legend);
|
||||
|
||||
save(chart,pngFile);
|
||||
|
||||
}
|
||||
|
||||
private static XYPlot createPlot(final XYSeriesCollection problem, final Map<XYDataItem, String> labels) {
|
||||
private static XYPlot createProblemPlot(final XYSeriesCollection problem, XYSeriesCollection shipments, final Map<XYDataItem, String> labels) {
|
||||
XYPlot plot = new XYPlot();
|
||||
plot.setBackgroundPaint(Color.LIGHT_GRAY);
|
||||
plot.setRangeGridlinePaint(Color.WHITE);
|
||||
|
|
@ -172,10 +227,25 @@ public class Plotter {
|
|||
plot.setDomainAxis(0, xAxis);
|
||||
plot.setRangeAxis(0, yAxis);
|
||||
|
||||
XYItemRenderer shipmentsRenderer = new XYLineAndShapeRenderer(true, false); // Shapes only
|
||||
for(int i=0;i<shipments.getSeriesCount();i++){
|
||||
shipmentsRenderer.setSeriesPaint(i, Color.BLUE);
|
||||
shipmentsRenderer.setSeriesStroke(i, new BasicStroke(
|
||||
1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
|
||||
1.0f, new float[] {6.0f, 6.0f}, 0.0f
|
||||
));
|
||||
}
|
||||
// shipmentsRenderer.getLegendItems().
|
||||
plot.setDataset(1, shipments);
|
||||
plot.setRenderer(1, shipmentsRenderer);
|
||||
// plot.setDomainAxis(1, xAxis);
|
||||
// plot.setRangeAxis(1, yAxis);
|
||||
|
||||
// plot.addl
|
||||
return plot;
|
||||
}
|
||||
|
||||
private XYPlot createPlot(final XYSeriesCollection problem, XYSeriesCollection solutionColl, final Map<XYDataItem, String> labels) {
|
||||
private XYPlot createProblemSolutionPlot(final XYSeriesCollection problem, XYSeriesCollection shipments, XYSeriesCollection solutionColl, final Map<XYDataItem, String> labels) {
|
||||
XYPlot plot = new XYPlot();
|
||||
plot.setBackgroundPaint(Color.LIGHT_GRAY);
|
||||
plot.setRangeGridlinePaint(Color.WHITE);
|
||||
|
|
@ -193,7 +263,6 @@ public class Plotter {
|
|||
problemRenderer.setBaseItemLabelsVisible(true);
|
||||
problemRenderer.setBaseItemLabelPaint(Color.BLACK);
|
||||
|
||||
|
||||
NumberAxis xAxis = new NumberAxis();
|
||||
xAxis.setRangeWithMargins(problem.getDomainBounds(true));
|
||||
|
||||
|
|
@ -204,7 +273,21 @@ public class Plotter {
|
|||
plot.setRenderer(0, problemRenderer);
|
||||
plot.setDomainAxis(0, xAxis);
|
||||
plot.setRangeAxis(0, yAxis);
|
||||
// plot.mapDatasetToDomainAxis(0, 0);
|
||||
|
||||
|
||||
XYItemRenderer shipmentsRenderer = new XYLineAndShapeRenderer(true, false); // Shapes only
|
||||
for(int i=0;i<shipments.getSeriesCount();i++){
|
||||
shipmentsRenderer.setSeriesPaint(i, Color.BLUE);
|
||||
shipmentsRenderer.setSeriesStroke(i, new BasicStroke(
|
||||
1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
|
||||
1.0f, new float[] {6.0f, 6.0f}, 0.0f
|
||||
));
|
||||
}
|
||||
plot.setDataset(1, shipments);
|
||||
plot.setRenderer(1, shipmentsRenderer);
|
||||
// plot.setDomainAxis(1, xAxis);
|
||||
// plot.setRangeAxis(1, yAxis);
|
||||
|
||||
XYItemRenderer solutionRenderer = new XYLineAndShapeRenderer(true, false); // Lines only
|
||||
if(showFirstActivity){
|
||||
|
|
@ -214,10 +297,10 @@ public class Plotter {
|
|||
solutionRenderer.addAnnotation(new XYShapeAnnotation( new Ellipse2D.Double(firstCustomer.getXValue()-0.7, firstCustomer.getYValue()-0.7, 1.5, 1.5), new BasicStroke(1.0f), Color.RED));
|
||||
}
|
||||
}
|
||||
plot.setDataset(1, solutionColl);
|
||||
plot.setRenderer(1, solutionRenderer);
|
||||
plot.setDomainAxis(1, xAxis);
|
||||
plot.setRangeAxis(1, yAxis);
|
||||
plot.setDataset(2, solutionColl);
|
||||
plot.setRenderer(2, solutionRenderer);
|
||||
// plot.setDomainAxis(2, xAxis);
|
||||
// plot.setRangeAxis(2, yAxis);
|
||||
|
||||
return plot;
|
||||
}
|
||||
|
|
@ -232,32 +315,8 @@ public class Plotter {
|
|||
}
|
||||
}
|
||||
|
||||
private XYSeriesCollection makeSolutionSeries(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution) throws NoLocationFoundException{
|
||||
private XYSeriesCollection makeSolutionSeries(VehicleRoutingProblem vrp, Collection<VehicleRoute> routes) throws NoLocationFoundException{
|
||||
Locations locations = retrieveLocations(vrp);
|
||||
XYSeriesCollection coll = new XYSeriesCollection();
|
||||
int counter = 1;
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
if(route.isEmpty()) continue;
|
||||
XYSeries series = new XYSeries(counter, false, true);
|
||||
|
||||
Coordinate startCoord = locations.getCoord(route.getStart().getLocationId());
|
||||
series.add(startCoord.getX(), startCoord.getY());
|
||||
|
||||
for(TourActivity act : route.getTourActivities().getActivities()){
|
||||
Coordinate coord = locations.getCoord(act.getLocationId());
|
||||
series.add(coord.getX(), coord.getY());
|
||||
}
|
||||
|
||||
Coordinate endCoord = locations.getCoord(route.getEnd().getLocationId());
|
||||
series.add(endCoord.getX(), endCoord.getY());
|
||||
|
||||
coll.addSeries(series);
|
||||
counter++;
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
|
||||
private XYSeriesCollection makeSolutionSeries(Collection<VehicleRoute> routes, Locations locations){
|
||||
XYSeriesCollection coll = new XYSeriesCollection();
|
||||
int counter = 1;
|
||||
for(VehicleRoute route : routes){
|
||||
|
|
@ -281,7 +340,34 @@ public class Plotter {
|
|||
return coll;
|
||||
}
|
||||
|
||||
private XYSeriesCollection makeVrpSeries(Collection<Vehicle> vehicles, Collection<Job> services, Map<XYDataItem, String> labels) throws NoLocationFoundException{
|
||||
private XYSeriesCollection makeShipmentSeries(Collection<Job> jobs, Map<XYDataItem, String> labels) throws NoLocationFoundException{
|
||||
XYSeriesCollection coll = new XYSeriesCollection();
|
||||
if(!plotShipments) return coll;
|
||||
int sCounter = 1;
|
||||
String ship = "shipment";
|
||||
boolean first = true;
|
||||
for(Job job : jobs){
|
||||
if(!(job instanceof Shipment)){
|
||||
continue;
|
||||
}
|
||||
Shipment shipment = (Shipment)job;
|
||||
XYSeries shipmentSeries;
|
||||
if(first){
|
||||
first = false;
|
||||
shipmentSeries = new XYSeries(ship, false, true);
|
||||
}
|
||||
else{
|
||||
shipmentSeries = new XYSeries(sCounter, false, true);
|
||||
sCounter++;
|
||||
}
|
||||
shipmentSeries.add(shipment.getPickupCoord().getX(), shipment.getPickupCoord().getY());
|
||||
shipmentSeries.add(shipment.getDeliveryCoord().getX(), shipment.getDeliveryCoord().getY());
|
||||
coll.addSeries(shipmentSeries);
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
|
||||
private XYSeriesCollection makeVrpSeries(Collection<Vehicle> vehicles, Collection<Job> jobs, Map<XYDataItem, String> labels) throws NoLocationFoundException{
|
||||
XYSeriesCollection coll = new XYSeriesCollection();
|
||||
XYSeries vehicleSeries = new XYSeries("depot", false, true);
|
||||
for(Vehicle v : vehicles){
|
||||
|
|
@ -294,13 +380,24 @@ public class Plotter {
|
|||
XYSeries serviceSeries = new XYSeries("service", false, true);
|
||||
XYSeries pickupSeries = new XYSeries("pickup", false, true);
|
||||
XYSeries deliverySeries = new XYSeries("delivery", false, true);
|
||||
for(Job job : services){
|
||||
if(job instanceof Pickup){
|
||||
for(Job job : jobs){
|
||||
if(job instanceof Shipment){
|
||||
Shipment s = (Shipment)job;
|
||||
XYDataItem dataItem = new XYDataItem(s.getPickupCoord().getX(), s.getPickupCoord().getY());
|
||||
pickupSeries.add(dataItem);
|
||||
addLabel(labels, s, dataItem);
|
||||
|
||||
XYDataItem dataItem2 = new XYDataItem(s.getDeliveryCoord().getX(), s.getDeliveryCoord().getY());
|
||||
deliverySeries.add(dataItem2);
|
||||
addLabel(labels, s, dataItem2);
|
||||
}
|
||||
else if(job instanceof Pickup){
|
||||
Pickup service = (Pickup)job;
|
||||
Coordinate coord = service.getCoord();
|
||||
XYDataItem dataItem = new XYDataItem(coord.getX(), coord.getY());
|
||||
pickupSeries.add(dataItem);
|
||||
addLabel(labels, service, dataItem);
|
||||
|
||||
}
|
||||
else if(job instanceof Delivery){
|
||||
Delivery service = (Delivery)job;
|
||||
|
|
@ -327,25 +424,15 @@ public class Plotter {
|
|||
return coll;
|
||||
}
|
||||
|
||||
private void addLabel(Map<XYDataItem, String> labels, Service service, XYDataItem dataItem) {
|
||||
private void addLabel(Map<XYDataItem, String> labels, Job job, XYDataItem dataItem) {
|
||||
if(this.label.equals(Label.SIZE)){
|
||||
labels.put(dataItem, String.valueOf(service.getCapacityDemand()));
|
||||
labels.put(dataItem, String.valueOf(job.getCapacityDemand()));
|
||||
}
|
||||
else if(this.label.equals(Label.ID)){
|
||||
labels.put(dataItem, String.valueOf(service.getId()));
|
||||
labels.put(dataItem, String.valueOf(job.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
private XYSeriesCollection makeVrpSeries(Collection<VehicleRoute> routes, Map<XYDataItem, String> labels) throws NoLocationFoundException{
|
||||
Set<Vehicle> vehicles = new HashSet<Vehicle>();
|
||||
Set<Job> jobs = new HashSet<Job>();
|
||||
for(VehicleRoute route : routes){
|
||||
vehicles.add(route.getVehicle());
|
||||
jobs.addAll(route.getTourActivities().getJobs());
|
||||
}
|
||||
return makeVrpSeries(vehicles, jobs, labels);
|
||||
}
|
||||
|
||||
private XYSeriesCollection makeVrpSeries(VehicleRoutingProblem vrp, Map<XYDataItem, String> labels) throws NoLocationFoundException{
|
||||
return makeVrpSeries(vrp.getVehicles(), vrp.getJobs().values(), labels);
|
||||
}
|
||||
|
|
@ -367,6 +454,22 @@ public class Plotter {
|
|||
if(coord == null) throw new NoLocationFoundException();
|
||||
locs.put(locationId, coord);
|
||||
}
|
||||
else if(j instanceof Shipment){
|
||||
{
|
||||
String locationId = ((Shipment) j).getPickupLocation();
|
||||
if(locationId == null) throw new NoLocationFoundException();
|
||||
Coordinate coord = ((Shipment) j).getPickupCoord();
|
||||
if(coord == null) throw new NoLocationFoundException();
|
||||
locs.put(locationId, coord);
|
||||
}
|
||||
{
|
||||
String locationId = ((Shipment) j).getDeliveryLocation();
|
||||
if(locationId == null) throw new NoLocationFoundException();
|
||||
Coordinate coord = ((Shipment) j).getDeliveryCoord();
|
||||
if(coord == null) throw new NoLocationFoundException();
|
||||
locs.put(locationId, coord);
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw new IllegalStateException("job is not a service. this is not supported yet.");
|
||||
}
|
||||
|
|
@ -380,4 +483,8 @@ public class Plotter {
|
|||
};
|
||||
}
|
||||
|
||||
public void plotShipments(boolean plotShipments) {
|
||||
this.plotShipments = plotShipments;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -14,11 +14,9 @@
|
|||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package analysis;
|
||||
package jsprit.analysis.toolbox;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
|
@ -27,31 +25,29 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.Locations;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jfree.chart.ChartUtilities;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.chart.annotations.XYShapeAnnotation;
|
||||
import org.jfree.chart.axis.NumberAxis;
|
||||
import org.jfree.chart.labels.XYItemLabelGenerator;
|
||||
import org.jfree.chart.plot.XYPlot;
|
||||
import org.jfree.chart.renderer.xy.XYItemRenderer;
|
||||
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
|
||||
import org.jfree.data.xy.XYDataItem;
|
||||
import org.jfree.data.xy.XYDataset;
|
||||
import org.jfree.data.xy.XYSeries;
|
||||
import org.jfree.data.xy.XYSeriesCollection;
|
||||
|
||||
import util.Coordinate;
|
||||
import util.Locations;
|
||||
import basics.Delivery;
|
||||
import basics.Job;
|
||||
import basics.Pickup;
|
||||
import basics.Service;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -82,7 +78,9 @@ public class SolutionPlotter {
|
|||
* @see VehicleRoutingProblem, VehicleRoutingProblemSolution
|
||||
*/
|
||||
public static void plotVrpAsPNG(VehicleRoutingProblem vrp, String pngFile, String title){
|
||||
log.info("plot routes to " + pngFile);
|
||||
String filename = pngFile;
|
||||
if(!pngFile.endsWith(".png")) filename += ".png";
|
||||
log.info("plot routes to " + filename);
|
||||
XYSeriesCollection problem;
|
||||
Map<XYDataItem,String> labels = new HashMap<XYDataItem, String>();
|
||||
try {
|
||||
|
|
@ -93,7 +91,7 @@ public class SolutionPlotter {
|
|||
}
|
||||
XYPlot plot = createPlot(problem, labels);
|
||||
JFreeChart chart = new JFreeChart(title, plot);
|
||||
save(chart,pngFile);
|
||||
save(chart,filename);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -106,7 +104,9 @@ public class SolutionPlotter {
|
|||
* @see VehicleRoute
|
||||
*/
|
||||
public static void plotRoutesAsPNG(Collection<VehicleRoute> routes, Locations locations, String pngFile, String title) {
|
||||
log.info("plot routes to " + pngFile);
|
||||
String filename = pngFile;
|
||||
if(!pngFile.endsWith(".png")) filename += ".png";
|
||||
log.info("plot routes to " + filename);
|
||||
XYSeriesCollection problem;
|
||||
Map<XYDataItem,String> labels = new HashMap<XYDataItem, String>();
|
||||
try {
|
||||
|
|
@ -118,7 +118,7 @@ public class SolutionPlotter {
|
|||
XYSeriesCollection solutionColl = makeSolutionSeries(routes,locations);
|
||||
XYPlot plot = createPlot(problem, solutionColl, labels);
|
||||
JFreeChart chart = new JFreeChart(title, plot);
|
||||
save(chart,pngFile);
|
||||
save(chart,filename);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -133,7 +133,9 @@ public class SolutionPlotter {
|
|||
* @see VehicleRoutingProblem, VehicleRoutingProblemSolution
|
||||
*/
|
||||
public static void plotSolutionAsPNG(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution, String pngFile, String title){
|
||||
log.info("plot solution to " + pngFile);
|
||||
String filename = pngFile;
|
||||
if(!pngFile.endsWith(".png")) filename += ".png";
|
||||
log.info("plot solution to " + filename);
|
||||
XYSeriesCollection problem;
|
||||
XYSeriesCollection solutionColl;
|
||||
Map<XYDataItem,String> labels = new HashMap<XYDataItem, String>();
|
||||
|
|
@ -146,7 +148,7 @@ public class SolutionPlotter {
|
|||
}
|
||||
XYPlot plot = createPlot(problem, solutionColl, labels);
|
||||
JFreeChart chart = new JFreeChart(title, plot);
|
||||
save(chart,pngFile);
|
||||
save(chart,filename);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.analysis.toolbox;
|
||||
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
/**
|
||||
* Printer to print the details of a vehicle-routing-problem solution.
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
public class SolutionPrinter {
|
||||
|
||||
/**
|
||||
* Enum to indicate verbose-level.
|
||||
*
|
||||
* <p> Print.CONCISE and Print.VERBOSE are available.
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
public enum Print {
|
||||
|
||||
CONCISE,VERBOSE
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints costs and #vehicles to stdout (System.out.println).
|
||||
*
|
||||
* @param solution
|
||||
*/
|
||||
public static void print(VehicleRoutingProblemSolution solution){
|
||||
System.out.println("[costs="+solution.getCost() + "]");
|
||||
System.out.println("[#vehicles="+solution.getRoutes().size() + "]");
|
||||
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Prints the details of the solution according to a print-level, i.e. Print.CONCISE or PRINT.VERBOSE.
|
||||
// *
|
||||
// * <p>CONCISE prints total-costs and #vehicles.
|
||||
// * <p>VERBOSE prints the route-details additionally. If the DefaultVehicleRouteCostCalculator (which is the standard-calculator)
|
||||
// * is used in VehicleRoute, then route-costs are differentiated further between transport, activity, vehicle, driver and other-costs.
|
||||
// *
|
||||
// * @param solution
|
||||
// * @param level
|
||||
// *
|
||||
// * @deprecated is not going to work anymore
|
||||
// */
|
||||
// @Deprecated
|
||||
// public static void print(VehicleRoutingProblemSolution solution, Print level){
|
||||
// if(level.equals(Print.CONCISE)){
|
||||
// print(solution);
|
||||
// }
|
||||
// else{
|
||||
// print(solution);
|
||||
// System.out.println("routes");
|
||||
// int routeCount = 1;
|
||||
// for(VehicleRoute route : solution.getRoutes()){
|
||||
// System.out.println("[route="+routeCount+"][departureTime="+route.getStart().getEndTime()+"[total=" + route.getCost() + "]");
|
||||
// if(route.getVehicleRouteCostCalculator() instanceof DefaultVehicleRouteCostCalculator){
|
||||
// DefaultVehicleRouteCostCalculator defaultCalc = (DefaultVehicleRouteCostCalculator) route.getVehicleRouteCostCalculator();
|
||||
// System.out.println("[transport=" + defaultCalc.getTpCosts() + "][activity=" + defaultCalc.getActCosts() +
|
||||
// "][vehicle=" + defaultCalc.getVehicleCosts() + "][driver=" + defaultCalc.getDriverCosts() + "][other=" + defaultCalc.getOther() + "]");
|
||||
// }
|
||||
// routeCount++;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
@ -14,17 +14,18 @@
|
|||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package analysis;
|
||||
package jsprit.analysis.toolbox;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.listener.AlgorithmEndsListener;
|
||||
import jsprit.core.algorithm.listener.AlgorithmStartsListener;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.algo.AlgorithmEndsListener;
|
||||
import basics.algo.AlgorithmStartsListener;
|
||||
|
||||
public class StopWatch implements AlgorithmStartsListener, AlgorithmEndsListener{
|
||||
|
||||
|
|
@ -14,10 +14,12 @@
|
|||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package util;
|
||||
package jsprit.analysis.util;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.util.BenchmarkResult;
|
||||
|
||||
public interface BenchmarkWriter {
|
||||
public void write(Collection<BenchmarkResult> results);
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package util;
|
||||
package jsprit.analysis.util;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
|
|
@ -22,6 +22,8 @@ import java.io.FileWriter;
|
|||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.util.BenchmarkResult;
|
||||
|
||||
import org.jfree.chart.renderer.xy.DeviationRenderer;
|
||||
|
||||
public class HtmlBenchmarkTableWriter implements BenchmarkWriter{
|
||||
Loading…
Add table
Add a link
Reference in a new issue