mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
improver graphstreamer
This commit is contained in:
parent
aea6574e60
commit
3eeb8fa084
1 changed files with 40 additions and 57 deletions
|
|
@ -4,8 +4,6 @@ import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.FlowLayout;
|
import java.awt.FlowLayout;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
|
|
@ -30,8 +28,6 @@ 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.MultiGraph;
|
import org.graphstream.graph.implementations.MultiGraph;
|
||||||
import org.graphstream.ui.graphicGraph.GraphicGraph;
|
|
||||||
import org.graphstream.ui.swingViewer.LayerRenderer;
|
|
||||||
import org.graphstream.ui.swingViewer.View;
|
import org.graphstream.ui.swingViewer.View;
|
||||||
import org.graphstream.ui.swingViewer.Viewer;
|
import org.graphstream.ui.swingViewer.Viewer;
|
||||||
|
|
||||||
|
|
@ -85,7 +81,7 @@ public class GraphStreamViewer {
|
||||||
"}" ;
|
"}" ;
|
||||||
|
|
||||||
public static enum Label {
|
public static enum Label {
|
||||||
NO_LABEL, ID
|
NO_LABEL, ID, ACTIVITY
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Center {
|
private static class Center {
|
||||||
|
|
@ -116,6 +112,8 @@ public class GraphStreamViewer {
|
||||||
|
|
||||||
private double zoomFactor;
|
private double zoomFactor;
|
||||||
|
|
||||||
|
private double scaling = 1.0;
|
||||||
|
|
||||||
public GraphStreamViewer(VehicleRoutingProblem vrp) {
|
public GraphStreamViewer(VehicleRoutingProblem vrp) {
|
||||||
super();
|
super();
|
||||||
this.vrp = vrp;
|
this.vrp = vrp;
|
||||||
|
|
@ -147,6 +145,11 @@ public class GraphStreamViewer {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GraphStreamViewer setGraphStreamFrameScalingFactor(double factor){
|
||||||
|
this.scaling=factor;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the camera-view. Center describes the center-focus of the camera and zoomFactor its
|
* Sets the camera-view. Center describes the center-focus of the camera and zoomFactor its
|
||||||
* zoomFactor.
|
* zoomFactor.
|
||||||
|
|
@ -184,42 +187,31 @@ public class GraphStreamViewer {
|
||||||
g.addAttribute("ui.stylesheet", styleSheet);
|
g.addAttribute("ui.stylesheet", styleSheet);
|
||||||
|
|
||||||
JPanel graphStreamPanel = new JPanel();
|
JPanel graphStreamPanel = new JPanel();
|
||||||
graphStreamPanel.setPreferredSize(new Dimension(800,460));
|
graphStreamPanel.setPreferredSize(new Dimension((int)(800*scaling),(int)(460*scaling)));
|
||||||
graphStreamPanel.setBackground(Color.WHITE);
|
graphStreamPanel.setBackground(Color.WHITE);
|
||||||
|
|
||||||
JPanel graphStreamBackPanel = new JPanel();
|
JPanel graphStreamBackPanel = new JPanel();
|
||||||
graphStreamBackPanel.setPreferredSize(new Dimension(700,450));
|
graphStreamBackPanel.setPreferredSize(new Dimension((int)(700*scaling),(int)(450*scaling)));
|
||||||
graphStreamBackPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
|
graphStreamBackPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
|
||||||
graphStreamBackPanel.setBackground(Color.WHITE);
|
graphStreamBackPanel.setBackground(Color.WHITE);
|
||||||
|
|
||||||
Viewer viewer = new Viewer(g,Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
|
Viewer viewer = new Viewer(g,Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
|
||||||
View view = viewer.addDefaultView(false);
|
View view = viewer.addDefaultView(false);
|
||||||
view.setPreferredSize(new Dimension(698,440));
|
view.setPreferredSize(new Dimension((int)(698*scaling),(int)(440*scaling)));
|
||||||
view.setForeLayoutRenderer(new LayerRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(Graphics2D graphics, GraphicGraph graph, double px2Gu,
|
|
||||||
int widthPx, int heightPx, double minXGu, double minYGu,
|
|
||||||
double maxXGu, double maxYGu) {
|
|
||||||
legendPanel.repaint();
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
graphStreamBackPanel.add(view);
|
graphStreamBackPanel.add(view);
|
||||||
|
|
||||||
graphStreamPanel.add(graphStreamBackPanel);
|
graphStreamPanel.add(graphStreamBackPanel);
|
||||||
|
|
||||||
//setup basicPanel
|
//setup basicPanel
|
||||||
basicPanel.add(resultPanel);
|
basicPanel.add(resultPanel);
|
||||||
basicPanel.add(graphStreamPanel);
|
basicPanel.add(graphStreamPanel);
|
||||||
basicPanel.add(legendPanel);
|
// basicPanel.add(legendPanel);
|
||||||
|
|
||||||
//put it together
|
//put it together
|
||||||
jframe.add(basicPanel);
|
jframe.add(basicPanel);
|
||||||
|
|
||||||
//conf jframe
|
//conf jframe
|
||||||
jframe.setSize(800,580);
|
jframe.setSize((int)(800*scaling),(int)(580*scaling));
|
||||||
jframe.setLocationRelativeTo(null);
|
jframe.setLocationRelativeTo(null);
|
||||||
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
jframe.setVisible(true);
|
jframe.setVisible(true);
|
||||||
|
|
@ -256,7 +248,7 @@ public class GraphStreamViewer {
|
||||||
if(solution != null){
|
if(solution != null){
|
||||||
int routeId = 1;
|
int routeId = 1;
|
||||||
for(VehicleRoute route : solution.getRoutes()){
|
for(VehicleRoute route : solution.getRoutes()){
|
||||||
renderRoute(g,route,routeId,renderDelay_in_ms);
|
renderRoute(g,route,routeId,renderDelay_in_ms,label);
|
||||||
sleep(renderDelay_in_ms);
|
sleep(renderDelay_in_ms);
|
||||||
routeId++;
|
routeId++;
|
||||||
}
|
}
|
||||||
|
|
@ -269,12 +261,12 @@ public class GraphStreamViewer {
|
||||||
int height = 50;
|
int height = 50;
|
||||||
|
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
panel.setPreferredSize(new Dimension(width,height));
|
panel.setPreferredSize(new Dimension((int)(width*scaling),(int)(height*scaling)));
|
||||||
panel.setBackground(Color.WHITE);
|
panel.setBackground(Color.WHITE);
|
||||||
|
|
||||||
JPanel subpanel = new JPanel();
|
JPanel subpanel = new JPanel();
|
||||||
subpanel.setLayout(new FlowLayout());
|
subpanel.setLayout(new FlowLayout());
|
||||||
subpanel.setPreferredSize(new Dimension(700,40));
|
subpanel.setPreferredSize(new Dimension((int)(700*scaling),(int)(40*scaling)));
|
||||||
subpanel.setBackground(Color.WHITE);
|
subpanel.setBackground(Color.WHITE);
|
||||||
subpanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
|
subpanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
|
||||||
|
|
||||||
|
|
@ -283,22 +275,10 @@ public class GraphStreamViewer {
|
||||||
//graphic2d
|
//graphic2d
|
||||||
// Graphics2D gr = new
|
// Graphics2D gr = new
|
||||||
|
|
||||||
JLabel circleL = new JLabel(){
|
|
||||||
|
|
||||||
public void paintComponent(Graphics g){
|
|
||||||
Color orig = g.getColor();
|
|
||||||
g.setColor(Color.RED);
|
|
||||||
g.fillOval(50,50,50,50);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
// circleL.paintComponents(circle);
|
|
||||||
|
|
||||||
|
|
||||||
//label
|
//label
|
||||||
JLabel depots = new JLabel(new String("depots"));
|
JLabel depots = new JLabel(new String("depots"));
|
||||||
depots.setFont(font);
|
depots.setFont(font);
|
||||||
depots.setPreferredSize(new Dimension(40,25));
|
depots.setPreferredSize(new Dimension((int)(40*scaling),(int)(25*scaling)));
|
||||||
|
|
||||||
|
|
||||||
//graphic2d
|
//graphic2d
|
||||||
|
|
@ -306,20 +286,20 @@ public class GraphStreamViewer {
|
||||||
//label
|
//label
|
||||||
JLabel pickups = new JLabel(new String("pickups"));
|
JLabel pickups = new JLabel(new String("pickups"));
|
||||||
pickups.setFont(font);
|
pickups.setFont(font);
|
||||||
pickups.setPreferredSize(new Dimension(40,25));
|
pickups.setPreferredSize(new Dimension((int)(40*scaling),(int)(25*scaling)));
|
||||||
|
|
||||||
//graphic2d
|
//graphic2d
|
||||||
|
|
||||||
//label
|
//label
|
||||||
JLabel deliveries = new JLabel(new String("deliveries"));
|
JLabel deliveries = new JLabel(new String("deliveries"));
|
||||||
deliveries.setFont(font);
|
deliveries.setFont(font);
|
||||||
deliveries.setPreferredSize(new Dimension(40,25));
|
deliveries.setPreferredSize(new Dimension((int)(40*scaling),(int)(25*scaling)));
|
||||||
|
|
||||||
//shipments
|
//shipments
|
||||||
// if(renderShipments()){
|
// if(renderShipments()){
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
subpanel.add(circleL);
|
|
||||||
subpanel.add(depots);
|
subpanel.add(depots);
|
||||||
|
|
||||||
JLabel emptyLabel1 = createEmptyLabel();
|
JLabel emptyLabel1 = createEmptyLabel();
|
||||||
|
|
@ -339,7 +319,7 @@ public class GraphStreamViewer {
|
||||||
|
|
||||||
private JLabel createEmptyLabel() {
|
private JLabel createEmptyLabel() {
|
||||||
JLabel emptyLabel1 = new JLabel();
|
JLabel emptyLabel1 = new JLabel();
|
||||||
emptyLabel1.setPreferredSize(new Dimension(40,25));
|
emptyLabel1.setPreferredSize(new Dimension((int)(40*scaling),(int)(25*scaling)));
|
||||||
return emptyLabel1;
|
return emptyLabel1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -348,12 +328,12 @@ public class GraphStreamViewer {
|
||||||
int height = 50;
|
int height = 50;
|
||||||
|
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
panel.setPreferredSize(new Dimension(width,height));
|
panel.setPreferredSize(new Dimension((int)(width*scaling),(int)(height*scaling)));
|
||||||
panel.setBackground(Color.WHITE);
|
panel.setBackground(Color.WHITE);
|
||||||
|
|
||||||
JPanel subpanel = new JPanel();
|
JPanel subpanel = new JPanel();
|
||||||
subpanel.setLayout(new FlowLayout());
|
subpanel.setLayout(new FlowLayout());
|
||||||
subpanel.setPreferredSize(new Dimension(700,40));
|
subpanel.setPreferredSize(new Dimension((int)(700*scaling),(int)(40*scaling)));
|
||||||
subpanel.setBackground(Color.WHITE);
|
subpanel.setBackground(Color.WHITE);
|
||||||
subpanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1));
|
subpanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1));
|
||||||
|
|
||||||
|
|
@ -361,7 +341,7 @@ public class GraphStreamViewer {
|
||||||
|
|
||||||
JLabel jobs = new JLabel(new String("jobs"));
|
JLabel jobs = new JLabel(new String("jobs"));
|
||||||
jobs.setFont(font);
|
jobs.setFont(font);
|
||||||
jobs.setPreferredSize(new Dimension(40,25));
|
jobs.setPreferredSize(new Dimension((int)(40*scaling),(int)(25*scaling)));
|
||||||
|
|
||||||
JFormattedTextField nJobs = new JFormattedTextField(this.vrp.getJobs().values().size());
|
JFormattedTextField nJobs = new JFormattedTextField(this.vrp.getJobs().values().size());
|
||||||
nJobs.setFont(font);
|
nJobs.setFont(font);
|
||||||
|
|
@ -371,7 +351,7 @@ public class GraphStreamViewer {
|
||||||
|
|
||||||
JLabel costs = new JLabel(new String("costs"));
|
JLabel costs = new JLabel(new String("costs"));
|
||||||
costs.setFont(font);
|
costs.setFont(font);
|
||||||
costs.setPreferredSize(new Dimension(40,25));
|
costs.setPreferredSize(new Dimension((int)(40*scaling),(int)(25*scaling)));
|
||||||
|
|
||||||
JFormattedTextField costsVal = new JFormattedTextField(new Double(getSolutionCosts()));
|
JFormattedTextField costsVal = new JFormattedTextField(new Double(getSolutionCosts()));
|
||||||
costsVal.setFont(font);
|
costsVal.setFont(font);
|
||||||
|
|
@ -381,7 +361,7 @@ public class GraphStreamViewer {
|
||||||
|
|
||||||
JLabel vehicles = new JLabel(new String("routes"));
|
JLabel vehicles = new JLabel(new String("routes"));
|
||||||
vehicles.setFont(font);
|
vehicles.setFont(font);
|
||||||
vehicles.setPreferredSize(new Dimension(40,25));
|
vehicles.setPreferredSize(new Dimension((int)(40*scaling),(int)(25*scaling)));
|
||||||
// vehicles.setForeground(Color.DARK_GRAY);
|
// vehicles.setForeground(Color.DARK_GRAY);
|
||||||
|
|
||||||
JFormattedTextField vehVal = new JFormattedTextField(getNuRoutes());
|
JFormattedTextField vehVal = new JFormattedTextField(getNuRoutes());
|
||||||
|
|
@ -393,7 +373,7 @@ public class GraphStreamViewer {
|
||||||
|
|
||||||
//platzhalter
|
//platzhalter
|
||||||
JLabel placeholder1 = new JLabel();
|
JLabel placeholder1 = new JLabel();
|
||||||
placeholder1.setPreferredSize(new Dimension(60,25));
|
placeholder1.setPreferredSize(new Dimension((int)(60*scaling),(int)(25*scaling)));
|
||||||
|
|
||||||
JLabel emptyLabel1 = createEmptyLabel();
|
JLabel emptyLabel1 = createEmptyLabel();
|
||||||
|
|
||||||
|
|
@ -411,12 +391,6 @@ JLabel emptyLabel1 = createEmptyLabel();
|
||||||
subpanel.add(vehicles);
|
subpanel.add(vehicles);
|
||||||
subpanel.add(vehVal);
|
subpanel.add(vehVal);
|
||||||
|
|
||||||
// subpanel.add(emptyLabel);
|
|
||||||
// subpanel.add(placeholder1);
|
|
||||||
// subpanel.add(placeholder1);
|
|
||||||
// subpanel.add(placeholder1);
|
|
||||||
// subpanel.add(placeholder1);
|
|
||||||
|
|
||||||
panel.add(subpanel);
|
panel.add(subpanel);
|
||||||
|
|
||||||
return panel;
|
return panel;
|
||||||
|
|
@ -480,16 +454,25 @@ JLabel emptyLabel1 = createEmptyLabel();
|
||||||
private void renderVehicle(Graph g, Vehicle vehicle, Label label) {
|
private void renderVehicle(Graph g, Vehicle vehicle, Label label) {
|
||||||
Node n = g.addNode(makeId(vehicle.getId(),vehicle.getLocationId()));
|
Node n = g.addNode(makeId(vehicle.getId(),vehicle.getLocationId()));
|
||||||
if(label.equals(Label.ID)) n.addAttribute("ui.label", "depot");
|
if(label.equals(Label.ID)) n.addAttribute("ui.label", "depot");
|
||||||
|
// if(label.equals(Label.ACTIVITY)) n.addAttribute("ui.label", "start");
|
||||||
n.addAttribute("x", vehicle.getCoord().getX());
|
n.addAttribute("x", vehicle.getCoord().getX());
|
||||||
n.addAttribute("y", vehicle.getCoord().getY());
|
n.addAttribute("y", vehicle.getCoord().getY());
|
||||||
n.setAttribute("ui.class", "depot");
|
n.setAttribute("ui.class", "depot");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderRoute(Graph g, VehicleRoute route, int routeId, long renderDelay_in_ms) {
|
private void renderRoute(Graph g, VehicleRoute route, int routeId, long renderDelay_in_ms, Label label) {
|
||||||
int vehicle_edgeId = 1;
|
int vehicle_edgeId = 1;
|
||||||
String prevIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getLocationId());
|
String prevIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getLocationId());
|
||||||
|
if(label.equals(Label.ACTIVITY)){
|
||||||
|
Node n = g.getNode(prevIdentifier);
|
||||||
|
n.addAttribute("ui.label", "start");
|
||||||
|
}
|
||||||
for(TourActivity act : route.getActivities()){
|
for(TourActivity act : route.getActivities()){
|
||||||
String currIdentifier = makeId(((JobActivity)act).getJob().getId(),act.getLocationId());
|
String currIdentifier = makeId(((JobActivity)act).getJob().getId(),act.getLocationId());
|
||||||
|
if(label.equals(Label.ACTIVITY)){
|
||||||
|
Node actNode = g.getNode(currIdentifier);
|
||||||
|
actNode.addAttribute("ui.label", act.getName());
|
||||||
|
}
|
||||||
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");
|
||||||
else if (act instanceof DeliveryActivity) g.getNode(currIdentifier).addAttribute("ui.class", "deliveryInRoute");
|
else if (act instanceof DeliveryActivity) g.getNode(currIdentifier).addAttribute("ui.class", "deliveryInRoute");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue