diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java index 4e494bd1..8849f6ae 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java @@ -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 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 labels) { + private XYPlot createProblemPlot(final XYSeriesCollection problem, XYSeriesCollection shipments, final Map 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 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); diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java index 9aaa823c..6cabfe27 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java @@ -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");