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

issue #63 - very basic version of GraphStreamViewer

This commit is contained in:
Stefan Schroeder 2013-12-11 16:40:22 +01:00
parent 439ee29895
commit 8e862b524e
4 changed files with 134 additions and 249 deletions

View file

@ -1,5 +1,11 @@
package jsprit.analysis.toolbox;
import java.awt.Dimension;
import java.text.MessageFormat;
import javax.swing.JFormattedTextField;
import javax.swing.JTextField;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.job.Job;
import jsprit.core.problem.job.Service;
@ -20,130 +26,52 @@ public class GraphStreamViewer {
protected static String styleSheet =
"node {" +
" size: 7px, 7px;" +
" fill-color: rgb(255,204,0);" +
" size: 10px, 10px;" +
" fill-color: #6CC644;" +
" text-alignment: at-right;" +
" stroke-mode: plain;" +
" stroke-color: black;" +
" stroke-color: #999;" +
" stroke-width: 1.0;" +
"}" +
"node.pickup {" +
" fill-color: rgb(255,204,0);" +
" fill-color: #6CC644;" +
"}" +
"node.delivery {" +
" fill-color: rgb(0,102,153);" +
" fill-color: #f93;" +
"}" +
"node.depot {" +
" fill-color: red;" +
" fill-color: #BD2C00;" +
" size: 10px, 10px;" +
" shape: box;" +
"}" +
"edge {" +
" fill-color: black;" +
" fill-color: #333;" +
" arrow-size: 6px,3px;" +
"}" +
"edge.shipment {" +
" fill-color: grey;" +
" fill-color: #999;" +
" arrow-size: 6px,3px;" +
"}" ;
private static class View {
private long renderDelay = 0;
private Label label = Label.NO_LABEL;
private boolean renderShipments = 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 VehicleRoutingProblemSolution solution;
public View(VehicleRoutingProblem vrp) {
super();
this.vrp = vrp;
}
public View(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution) {
super();
this.vrp = vrp;
this.solution = solution;
}
public void setEnableAutoDisplay(boolean enableAutoDisplay) {
this.enableAutoDisplay = enableAutoDisplay;
}
public void setRenderDelay(long renderDelay) {
this.renderDelay = renderDelay;
}
public void setLabel(Label label) {
this.label = label;
}
public void setRenderShipments(boolean renderShipments) {
this.renderShipments = renderShipments;
}
}
// public static void display(VehicleRoutingProblem vrp, int renderDelay_in_ms) {
// View builder = new View(vrp);
// builder.setRenderDelay(renderDelay_in_ms);
// display();
// }
// public static void display(VehicleRoutingProblem vrp) {
// display();
// }
// public static void display(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution, int renderDelay_in_ms, boolean enableAutoLayout) {
// View view = new View(vrp,solution);
// view.setEnableAutoDisplay(enableAutoLayout);
// view.setRenderDelay(renderDelay_in_ms);
// display();
// }
//
// public static void display(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution, int renderDelay_in_ms) {
// View view = new View(vrp,solution);
// view.setRenderDelay(renderDelay_in_ms);
// display();
// }
//
// public static void display(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution) {
// display();
// }
public static enum Label {
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 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;
@ -153,7 +81,7 @@ public class GraphStreamViewer {
private boolean renderShipments = false;
private BoundingBox boundingBox;
// private BoundingBox boundingBox;
private VehicleRoutingProblem vrp;
@ -190,22 +118,6 @@ public class GraphStreamViewer {
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(){
// display();
//// View view = new View(vrp,solution);
//// view.setEnableAutoDisplay(enableAutoLayout);
//// view.setLabel(label);
//// view.setRenderDelay(renderDelay_in_ms);
//// view.setRenderShipments(renderShipments);
//// view.setBoundingBox(boundingBox);
//// display(view);
// }
public void display(){
System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
Graph g = new MultiGraph("g");
@ -214,6 +126,17 @@ public class GraphStreamViewer {
g.addAttribute("ui.stylesheet", styleSheet);
Viewer viewer = g.display();
// MessageFormat format = new MessageFormat("{0,number,00}:{1,number,00}:{2,number,00}");
//
// JFormattedTextField textField = new JFormattedTextField(format);
// textField.setEditable(false);
// textField.setMaximumSize(new Dimension(100,30));
// textField.setMinimumSize(new Dimension(80,30));
// textField.setHorizontalAlignment(JTextField.CENTER);
// textField.setText("00:01:56");
// viewer.getDefaultView().add(textField);
if(!enableAutoLayout) viewer.disableAutoLayout();
@ -240,28 +163,8 @@ public class GraphStreamViewer {
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);
//
// }
}
// public static void display(VehicleRoutingProblem vrp, int renderDelay_in_ms) {
// View builder = new View(vrp);
// builder.setRenderDelay(renderDelay_in_ms);
// display();
// }
private void renderShipment(Graph g, Shipment shipment, Label label, boolean renderShipments) {
Node n1 = g.addNode(makeId(shipment.getId(),shipment.getPickupLocation()));
@ -315,27 +218,6 @@ public class GraphStreamViewer {
n.setAttribute("ui.class", "depot");
}
// public static void display(VehicleRoutingProblem vrp) {
// display();
// }
// public static void display(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution, int renderDelay_in_ms, boolean enableAutoLayout) {
// View view = new View(vrp,solution);
// view.setEnableAutoDisplay(enableAutoLayout);
// view.setRenderDelay(renderDelay_in_ms);
// display();
// }
//
// public static void display(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution, int renderDelay_in_ms) {
// View view = new View(vrp,solution);
// view.setRenderDelay(renderDelay_in_ms);
// display();
// }
//
// public static void display(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution) {
// display();
// }
private void renderRoute(Graph g, VehicleRoute route, int routeId, long renderDelay_in_ms) {
int vehicle_edgeId = 1;
String prevIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getLocationId());

View file

@ -108,7 +108,7 @@ public class PickupAndDeliveryExample2 {
plotter.plot("output/pd_christophides_vrpnc1_solution.png","pd_vrpnc1");
new GraphStreamViewer(vrp, solution).setRenderDelay(100).labelWith(jsprit.analysis.toolbox.GraphStreamViewer.Label.ID).display();
new GraphStreamViewer(vrp, solution).setRenderDelay(100).display();
}

View file

@ -129,7 +129,7 @@ public class SimpleEnRoutePickupAndDeliveryOpenRoutesExample {
solutionPlotter.plotShipments(true);
solutionPlotter.plot("output/simpleEnRoutePickupAndDeliveryExample_solution.png", "en-route pickup and delivery");
new GraphStreamViewer(problem, bestSolution).setRenderDelay(100).display();
new GraphStreamViewer(problem, bestSolution).setRenderShipments(true).setRenderDelay(100).display();
}
}

View file

@ -19,6 +19,7 @@ package jsprit.examples;
import java.io.File;
import java.util.Collection;
import jsprit.analysis.toolbox.GraphStreamViewer;
import jsprit.analysis.toolbox.SolutionPlotter;
import jsprit.analysis.toolbox.SolutionPrinter;
import jsprit.analysis.toolbox.SolutionPrinter.Print;
@ -103,7 +104,9 @@ public class SimpleExample {
/*
* plot
*/
SolutionPlotter.plotSolutionAsPNG(problem, bestSolution, "output/solution.png", "solution");
// SolutionPlotter.plotSolutionAsPNG(problem, bestSolution, "output/solution.png", "solution");
new GraphStreamViewer(problem, bestSolution).display();
}
}