1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

Merge branch 'master' into open-routes-with-constraints

This commit is contained in:
Stefan Schroeder 2013-11-29 17:08:22 +01:00
commit b1c2777030
2 changed files with 44 additions and 7 deletions

View file

@ -50,6 +50,7 @@ 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.Range;
import org.jfree.data.xy.XYDataItem;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
@ -59,6 +60,21 @@ import org.jfree.ui.RectangleEdge;
public class Plotter {
private static class BoundingBox {
double minX;
double minY;
double maxX;
double maxY;
public BoundingBox(double minX, double minY, double maxX, double maxY) {
super();
this.minX = minX;
this.minY = minY;
this.maxX = maxX;
this.maxY = maxY;
}
}
private static class NoLocationFoundException extends Exception{
/**
@ -87,6 +103,8 @@ public class Plotter {
private Collection<VehicleRoute> routes;
private BoundingBox boundingBox = null;
public void setShowFirstActivity(boolean show){
showFirstActivity = show;
}
@ -94,6 +112,10 @@ public class Plotter {
public void setLabel(Label label){
this.label = label;
}
public void setBoundingBox(double minX, double minY, double maxX, double maxY){
boundingBox = new BoundingBox(minX,minY,maxX,maxY);
}
public Plotter(VehicleRoutingProblem vrp) {
super();
@ -198,7 +220,7 @@ public class Plotter {
}
private static XYPlot createProblemPlot(final XYSeriesCollection problem, XYSeriesCollection shipments, final Map<XYDataItem, String> labels) {
private 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);
@ -216,11 +238,12 @@ public class Plotter {
problemRenderer.setBaseItemLabelsVisible(true);
problemRenderer.setBaseItemLabelPaint(Color.BLACK);
NumberAxis xAxis = new NumberAxis();
xAxis.setRangeWithMargins(problem.getDomainBounds(true));
NumberAxis xAxis = new NumberAxis();
xAxis.setRangeWithMargins(getDomainRange(problem));
NumberAxis yAxis = new NumberAxis();
yAxis.setRangeWithMargins(problem.getRangeBounds(false));
yAxis.setRangeWithMargins(getRange(problem));
plot.setDataset(0, problem);
plot.setRenderer(0, problemRenderer);
@ -245,6 +268,16 @@ public class Plotter {
return plot;
}
private Range getRange(final XYSeriesCollection problem) {
if(this.boundingBox==null) return problem.getRangeBounds(false);
else return new Range(boundingBox.minY, boundingBox.maxY);
}
private Range getDomainRange(final XYSeriesCollection problem) {
if(this.boundingBox == null) return problem.getDomainBounds(true);
else return new Range(boundingBox.minX, boundingBox.maxX);
}
private XYPlot createProblemSolutionPlot(final XYSeriesCollection problem, XYSeriesCollection shipments, XYSeriesCollection solutionColl, final Map<XYDataItem, String> labels) {
XYPlot plot = new XYPlot();
plot.setBackgroundPaint(Color.LIGHT_GRAY);
@ -264,10 +297,10 @@ public class Plotter {
problemRenderer.setBaseItemLabelPaint(Color.BLACK);
NumberAxis xAxis = new NumberAxis();
xAxis.setRangeWithMargins(problem.getDomainBounds(true));
xAxis.setRangeWithMargins(getDomainRange(problem));
NumberAxis yAxis = new NumberAxis();
yAxis.setRangeWithMargins(problem.getRangeBounds(true));
yAxis.setRangeWithMargins(getRange(problem));
plot.setDataset(0, problem);
plot.setRenderer(0, problemRenderer);

View file

@ -19,6 +19,7 @@ package jsprit.examples;
import java.io.File;
import java.util.Collection;
import jsprit.analysis.toolbox.Plotter;
import jsprit.analysis.toolbox.SolutionPlotter;
import jsprit.analysis.toolbox.SolutionPrinter;
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
@ -91,7 +92,10 @@ public class SolomonExample {
/*
* Plot solution.
*/
SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/solomon_C101_solution.png","C101");
Plotter plotter = new Plotter(vrp,solution);
// plotter.setBoundingBox(30, 0, 50, 20);
plotter.plot("output/solomon_C101_solution.png", "C101");
// SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/solomon_C101_solution.png","C101");