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

Merge pull request #371 from albertjimenez/master

Modified signature for returning the file instance
This commit is contained in:
Stefan Schröder 2017-08-11 09:46:36 +02:00 committed by GitHub
commit dec11f646a

View file

@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
import java.awt.*; import java.awt.*;
import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
@ -270,20 +271,21 @@ public class Plotter {
* *
* @param pngFileName - path and filename * @param pngFileName - path and filename
* @param plotTitle - title that appears on top of image * @param plotTitle - title that appears on top of image
* @return BufferedImage image to write
*/ */
public void plot(String pngFileName, String plotTitle) { public BufferedImage plot(String pngFileName, String plotTitle) {
String filename = pngFileName; String filename = pngFileName;
if (!pngFileName.endsWith(".png")) filename += ".png"; if (!pngFileName.endsWith(".png")) filename += ".png";
if (plotSolutionAsWell) { if (plotSolutionAsWell) {
plot(vrp, routes, filename, plotTitle); return plot(vrp, routes, filename, plotTitle);
} else if (!(vrp.getInitialVehicleRoutes().isEmpty())) { } else if (!(vrp.getInitialVehicleRoutes().isEmpty())) {
plot(vrp, vrp.getInitialVehicleRoutes(), filename, plotTitle); return plot(vrp, vrp.getInitialVehicleRoutes(), filename, plotTitle);
} else { } else {
plot(vrp, null, filename, plotTitle); return plot(vrp, null, filename, plotTitle);
} }
} }
private void plot(VehicleRoutingProblem vrp, final Collection<VehicleRoute> routes, String pngFile, String title) { private BufferedImage plot(VehicleRoutingProblem vrp, final Collection<VehicleRoute> routes, String pngFile, String title) {
log.info("plot to {}", pngFile); log.info("plot to {}", pngFile);
XYSeriesCollection problem; XYSeriesCollection problem;
XYSeriesCollection solution = null; XYSeriesCollection solution = null;
@ -295,7 +297,7 @@ public class Plotter {
if (routes != null) solution = makeSolutionSeries(vrp, routes); if (routes != null) solution = makeSolutionSeries(vrp, routes);
} catch (NoLocationFoundException e) { } catch (NoLocationFoundException e) {
log.warn("cannot plot vrp, since coord is missing"); log.warn("cannot plot vrp, since coord is missing");
return; return null;
} }
final XYPlot plot = createPlot(problem, shipments, solution); final XYPlot plot = createPlot(problem, shipments, solution);
JFreeChart chart = new JFreeChart(title, plot); JFreeChart chart = new JFreeChart(title, plot);
@ -305,6 +307,7 @@ public class Plotter {
chart.addLegend(legend); chart.addLegend(legend);
save(chart, pngFile); save(chart, pngFile);
return chart.createBufferedImage(1024, 1024);
} }
@ -461,7 +464,7 @@ public class Plotter {
} }
private XYSeriesCollection makeSolutionSeries(VehicleRoutingProblem vrp, Collection<VehicleRoute> routes) throws NoLocationFoundException { private XYSeriesCollection makeSolutionSeries(VehicleRoutingProblem vrp, Collection<VehicleRoute> routes) throws NoLocationFoundException {
Map<String,Coordinate> coords = makeMap(vrp.getAllLocations()); Map<String, Coordinate> coords = makeMap(vrp.getAllLocations());
XYSeriesCollection coll = new XYSeriesCollection(); XYSeriesCollection coll = new XYSeriesCollection();
int counter = 1; int counter = 1;
for (VehicleRoute route : routes) { for (VehicleRoute route : routes) {
@ -487,7 +490,7 @@ public class Plotter {
private Map<String, Coordinate> makeMap(Collection<Location> allLocations) { private Map<String, Coordinate> makeMap(Collection<Location> allLocations) {
Map<String, Coordinate> coords = new HashMap<String, Coordinate>(); Map<String, Coordinate> coords = new HashMap<String, Coordinate>();
for(Location l : allLocations) coords.put(l.getId(),l.getCoordinate()); for (Location l : allLocations) coords.put(l.getId(), l.getCoordinate());
return coords; return coords;
} }