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

add shipment view

This commit is contained in:
Stefan Schroeder 2013-12-11 12:14:44 +01:00
parent f0c6d15852
commit be00d30fde
3 changed files with 70 additions and 18 deletions

View file

@ -10,9 +10,10 @@ import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity;
import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.Vehicle;
import org.graphstream.graph.Edge;
import org.graphstream.graph.Graph; import org.graphstream.graph.Graph;
import org.graphstream.graph.Node; import org.graphstream.graph.Node;
import org.graphstream.graph.implementations.DefaultGraph; import org.graphstream.graph.implementations.MultiGraph;
import org.graphstream.ui.swingViewer.Viewer; import org.graphstream.ui.swingViewer.Viewer;
public class GraphStreamViewer { public class GraphStreamViewer {
@ -41,7 +42,7 @@ public class GraphStreamViewer {
" arrow-size: 6px,3px;" + " arrow-size: 6px,3px;" +
"}" + "}" +
"edge.shipment {" + "edge.shipment {" +
" fill-color: blue;" + " fill-color: grey;" +
" arrow-size: 6px,3px;" + " arrow-size: 6px,3px;" +
"}" ; "}" ;
@ -51,7 +52,15 @@ public class GraphStreamViewer {
private Label label = Label.NO_LABEL; private Label label = Label.NO_LABEL;
private boolean renderShipments = false; private boolean renderShipments = false;
private boolean enableAutoDisplay = false; private boolean enableAutoDisplay = false;
private BoundingBox boundingBox;
/**
* @param boundingBox the boundingBox to set
*/
public void setBoundingBox(BoundingBox boundingBox) {
this.boundingBox = boundingBox;
}
private VehicleRoutingProblem vrp; private VehicleRoutingProblem vrp;
private VehicleRoutingProblemSolution solution; private VehicleRoutingProblemSolution solution;
@ -86,7 +95,7 @@ public class GraphStreamViewer {
private static void display(View view){ private static void display(View view){
System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer"); System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
Graph g = new DefaultGraph("g"); Graph g = new MultiGraph("g");
g.addAttribute("ui.quality"); g.addAttribute("ui.quality");
g.addAttribute("ui.antialias"); g.addAttribute("ui.antialias");
g.addAttribute("ui.stylesheet", styleSheet); g.addAttribute("ui.stylesheet", styleSheet);
@ -94,6 +103,7 @@ public class GraphStreamViewer {
Viewer viewer = g.display(); Viewer viewer = g.display();
if(!view.enableAutoDisplay) viewer.disableAutoLayout(); if(!view.enableAutoDisplay) viewer.disableAutoLayout();
for(Vehicle vehicle : view.vrp.getVehicles()){ for(Vehicle vehicle : view.vrp.getVehicles()){
renderVehicle(g,vehicle,view.label); renderVehicle(g,vehicle,view.label);
sleep(view.renderDelay); sleep(view.renderDelay);
@ -117,6 +127,19 @@ public class GraphStreamViewer {
routeId++; routeId++;
} }
} }
if(view.boundingBox != null){
//// viewer.getDefaultView().getCamera().setViewPercent(0.5);
// System.out.println("metric="+viewer.getDefaultView().getCamera().getMetrics());
//// viewer.getDefaultView().getCamera().setViewCenter(15000, 50000, 0);
//// viewer.getDefaultView().getCamera().setViewPercent(0.5);
// viewer.getDefaultView().getCamera().setBounds(10000,40000, 0, 20000, 60000, 0);
// System.out.println("metric="+viewer.getDefaultView().getCamera().getMetrics());
//// viewer.getDefaultView().se
// viewer.getDefaultView().display(viewer.getGraphicGraph(), true);
//// viewer.getDefaultView().getCamera().setViewPercent(0.5);
//
}
} }
@ -141,7 +164,9 @@ public class GraphStreamViewer {
n2.setAttribute("ui.class", "delivery"); n2.setAttribute("ui.class", "delivery");
if(renderShipments){ if(renderShipments){
Edge s = g.addEdge(shipment.getId(), makeId(shipment.getId(),shipment.getPickupLocation()),
makeId(shipment.getId(),shipment.getDeliveryLocation()), true);
s.addAttribute("ui.class", "shipment");
} }
} }
@ -221,6 +246,22 @@ public class GraphStreamViewer {
NO_LABEL, ID NO_LABEL, ID
} }
private static class BoundingBox {
final double minX;
final double minY;
final double maxX;
final 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 Label label = Label.NO_LABEL; private Label label = Label.NO_LABEL;
private long renderDelay_in_ms = 0; private long renderDelay_in_ms = 0;
@ -228,6 +269,8 @@ public class GraphStreamViewer {
private boolean enableAutoLayout = false; private boolean enableAutoLayout = false;
private boolean renderShipments = false; private boolean renderShipments = false;
private BoundingBox boundingBox;
private VehicleRoutingProblem vrp; private VehicleRoutingProblem vrp;
@ -263,6 +306,11 @@ public class GraphStreamViewer {
this.renderShipments = renderShipments; this.renderShipments = renderShipments;
return this; return this;
} }
// public GraphStreamViewer setBoundingBox(double minX, double minY, double maxX, double maxY){
// boundingBox = new BoundingBox(minX,minY,maxX,maxY);
// return this;
// }
public void display(){ public void display(){
View view = new View(vrp,solution); View view = new View(vrp,solution);
@ -270,6 +318,7 @@ public class GraphStreamViewer {
view.setLabel(label); view.setLabel(label);
view.setRenderDelay(renderDelay_in_ms); view.setRenderDelay(renderDelay_in_ms);
view.setRenderShipments(renderShipments); view.setRenderShipments(renderShipments);
view.setBoundingBox(boundingBox);
display(view); display(view);
} }

View file

@ -240,32 +240,32 @@ public class BicycleMessenger {
//if you want, terminate it after 1000 iterations with no change //if you want, terminate it after 1000 iterations with no change
// algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(1000)); // algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(1000));
algorithm.addListener(new AlgorithmSearchProgressChartListener("output/progress.png")); algorithm.addListener(new AlgorithmSearchProgressChartListener("output/progress.png"));
algorithm.setNuOfIterations(2000); algorithm.setNuOfIterations(200);
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
//this is just to ensure that solution meet the above constraints //this is just to ensure that solution meet the above constraints
validateSolution(Solutions.bestOf(solutions), bicycleMessengerProblem, nearestMessengers); validateSolution(Solutions.bestOf(solutions), bicycleMessengerProblem, nearestMessengers);
//you may want to plot the problem // //you may want to plot the problem
Plotter plotter = new Plotter(bicycleMessengerProblem); // Plotter plotter = new Plotter(bicycleMessengerProblem);
// plotter.setBoundingBox(10000, 47500, 20000, 67500); //// plotter.setBoundingBox(10000, 47500, 20000, 67500);
plotter.plotShipments(true); // plotter.plotShipments(true);
plotter.plot("output/bicycleMessengerProblem.png", "bicycleMessenger"); // plotter.plot("output/bicycleMessengerProblem.png", "bicycleMessenger");
//
//and the problem as well as the solution // //and the problem as well as the solution
Plotter plotter1 = new Plotter(bicycleMessengerProblem, Solutions.bestOf(solutions)); // Plotter plotter1 = new Plotter(bicycleMessengerProblem, Solutions.bestOf(solutions));
plotter1.plotShipments(true); // plotter1.plotShipments(true);
plotter1.setShowFirstActivity(true); // plotter1.setShowFirstActivity(true);
// plotter1.setBoundingBox(5000, 45500, 25000, 66500); //// plotter1.setBoundingBox(5000, 45500, 25000, 66500);
plotter1.plot("output/bicycleMessengerSolution.png", "bicycleMessenger"); // plotter1.plot("output/bicycleMessengerSolution.png", "bicycleMessenger");
//and write out your solution in xml //and write out your solution in xml
new VrpXMLWriter(bicycleMessengerProblem, solutions).write("output/bicycleMessenger.xml"); new VrpXMLWriter(bicycleMessengerProblem, solutions).write("output/bicycleMessenger.xml");
SolutionPrinter.print(bicycleMessengerProblem, Solutions.bestOf(solutions), Print.VERBOSE); SolutionPrinter.print(bicycleMessengerProblem, Solutions.bestOf(solutions), Print.VERBOSE);
GraphStreamViewer.display(bicycleMessengerProblem, Solutions.bestOf(solutions), 100); new GraphStreamViewer(bicycleMessengerProblem, Solutions.bestOf(solutions)).setRenderDelay(50).setRenderShipments(true).display();
} }

View file

@ -20,6 +20,7 @@ import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import jsprit.analysis.toolbox.GraphStreamViewer;
import jsprit.analysis.toolbox.Plotter; import jsprit.analysis.toolbox.Plotter;
import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.analysis.toolbox.SolutionPrinter;
import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.VehicleRoutingAlgorithm;
@ -126,6 +127,8 @@ public class SimpleEnRoutePickupAndDeliveryExample {
solutionPlotter.plotShipments(true); solutionPlotter.plotShipments(true);
solutionPlotter.plot("output/simpleEnRoutePickupAndDeliveryExample_solution.png", "en-route pickup and delivery"); solutionPlotter.plot("output/simpleEnRoutePickupAndDeliveryExample_solution.png", "en-route pickup and delivery");
new GraphStreamViewer(problem).setRenderShipments(true).display();
} }
} }