mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
simplify according to getActivities
This commit is contained in:
parent
dd3f29b5cc
commit
fe590fc9f8
3 changed files with 152 additions and 210 deletions
|
|
@ -153,8 +153,6 @@ public class AlgorithmEventsViewer {
|
||||||
|
|
||||||
private long delayRuin = 5;
|
private long delayRuin = 5;
|
||||||
|
|
||||||
private long delay = 2;
|
|
||||||
|
|
||||||
public void setRecreationDelay(long delay_in_ms) {
|
public void setRecreationDelay(long delay_in_ms) {
|
||||||
this.delayRecreation = delay_in_ms;
|
this.delayRecreation = delay_in_ms;
|
||||||
}
|
}
|
||||||
|
|
@ -174,6 +172,7 @@ public class AlgorithmEventsViewer {
|
||||||
|
|
||||||
DelayContainer delayContainer = new DelayContainer();
|
DelayContainer delayContainer = new DelayContainer();
|
||||||
DelaySink delaySink = new DelaySink(delayContainer);
|
DelaySink delaySink = new DelaySink(delayContainer);
|
||||||
|
long delay = 2;
|
||||||
delaySink.setDelay(delay);
|
delaySink.setDelay(delay);
|
||||||
delaySink.setRecreateDelay(delayRecreation);
|
delaySink.setRecreateDelay(delayRecreation);
|
||||||
delaySink.setRuinDelay(delayRuin);
|
delaySink.setRuinDelay(delayRuin);
|
||||||
|
|
@ -197,7 +196,7 @@ public class AlgorithmEventsViewer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) {
|
||||||
AlgorithmEventsViewer viewer = new AlgorithmEventsViewer();
|
AlgorithmEventsViewer viewer = new AlgorithmEventsViewer();
|
||||||
viewer.setRuinDelay(10);
|
viewer.setRuinDelay(10);
|
||||||
viewer.setRecreationDelay(5);
|
viewer.setRecreationDelay(5);
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,8 @@ package com.graphhopper.jsprit.analysis.toolbox;
|
||||||
|
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||||
|
import com.graphhopper.jsprit.core.problem.job.Activity;
|
||||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
|
||||||
import com.graphhopper.jsprit.core.problem.job.Shipment;
|
|
||||||
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.DeliveryActivity;
|
import com.graphhopper.jsprit.core.problem.solution.route.activity.DeliveryActivity;
|
||||||
|
|
@ -46,7 +45,7 @@ public class GraphStreamViewer {
|
||||||
|
|
||||||
public static class StyleSheets {
|
public static class StyleSheets {
|
||||||
|
|
||||||
public static String BLUE_FOREST =
|
static String BLUE_FOREST =
|
||||||
"graph { fill-color: #141F2E; }" +
|
"graph { fill-color: #141F2E; }" +
|
||||||
"node {" +
|
"node {" +
|
||||||
" size: 7px, 7px;" +
|
" size: 7px, 7px;" +
|
||||||
|
|
@ -169,7 +168,7 @@ public class GraphStreamViewer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Graph createMultiGraph(String name, String style) {
|
static Graph createMultiGraph(String name, String style) {
|
||||||
Graph g = new MultiGraph(name);
|
Graph g = new MultiGraph(name);
|
||||||
g.addAttribute("ui.quality");
|
g.addAttribute("ui.quality");
|
||||||
g.addAttribute("ui.antialias");
|
g.addAttribute("ui.antialias");
|
||||||
|
|
@ -177,66 +176,14 @@ public class GraphStreamViewer {
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ViewPanel createEmbeddedView(Graph graph, double scaling) {
|
private static ViewPanel createEmbeddedView(Graph graph, double scaling) {
|
||||||
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
|
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
|
||||||
ViewPanel view = viewer.addDefaultView(false);
|
ViewPanel view = viewer.addDefaultView(false);
|
||||||
view.setPreferredSize(new Dimension((int) (698 * scaling), (int) (440 * scaling)));
|
view.setPreferredSize(new Dimension((int) (698 * scaling), (int) (440 * scaling)));
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String STYLESHEET =
|
public enum Label {
|
||||||
"node {" +
|
|
||||||
" size: 10px, 10px;" +
|
|
||||||
" fill-color: #6CC644;" +
|
|
||||||
" text-alignment: at-right;" +
|
|
||||||
" stroke-mode: plain;" +
|
|
||||||
" stroke-color: #999;" +
|
|
||||||
" stroke-width: 1.0;" +
|
|
||||||
" text-font: couriernew;" +
|
|
||||||
" text-offset: 2,-5;" +
|
|
||||||
" text-size: 8;" +
|
|
||||||
"}" +
|
|
||||||
"node.pickup {" +
|
|
||||||
" fill-color: #6CC644;" +
|
|
||||||
"}" +
|
|
||||||
"node.delivery {" +
|
|
||||||
" fill-color: #f93;" +
|
|
||||||
"}" +
|
|
||||||
"node.pickupInRoute {" +
|
|
||||||
" fill-color: #6CC644;" +
|
|
||||||
" stroke-mode: plain;" +
|
|
||||||
" stroke-color: #333;" +
|
|
||||||
" stroke-width: 2.0;" +
|
|
||||||
"}" +
|
|
||||||
"node.deliveryInRoute {" +
|
|
||||||
" fill-color: #f93;" +
|
|
||||||
" stroke-mode: plain;" +
|
|
||||||
" stroke-color: #333;" +
|
|
||||||
" stroke-width: 2.0;" +
|
|
||||||
"}" +
|
|
||||||
"node.depot {" +
|
|
||||||
" fill-color: #BD2C00;" +
|
|
||||||
" size: 10px, 10px;" +
|
|
||||||
" shape: box;" +
|
|
||||||
"}" +
|
|
||||||
"node.removed {" +
|
|
||||||
" fill-color: #BD2C00;" +
|
|
||||||
" size: 10px, 10px;" +
|
|
||||||
" stroke-mode: plain;" +
|
|
||||||
" stroke-color: #333;" +
|
|
||||||
" stroke-width: 2.0;" +
|
|
||||||
"}" +
|
|
||||||
|
|
||||||
"edge {" +
|
|
||||||
" fill-color: #333;" +
|
|
||||||
" arrow-size: 6px,3px;" +
|
|
||||||
"}" +
|
|
||||||
"edge.shipment {" +
|
|
||||||
" fill-color: #999;" +
|
|
||||||
" arrow-size: 6px,3px;" +
|
|
||||||
"}";
|
|
||||||
|
|
||||||
public static enum Label {
|
|
||||||
NO_LABEL, ID, JOB_NAME, ARRIVAL_TIME, DEPARTURE_TIME, ACTIVITY
|
NO_LABEL, ID, JOB_NAME, ARRIVAL_TIME, DEPARTURE_TIME, ACTIVITY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,7 +191,7 @@ public class GraphStreamViewer {
|
||||||
final double x;
|
final double x;
|
||||||
final double y;
|
final double y;
|
||||||
|
|
||||||
public Center(double x, double y) {
|
Center(double x, double y) {
|
||||||
super();
|
super();
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
|
@ -319,13 +266,9 @@ public class GraphStreamViewer {
|
||||||
|
|
||||||
public void display() {
|
public void display() {
|
||||||
System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
|
System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
|
||||||
|
Graph g = createMultiGraph();
|
||||||
Graph g = createMultiGraph("g");
|
|
||||||
|
|
||||||
ViewPanel view = createEmbeddedView(g, scaling);
|
ViewPanel view = createEmbeddedView(g, scaling);
|
||||||
|
|
||||||
createJFrame(view, scaling);
|
createJFrame(view, scaling);
|
||||||
|
|
||||||
render(g, view);
|
render(g, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -369,8 +312,58 @@ public class GraphStreamViewer {
|
||||||
return jframe;
|
return jframe;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Graph createMultiGraph(String name) {
|
private Graph createMultiGraph() {
|
||||||
return GraphStreamViewer.createMultiGraph(name, STYLESHEET);
|
String STYLESHEET = "node {" +
|
||||||
|
" size: 10px, 10px;" +
|
||||||
|
" fill-color: #6CC644;" +
|
||||||
|
" text-alignment: at-right;" +
|
||||||
|
" stroke-mode: plain;" +
|
||||||
|
" stroke-color: #999;" +
|
||||||
|
" stroke-width: 1.0;" +
|
||||||
|
" text-font: couriernew;" +
|
||||||
|
" text-offset: 2,-5;" +
|
||||||
|
" text-size: 8;" +
|
||||||
|
"}" +
|
||||||
|
"node.pickup {" +
|
||||||
|
" fill-color: #6CC644;" +
|
||||||
|
"}" +
|
||||||
|
"node.delivery {" +
|
||||||
|
" fill-color: #f93;" +
|
||||||
|
"}" +
|
||||||
|
"node.pickupInRoute {" +
|
||||||
|
" fill-color: #6CC644;" +
|
||||||
|
" stroke-mode: plain;" +
|
||||||
|
" stroke-color: #333;" +
|
||||||
|
" stroke-width: 2.0;" +
|
||||||
|
"}" +
|
||||||
|
"node.deliveryInRoute {" +
|
||||||
|
" fill-color: #f93;" +
|
||||||
|
" stroke-mode: plain;" +
|
||||||
|
" stroke-color: #333;" +
|
||||||
|
" stroke-width: 2.0;" +
|
||||||
|
"}" +
|
||||||
|
"node.depot {" +
|
||||||
|
" fill-color: #BD2C00;" +
|
||||||
|
" size: 10px, 10px;" +
|
||||||
|
" shape: box;" +
|
||||||
|
"}" +
|
||||||
|
"node.removed {" +
|
||||||
|
" fill-color: #BD2C00;" +
|
||||||
|
" size: 10px, 10px;" +
|
||||||
|
" stroke-mode: plain;" +
|
||||||
|
" stroke-color: #333;" +
|
||||||
|
" stroke-width: 2.0;" +
|
||||||
|
"}" +
|
||||||
|
|
||||||
|
"edge {" +
|
||||||
|
" fill-color: #333;" +
|
||||||
|
" arrow-size: 6px,3px;" +
|
||||||
|
"}" +
|
||||||
|
"edge.shipment {" +
|
||||||
|
" fill-color: #999;" +
|
||||||
|
" arrow-size: 6px,3px;" +
|
||||||
|
"}";
|
||||||
|
return GraphStreamViewer.createMultiGraph("g", STYLESHEET);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void render(Graph g, ViewPanel view) {
|
private void render(Graph g, ViewPanel view) {
|
||||||
|
|
@ -385,11 +378,7 @@ public class GraphStreamViewer {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Job j : vrp.getJobs().values()) {
|
for (Job j : vrp.getJobs().values()) {
|
||||||
if (j instanceof Service) {
|
renderJob(g, j, label);
|
||||||
renderService(g, (Service) j, label);
|
|
||||||
} else if (j instanceof Shipment) {
|
|
||||||
renderShipment(g, (Shipment) j, label, renderShipments);
|
|
||||||
}
|
|
||||||
sleep(renderDelay_in_ms);
|
sleep(renderDelay_in_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -404,6 +393,7 @@ public class GraphStreamViewer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void alignCamera(View view) {
|
private void alignCamera(View view) {
|
||||||
view.getCamera().setViewCenter(center.x, center.y, 0);
|
view.getCamera().setViewCenter(center.x, center.y, 0);
|
||||||
view.getCamera().setViewPercent(zoomFactor);
|
view.getCamera().setViewPercent(zoomFactor);
|
||||||
|
|
@ -501,26 +491,22 @@ public class GraphStreamViewer {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderShipment(Graph g, Shipment shipment, Label label, boolean renderShipments) {
|
private void renderJob(Graph g, Job j, Label label) {
|
||||||
|
String lastNodeId = null;
|
||||||
Node n1 = g.addNode(makeId(shipment.getId(), shipment.getPickupLocation().getId()));
|
for (Activity act : j.getActivities()) {
|
||||||
if (label.equals(Label.ID)) n1.addAttribute("ui.label", shipment.getId());
|
String nodeId = makeId(j.getId(), act.getLocation().getId());
|
||||||
n1.addAttribute("x", shipment.getPickupLocation().getCoordinate().getX());
|
Node n1 = g.addNode(nodeId);
|
||||||
n1.addAttribute("y", shipment.getPickupLocation().getCoordinate().getY());
|
if (label.equals(Label.ID)) n1.addAttribute("ui.label", j.getId());
|
||||||
n1.setAttribute("ui.class", "pickup");
|
n1.addAttribute("x", act.getLocation().getCoordinate().getX());
|
||||||
|
n1.addAttribute("y", act.getLocation().getCoordinate().getY());
|
||||||
Node n2 = g.addNode(makeId(shipment.getId(), shipment.getDeliveryLocation().getId()));
|
if (act.getActivityType().equals(Activity.Type.PICKUP)) n1.setAttribute("ui.class", "pickup");
|
||||||
if (label.equals(Label.ID)) n2.addAttribute("ui.label", shipment.getId());
|
else if (act.getActivityType().equals(Activity.Type.DELIVERY)) n1.setAttribute("ui.class", "delivery");
|
||||||
n2.addAttribute("x", shipment.getDeliveryLocation().getCoordinate().getX());
|
if (renderShipments && lastNodeId != null) {
|
||||||
n2.addAttribute("y", shipment.getDeliveryLocation().getCoordinate().getY());
|
Edge s = g.addEdge(j.getId(), lastNodeId, nodeId, true);
|
||||||
n2.setAttribute("ui.class", "delivery");
|
s.addAttribute("ui.class", "shipment");
|
||||||
|
}
|
||||||
if (renderShipments) {
|
lastNodeId = nodeId;
|
||||||
Edge s = g.addEdge(shipment.getId(), makeId(shipment.getId(), shipment.getPickupLocation().getId()),
|
|
||||||
makeId(shipment.getId(), shipment.getDeliveryLocation().getId()), true);
|
|
||||||
s.addAttribute("ui.class", "shipment");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sleep(long renderDelay_in_ms2) {
|
private void sleep(long renderDelay_in_ms2) {
|
||||||
|
|
@ -532,15 +518,6 @@ public class GraphStreamViewer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderService(Graph g, Service service, Label label) {
|
|
||||||
Node n = g.addNode(makeId(service.getId(), service.getLocation().getId()));
|
|
||||||
if (label.equals(Label.ID)) n.addAttribute("ui.label", service.getId());
|
|
||||||
n.addAttribute("x", service.getLocation().getCoordinate().getX());
|
|
||||||
n.addAttribute("y", service.getLocation().getCoordinate().getY());
|
|
||||||
if (service.getType().equals("pickup")) n.setAttribute("ui.class", "pickup");
|
|
||||||
if (service.getType().equals("delivery")) n.setAttribute("ui.class", "delivery");
|
|
||||||
}
|
|
||||||
|
|
||||||
private String makeId(String id, String locationId) {
|
private String makeId(String id, String locationId) {
|
||||||
return id + "_" + locationId;
|
return id + "_" + locationId;
|
||||||
}
|
}
|
||||||
|
|
@ -575,18 +552,24 @@ public class GraphStreamViewer {
|
||||||
if (act instanceof JobActivity) {
|
if (act instanceof JobActivity) {
|
||||||
Job job = ((JobActivity) act).getJob();
|
Job job = ((JobActivity) act).getJob();
|
||||||
String currIdentifier = makeId(job.getId(), act.getLocation().getId());
|
String currIdentifier = makeId(job.getId(), act.getLocation().getId());
|
||||||
if (label.equals(Label.ACTIVITY)) {
|
Node actNode = g.getNode(currIdentifier);
|
||||||
Node actNode = g.getNode(currIdentifier);
|
switch (label) {
|
||||||
actNode.addAttribute("ui.label", act.getName());
|
case ACTIVITY: {
|
||||||
} else if (label.equals(Label.JOB_NAME)) {
|
actNode.addAttribute("ui.label", act.getName());
|
||||||
Node actNode = g.getNode(currIdentifier);
|
break;
|
||||||
actNode.addAttribute("ui.label", job.getName());
|
}
|
||||||
} else if (label.equals(Label.ARRIVAL_TIME)) {
|
case JOB_NAME: {
|
||||||
Node actNode = g.getNode(currIdentifier);
|
actNode.addAttribute("ui.label", job.getName());
|
||||||
actNode.addAttribute("ui.label", Time.parseSecondsToTime(act.getArrTime()));
|
break;
|
||||||
} else if (label.equals(Label.DEPARTURE_TIME)) {
|
}
|
||||||
Node actNode = g.getNode(currIdentifier);
|
case ARRIVAL_TIME: {
|
||||||
actNode.addAttribute("ui.label", Time.parseSecondsToTime(act.getEndTime()));
|
actNode.addAttribute("ui.label", Time.parseSecondsToTime(act.getArrTime()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DEPARTURE_TIME: {
|
||||||
|
actNode.addAttribute("ui.label", Time.parseSecondsToTime(act.getEndTime()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
g.addEdge(makeEdgeId(routeId, vehicle_edgeId), prevIdentifier, currIdentifier, true);
|
g.addEdge(makeEdgeId(routeId, vehicle_edgeId), prevIdentifier, currIdentifier, true);
|
||||||
if (act instanceof PickupActivity) g.getNode(currIdentifier).addAttribute("ui.class", "pickupInRoute");
|
if (act instanceof PickupActivity) g.getNode(currIdentifier).addAttribute("ui.class", "pickupInRoute");
|
||||||
|
|
@ -607,7 +590,4 @@ public class GraphStreamViewer {
|
||||||
return Integer.valueOf(routeId).toString() + "." + Integer.valueOf(vehicle_edgeId).toString();
|
return Integer.valueOf(routeId).toString() + "." + Integer.valueOf(vehicle_edgeId).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void saveAsPNG(String filename){
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ package com.graphhopper.jsprit.analysis.toolbox;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.problem.Location;
|
import com.graphhopper.jsprit.core.problem.Location;
|
||||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import com.graphhopper.jsprit.core.problem.job.*;
|
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
||||||
|
|
@ -27,14 +27,12 @@ import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||||
import org.jfree.chart.*;
|
import org.jfree.chart.*;
|
||||||
import org.jfree.chart.axis.NumberAxis;
|
import org.jfree.chart.axis.NumberAxis;
|
||||||
import org.jfree.chart.labels.XYItemLabelGenerator;
|
|
||||||
import org.jfree.chart.plot.XYPlot;
|
import org.jfree.chart.plot.XYPlot;
|
||||||
import org.jfree.chart.renderer.xy.XYItemRenderer;
|
import org.jfree.chart.renderer.xy.XYItemRenderer;
|
||||||
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
|
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
|
||||||
import org.jfree.chart.title.LegendTitle;
|
import org.jfree.chart.title.LegendTitle;
|
||||||
import org.jfree.data.Range;
|
import org.jfree.data.Range;
|
||||||
import org.jfree.data.xy.XYDataItem;
|
import org.jfree.data.xy.XYDataItem;
|
||||||
import org.jfree.data.xy.XYDataset;
|
|
||||||
import org.jfree.data.xy.XYSeries;
|
import org.jfree.data.xy.XYSeries;
|
||||||
import org.jfree.data.xy.XYSeriesCollection;
|
import org.jfree.data.xy.XYSeriesCollection;
|
||||||
import org.jfree.ui.RectangleEdge;
|
import org.jfree.ui.RectangleEdge;
|
||||||
|
|
@ -79,7 +77,7 @@ public class Plotter {
|
||||||
|
|
||||||
private Set<XYDataItem> firstActivities;
|
private Set<XYDataItem> firstActivities;
|
||||||
|
|
||||||
public MyActivityRenderer(XYSeriesCollection seriesCollection, Map<XYDataItem, Activity> activities, Set<XYDataItem> firstActivities) {
|
MyActivityRenderer(XYSeriesCollection seriesCollection, Map<XYDataItem, Activity> activities, Set<XYDataItem> firstActivities) {
|
||||||
super(false, true);
|
super(false, true);
|
||||||
this.seriesCollection = seriesCollection;
|
this.seriesCollection = seriesCollection;
|
||||||
this.activities = activities;
|
this.activities = activities;
|
||||||
|
|
@ -126,7 +124,7 @@ public class Plotter {
|
||||||
double maxX;
|
double maxX;
|
||||||
double maxY;
|
double maxY;
|
||||||
|
|
||||||
public BoundingBox(double minX, double minY, double maxX, double maxY) {
|
BoundingBox(double minX, double minY, double maxX, double maxY) {
|
||||||
super();
|
super();
|
||||||
this.minX = minX;
|
this.minX = minX;
|
||||||
this.minY = minY;
|
this.minY = minY;
|
||||||
|
|
@ -148,7 +146,7 @@ public class Plotter {
|
||||||
*
|
*
|
||||||
* @author schroeder
|
* @author schroeder
|
||||||
*/
|
*/
|
||||||
public static enum Label {
|
public enum Label {
|
||||||
ID, SIZE, @SuppressWarnings("UnusedDeclaration")NO_LABEL
|
ID, SIZE, @SuppressWarnings("UnusedDeclaration")NO_LABEL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,13 +162,13 @@ public class Plotter {
|
||||||
|
|
||||||
private BoundingBox boundingBox = null;
|
private BoundingBox boundingBox = null;
|
||||||
|
|
||||||
private Map<XYDataItem, Activity> activitiesByDataItem = new HashMap<XYDataItem, Plotter.Activity>();
|
private Map<XYDataItem, Activity> activitiesByDataItem = new HashMap<>();
|
||||||
|
|
||||||
private Map<XYDataItem, String> labelsByDataItem = new HashMap<XYDataItem, String>();
|
private Map<XYDataItem, String> labelsByDataItem = new HashMap<>();
|
||||||
|
|
||||||
private XYSeries activities;
|
private XYSeries activities;
|
||||||
|
|
||||||
private Set<XYDataItem> firstActivities = new HashSet<XYDataItem>();
|
private Set<XYDataItem> firstActivities = new HashSet<>();
|
||||||
|
|
||||||
private boolean containsPickupAct = false;
|
private boolean containsPickupAct = false;
|
||||||
|
|
||||||
|
|
@ -247,7 +245,7 @@ public class Plotter {
|
||||||
* @param minY lower left y
|
* @param minY lower left y
|
||||||
* @param maxX upper right x
|
* @param maxX upper right x
|
||||||
* @param maxY upper right y
|
* @param maxY upper right y
|
||||||
* @return
|
* @return Plotter
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
public Plotter setBoundingBox(double minX, double minY, double maxX, double maxY) {
|
public Plotter setBoundingBox(double minX, double minY, double maxX, double maxY) {
|
||||||
|
|
@ -321,27 +319,15 @@ public class Plotter {
|
||||||
@Override
|
@Override
|
||||||
public LegendItemCollection getLegendItems() {
|
public LegendItemCollection getLegendItems() {
|
||||||
LegendItemCollection lic = new LegendItemCollection();
|
LegendItemCollection lic = new LegendItemCollection();
|
||||||
LegendItem vehLoc = new LegendItem("vehLoc", Color.RED);
|
addLegendItem(lic, "vehLoc", Color.RED);
|
||||||
vehLoc.setShape(ELLIPSE);
|
|
||||||
vehLoc.setShapeVisible(true);
|
|
||||||
lic.add(vehLoc);
|
|
||||||
if (containsServiceAct) {
|
if (containsServiceAct) {
|
||||||
LegendItem item = new LegendItem("service", Color.BLUE);
|
addLegendItem(lic, "service", Color.BLUE);
|
||||||
item.setShape(ELLIPSE);
|
|
||||||
item.setShapeVisible(true);
|
|
||||||
lic.add(item);
|
|
||||||
}
|
}
|
||||||
if (containsPickupAct) {
|
if (containsPickupAct) {
|
||||||
LegendItem item = new LegendItem("pickup", Color.GREEN);
|
addLegendItem(lic, "pickup", Color.GREEN);
|
||||||
item.setShape(ELLIPSE);
|
|
||||||
item.setShapeVisible(true);
|
|
||||||
lic.add(item);
|
|
||||||
}
|
}
|
||||||
if (containsDeliveryAct) {
|
if (containsDeliveryAct) {
|
||||||
LegendItem item = new LegendItem("delivery", Color.BLUE);
|
addLegendItem(lic, "delivery", Color.BLUE);
|
||||||
item.setShape(ELLIPSE);
|
|
||||||
item.setShapeVisible(true);
|
|
||||||
lic.add(item);
|
|
||||||
}
|
}
|
||||||
if (routes != null) {
|
if (routes != null) {
|
||||||
LegendItem item = new LegendItem("firstActivity", Color.BLACK);
|
LegendItem item = new LegendItem("firstActivity", Color.BLACK);
|
||||||
|
|
@ -363,6 +349,13 @@ public class Plotter {
|
||||||
}
|
}
|
||||||
return lic;
|
return lic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addLegendItem(LegendItemCollection lic, String jobType, Color color) {
|
||||||
|
LegendItem item = new LegendItem(jobType, color);
|
||||||
|
item.setShape(ELLIPSE);
|
||||||
|
item.setShapeVisible(true);
|
||||||
|
lic.add(item);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
LegendTitle legend = new LegendTitle(lis);
|
LegendTitle legend = new LegendTitle(lis);
|
||||||
|
|
@ -384,14 +377,9 @@ public class Plotter {
|
||||||
|
|
||||||
private MyActivityRenderer getProblemRenderer(final XYSeriesCollection problem) {
|
private MyActivityRenderer getProblemRenderer(final XYSeriesCollection problem) {
|
||||||
MyActivityRenderer problemRenderer = new MyActivityRenderer(problem, activitiesByDataItem, firstActivities);
|
MyActivityRenderer problemRenderer = new MyActivityRenderer(problem, activitiesByDataItem, firstActivities);
|
||||||
problemRenderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {
|
problemRenderer.setBaseItemLabelGenerator((arg0, arg1, arg2) -> {
|
||||||
|
XYDataItem item = problem.getSeries(arg1).getDataItem(arg2);
|
||||||
@Override
|
return labelsByDataItem.get(item);
|
||||||
public String generateLabel(XYDataset arg0, int arg1, int arg2) {
|
|
||||||
XYDataItem item = problem.getSeries(arg1).getDataItem(arg2);
|
|
||||||
return labelsByDataItem.get(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
problemRenderer.setBaseItemLabelsVisible(true);
|
problemRenderer.setBaseItemLabelsVisible(true);
|
||||||
problemRenderer.setBaseItemLabelPaint(Color.BLACK);
|
problemRenderer.setBaseItemLabelPaint(Color.BLACK);
|
||||||
|
|
@ -467,7 +455,7 @@ public class Plotter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private XYSeriesCollection makeSolutionSeries(VehicleRoutingProblem vrp, Collection<VehicleRoute> routes) throws NoLocationFoundException {
|
private XYSeriesCollection makeSolutionSeries(VehicleRoutingProblem vrp, Collection<VehicleRoute> routes) {
|
||||||
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;
|
||||||
|
|
@ -493,22 +481,20 @@ 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<>();
|
||||||
for (Location l : allLocations) coords.put(l.getId(), l.getCoordinate());
|
for (Location l : allLocations) coords.put(l.getId(), l.getCoordinate());
|
||||||
return coords;
|
return coords;
|
||||||
}
|
}
|
||||||
|
|
||||||
private XYSeriesCollection makeShipmentSeries(Collection<Job> jobs) throws NoLocationFoundException {
|
private XYSeriesCollection makeShipmentSeries(Collection<Job> jobs) {
|
||||||
XYSeriesCollection coll = new XYSeriesCollection();
|
XYSeriesCollection coll = new XYSeriesCollection();
|
||||||
if (!plotShipments) return coll;
|
if (!plotShipments) return coll;
|
||||||
int sCounter = 1;
|
int sCounter = 1;
|
||||||
String ship = "shipment";
|
String ship = "shipment";
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Job job : jobs) {
|
for (Job job : jobs) {
|
||||||
if (!(job instanceof Shipment)) {
|
if (job.getActivities().size() == 1) continue;
|
||||||
continue;
|
// Shipment shipment = (Shipment) job;
|
||||||
}
|
|
||||||
Shipment shipment = (Shipment) job;
|
|
||||||
XYSeries shipmentSeries;
|
XYSeries shipmentSeries;
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
|
|
@ -517,57 +503,34 @@ public class Plotter {
|
||||||
shipmentSeries = new XYSeries(sCounter, false, true);
|
shipmentSeries = new XYSeries(sCounter, false, true);
|
||||||
sCounter++;
|
sCounter++;
|
||||||
}
|
}
|
||||||
Coordinate pickupCoordinate = getCoordinate(shipment.getPickupLocation().getCoordinate());
|
for (com.graphhopper.jsprit.core.problem.job.Activity act : job.getActivities()) {
|
||||||
Coordinate delCoordinate = getCoordinate(shipment.getDeliveryLocation().getCoordinate());
|
Coordinate actCoordinate = getCoordinate(act.getLocation().getCoordinate());
|
||||||
shipmentSeries.add(pickupCoordinate.getX() * scalingFactor, pickupCoordinate.getY() * scalingFactor);
|
shipmentSeries.add(actCoordinate.getX() * scalingFactor, actCoordinate.getY() * scalingFactor);
|
||||||
shipmentSeries.add(delCoordinate.getX() * scalingFactor, delCoordinate.getY() * scalingFactor);
|
}
|
||||||
coll.addSeries(shipmentSeries);
|
coll.addSeries(shipmentSeries);
|
||||||
}
|
}
|
||||||
return coll;
|
return coll;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addJob(XYSeries activities, Job job) {
|
private void addJob(XYSeries activities, Job job) {
|
||||||
if (job instanceof Shipment) {
|
for (com.graphhopper.jsprit.core.problem.job.Activity act : job.getActivities()) {
|
||||||
Shipment s = (Shipment) job;
|
XYDataItem dataItem = new XYDataItem(getCoordinate(act.getLocation().getCoordinate()).getX() * scalingFactor, getCoordinate(act.getLocation().getCoordinate()).getY() * scalingFactor);
|
||||||
Coordinate pickupCoordinate = getCoordinate(s.getPickupLocation().getCoordinate());
|
|
||||||
XYDataItem dataItem = new XYDataItem(pickupCoordinate.getX() * scalingFactor, pickupCoordinate.getY() * scalingFactor);
|
|
||||||
activities.add(dataItem);
|
activities.add(dataItem);
|
||||||
addLabel(s, dataItem);
|
addLabel(job, dataItem);
|
||||||
markItem(dataItem, Activity.PICKUP);
|
switch (act.getActivityType()) {
|
||||||
containsPickupAct = true;
|
case PICKUP:
|
||||||
|
markItem(dataItem, Activity.PICKUP);
|
||||||
Coordinate deliveryCoordinate = getCoordinate(s.getDeliveryLocation().getCoordinate());
|
containsPickupAct = true;
|
||||||
XYDataItem dataItem2 = new XYDataItem(deliveryCoordinate.getX() * scalingFactor, deliveryCoordinate.getY() * scalingFactor);
|
break;
|
||||||
activities.add(dataItem2);
|
case DELIVERY:
|
||||||
addLabel(s, dataItem2);
|
markItem(dataItem, Activity.DELIVERY);
|
||||||
markItem(dataItem2, Activity.DELIVERY);
|
containsDeliveryAct = true;
|
||||||
containsDeliveryAct = true;
|
break;
|
||||||
} else if (job instanceof Pickup) {
|
case SERVICE:
|
||||||
Pickup service = (Pickup) job;
|
markItem(dataItem, Activity.SERVICE);
|
||||||
Coordinate coord = getCoordinate(service.getLocation().getCoordinate());
|
containsServiceAct = true;
|
||||||
XYDataItem dataItem = new XYDataItem(coord.getX() * scalingFactor, coord.getY() * scalingFactor);
|
break;
|
||||||
activities.add(dataItem);
|
}
|
||||||
addLabel(service, dataItem);
|
|
||||||
markItem(dataItem, Activity.PICKUP);
|
|
||||||
containsPickupAct = true;
|
|
||||||
} else if (job instanceof Delivery) {
|
|
||||||
Delivery service = (Delivery) job;
|
|
||||||
Coordinate coord = getCoordinate(service.getLocation().getCoordinate());
|
|
||||||
XYDataItem dataItem = new XYDataItem(coord.getX() * scalingFactor, coord.getY() * scalingFactor);
|
|
||||||
activities.add(dataItem);
|
|
||||||
addLabel(service, dataItem);
|
|
||||||
markItem(dataItem, Activity.DELIVERY);
|
|
||||||
containsDeliveryAct = true;
|
|
||||||
} else if (job instanceof Service) {
|
|
||||||
Service service = (Service) job;
|
|
||||||
Coordinate coord = getCoordinate(service.getLocation().getCoordinate());
|
|
||||||
XYDataItem dataItem = new XYDataItem(coord.getX() * scalingFactor, coord.getY() * scalingFactor);
|
|
||||||
activities.add(dataItem);
|
|
||||||
addLabel(service, dataItem);
|
|
||||||
markItem(dataItem, Activity.SERVICE);
|
|
||||||
containsServiceAct = true;
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("job instanceof " + job.getClass().toString() + ". this is not supported.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -585,11 +548,11 @@ public class Plotter {
|
||||||
boolean firstDim = true;
|
boolean firstDim = true;
|
||||||
for (int i = 0; i < job.getSize().getNuOfDimensions(); i++) {
|
for (int i = 0; i < job.getSize().getNuOfDimensions(); i++) {
|
||||||
if (firstDim) {
|
if (firstDim) {
|
||||||
builder.append(String.valueOf(job.getSize().get(i)));
|
builder.append(job.getSize().get(i));
|
||||||
firstDim = false;
|
firstDim = false;
|
||||||
} else {
|
} else {
|
||||||
builder.append(",");
|
builder.append(",");
|
||||||
builder.append(String.valueOf(job.getSize().get(i)));
|
builder.append(job.getSize().get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
builder.append(")");
|
builder.append(")");
|
||||||
|
|
@ -606,16 +569,16 @@ public class Plotter {
|
||||||
private void retrieveActivities(VehicleRoutingProblem vrp) throws NoLocationFoundException {
|
private void retrieveActivities(VehicleRoutingProblem vrp) throws NoLocationFoundException {
|
||||||
activities = new XYSeries("activities", false, true);
|
activities = new XYSeries("activities", false, true);
|
||||||
for (Vehicle v : vrp.getVehicles()) {
|
for (Vehicle v : vrp.getVehicles()) {
|
||||||
Coordinate start_coordinate = getCoordinate(v.getStartLocation().getCoordinate());
|
Coordinate startCoordinate = getCoordinate(v.getStartLocation().getCoordinate());
|
||||||
if (start_coordinate == null) throw new NoLocationFoundException();
|
if (startCoordinate == null) throw new NoLocationFoundException();
|
||||||
XYDataItem item = new XYDataItem(start_coordinate.getX() * scalingFactor, start_coordinate.getY() * scalingFactor);
|
XYDataItem item = new XYDataItem(startCoordinate.getX() * scalingFactor, startCoordinate.getY() * scalingFactor);
|
||||||
markItem(item, Activity.START);
|
markItem(item, Activity.START);
|
||||||
activities.add(item);
|
activities.add(item);
|
||||||
|
|
||||||
if (!v.getStartLocation().getId().equals(v.getEndLocation().getId())) {
|
if (!v.getStartLocation().getId().equals(v.getEndLocation().getId())) {
|
||||||
Coordinate end_coordinate = getCoordinate(v.getEndLocation().getCoordinate());
|
Coordinate endCoordinate = getCoordinate(v.getEndLocation().getCoordinate());
|
||||||
if (end_coordinate == null) throw new NoLocationFoundException();
|
if (endCoordinate == null) throw new NoLocationFoundException();
|
||||||
XYDataItem end_item = new XYDataItem(end_coordinate.getX() * scalingFactor, end_coordinate.getY() * scalingFactor);
|
XYDataItem end_item = new XYDataItem(endCoordinate.getX() * scalingFactor, endCoordinate.getY() * scalingFactor);
|
||||||
markItem(end_item, Activity.END);
|
markItem(end_item, Activity.END);
|
||||||
activities.add(end_item);
|
activities.add(end_item);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue