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

replace deprecated methods

This commit is contained in:
oblonski 2015-03-09 21:49:30 +01:00
parent db0cdbe310
commit 62e12d5153
23 changed files with 291 additions and 327 deletions

View file

@ -65,7 +65,6 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis
public static final int CLEAR_SOLUTION = 3;
public static final int RENDER_FINAL_SOLUTION = 4;
private Graph graph;
@ -104,6 +103,7 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis
initialiseGraph(vrp);
}
@Deprecated
public AlgorithmEventsRecorder(VehicleRoutingProblem vrp, String dgsFileLocation, boolean renderShipments) {
this.renderShipments = renderShipments;
new AlgorithmEventsRecorder(vrp, dgsFileLocation);
@ -352,15 +352,15 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis
private void addVehicle(Vehicle vehicle) {
String startId = makeStartId(vehicle);
Node node = graph.addNode(startId);
node.addAttribute("x",vehicle.getStartLocationCoordinate().getX());
node.addAttribute("y",vehicle.getStartLocationCoordinate().getY());
node.addAttribute("x",vehicle.getStartLocation().getCoordinate().getX());
node.addAttribute("y", vehicle.getStartLocation().getCoordinate().getY());
node.addAttribute("ui.class","depot");
String endId = makeEndId(vehicle);
if(!startId.equals(endId)){
Node endNode = graph.addNode(endId);
endNode.addAttribute("x",vehicle.getEndLocationCoordinate().getX());
endNode.addAttribute("y",vehicle.getEndLocationCoordinate().getY());
endNode.addAttribute("x", vehicle.getEndLocation().getCoordinate().getX());
endNode.addAttribute("y", vehicle.getEndLocation().getCoordinate().getY());
endNode.addAttribute("ui.class","depot");
}
}
@ -370,7 +370,7 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis
}
private String makeEndId(Vehicle vehicle) {
if(vehicle.getStartLocationId().equals(vehicle.getEndLocationId())) return makeStartId(vehicle);
if(vehicle.getStartLocation().getId().equals(vehicle.getEndLocation().getId())) return makeStartId(vehicle);
return vehicle.getId() + "_end";
}
@ -436,15 +436,14 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis
String node_i;
if(isFirst(insertionIndex,route)) {
if(isFirst(insertionIndex)) {
node_i = makeStartId(data.getSelectedVehicle());
}
else {
TourActivity.JobActivity jobActivity = (TourActivity.JobActivity) route.getActivities().get(insertionIndex - 1);
node_i = getNodeId(jobActivity);
}
String node_k = nodeId;
String edgeId_1 = node_i + "_" + node_k;
String edgeId_1 = node_i + "_" + nodeId;
String node_j;
if(isLast(insertionIndex,route)) {
node_j = makeEndId(data.getSelectedVehicle());
@ -453,12 +452,12 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis
TourActivity.JobActivity jobActivity = (TourActivity.JobActivity) route.getActivities().get(insertionIndex);
node_j = getNodeId(jobActivity);
}
String edgeId_2 = node_k + "_" + node_j;
String edgeId_2 = nodeId + "_" + node_j;
addEdge(edgeId_1, node_i, node_k);
addEdge(edgeId_1, node_i, nodeId);
if(!(isLast(insertionIndex,route) && !data.getSelectedVehicle().isReturnToDepot())) {
addEdge(edgeId_2, node_k, node_j);
addEdge(edgeId_2, nodeId, node_j);
if (!route.getActivities().isEmpty()) {
removeEdge(node_i + "_" + node_j);
}
@ -511,7 +510,7 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis
graph.getEdge(edgeId).addAttribute("ui.class","removed");
}
private boolean isFirst(int index, VehicleRoute route) {
private boolean isFirst(int index) {
return index == 0;
}

View file

@ -112,6 +112,8 @@ public class GraphStreamViewer {
"}" ;
@SuppressWarnings("UnusedDeclaration")
public static String SIMPLE_WHITE =
"node {" +
" size: 10px, 10px;" +
@ -287,6 +289,7 @@ public class GraphStreamViewer {
return this;
}
@Deprecated
public GraphStreamViewer setEnableAutoLayout(boolean enableAutoLayout) {
return this;
}
@ -325,7 +328,7 @@ public class GraphStreamViewer {
View view = createEmbeddedView(g,scaling);
JFrame jframe = createJFrame(view,scaling);
createJFrame(view,scaling);
render(g, view);
}
@ -363,7 +366,7 @@ public class GraphStreamViewer {
//conf jframe
jframe.setSize((int)(800*scaling),(int)(580*scaling));
jframe.setLocationRelativeTo(null);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jframe.setVisible(true);
jframe.pack();
jframe.setTitle("jsprit - GraphStream");
@ -548,20 +551,19 @@ public class GraphStreamViewer {
}
private void renderVehicle(Graph g, Vehicle vehicle, Label label) {
String nodeId = makeId(vehicle.getId(),vehicle.getStartLocationId());
String nodeId = makeId(vehicle.getId(),vehicle.getStartLocation().getId());
Node vehicleStart = g.addNode(nodeId);
if(label.equals(Label.ID)) vehicleStart.addAttribute("ui.label", "depot");
// if(label.equals(Label.ACTIVITY)) n.addAttribute("ui.label", "start");
vehicleStart.addAttribute("x", vehicle.getStartLocationCoordinate().getX());
vehicleStart.addAttribute("y", vehicle.getStartLocationCoordinate().getY());
vehicleStart.addAttribute("x", vehicle.getStartLocation().getCoordinate().getX());
vehicleStart.addAttribute("y", vehicle.getStartLocation().getCoordinate().getY());
vehicleStart.setAttribute("ui.class", "depot");
if(!vehicle.getStartLocationId().equals(vehicle.getEndLocationId())){
Node vehicleEnd = g.addNode(makeId(vehicle.getId(),vehicle.getEndLocationId()));
if(!vehicle.getStartLocation().getId().equals(vehicle.getEndLocation().getId())){
Node vehicleEnd = g.addNode(makeId(vehicle.getId(),vehicle.getEndLocation().getId()));
if(label.equals(Label.ID)) vehicleEnd.addAttribute("ui.label", "depot");
// if(label.equals(Label.ACTIVITY)) n.addAttribute("ui.label", "start");
vehicleEnd.addAttribute("x", vehicle.getEndLocationCoordinate().getX());
vehicleEnd.addAttribute("y", vehicle.getEndLocationCoordinate().getY());
vehicleEnd.addAttribute("x", vehicle.getEndLocation().getCoordinate().getX());
vehicleEnd.addAttribute("y", vehicle.getEndLocation().getCoordinate().getY());
vehicleEnd.setAttribute("ui.class", "depot");
}
@ -569,7 +571,7 @@ public class GraphStreamViewer {
private void renderRoute(Graph g, VehicleRoute route, int routeId, long renderDelay_in_ms, Label label) {
int vehicle_edgeId = 1;
String prevIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getStartLocationId());
String prevIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getStartLocation().getId());
if(label.equals(Label.ACTIVITY) || label.equals(Label.JOB_NAME)){
Node n = g.getNode(prevIdentifier);
n.addAttribute("ui.label", "start");
@ -601,7 +603,7 @@ public class GraphStreamViewer {
sleep(renderDelay_in_ms);
}
if(route.getVehicle().isReturnToDepot()){
String lastIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getEndLocationId());
String lastIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getEndLocation().getId());
g.addEdge(makeEdgeId(routeId,vehicle_edgeId), prevIdentifier, lastIdentifier, true);
}
}

View file

@ -147,7 +147,7 @@ public class Plotter {
*
*/
public static enum Label {
ID, SIZE, NO_LABEL
ID, SIZE, @SuppressWarnings("UnusedDeclaration")NO_LABEL
}
private Label label = Label.SIZE;
@ -181,7 +181,7 @@ public class Plotter {
/**
* Constructs Plotter with problem. Thus only the problem can be rendered.
*
* @param vrp
* @param vrp the routing problem
*/
public Plotter(VehicleRoutingProblem vrp) {
super();
@ -191,8 +191,8 @@ public class Plotter {
/**
* Constructs Plotter with problem and solution to render them both.
*
* @param vrp
* @param solution
* @param vrp the routing problem
* @param solution the solution
*/
public Plotter(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution) {
super();
@ -204,8 +204,8 @@ public class Plotter {
/**
* Constructs Plotter with problem and routes to render individual routes.
*
* @param vrp
* @param routes
* @param vrp the routing problem
* @param routes routes
*/
public Plotter(VehicleRoutingProblem vrp, Collection<VehicleRoute> routes) {
super();
@ -214,17 +214,7 @@ public class Plotter {
plotSolutionAsWell = true;
}
/**
*
* @param show
* @return plotter
* @deprecated always true
*/
@Deprecated
public Plotter setShowFirstActivity(boolean show){
return this;
}
@SuppressWarnings("UnusedDeclaration")
public Plotter setScalingFactor(double scalingFactor){
this.scalingFactor=scalingFactor;
return this;
@ -232,8 +222,8 @@ public class Plotter {
/**
* Sets a label.
* @param label
* @return
* @param label of jobs
* @return plotter
*/
public Plotter setLabel(Label label){
this.label = label;
@ -243,12 +233,13 @@ public class Plotter {
/**
* Sets a bounding box to zoom in to certain areas.
*
* @param minX
* @param minY
* @param maxX
* @param maxY
* @param minX lower left x
* @param minY lower left y
* @param maxX upper right x
* @param maxY upper right y
* @return
*/
@SuppressWarnings("UnusedDeclaration")
public Plotter setBoundingBox(double minX, double minY, double maxX, double maxY){
boundingBox = new BoundingBox(minX,minY,maxX,maxY);
return this;
@ -257,8 +248,8 @@ public class Plotter {
/**
* Flag that indicates whether shipments should be rendered as well.
*
* @param plotShipments
* @return
* @param plotShipments flag to plot shipment
* @return the plotter
*/
public Plotter plotShipments(boolean plotShipments) {
this.plotShipments = plotShipments;
@ -287,7 +278,7 @@ public class Plotter {
private void plot(VehicleRoutingProblem vrp, final Collection<VehicleRoute> routes, String pngFile, String title){
log.info("plot to " + pngFile);
XYSeriesCollection problem = null;
XYSeriesCollection problem;
XYSeriesCollection solution = null;
final XYSeriesCollection shipments;
try {
@ -520,13 +511,13 @@ public class Plotter {
XYDataItem dataItem = new XYDataItem(s.getPickupLocation().getCoordinate().getX()*scalingFactor, s.getPickupLocation().getCoordinate().getY()*scalingFactor);
activities.add(dataItem);
addLabel(s, dataItem);
markItem(dataItem,Activity.PICKUP, job);
markItem(dataItem,Activity.PICKUP);
containsPickupAct = true;
XYDataItem dataItem2 = new XYDataItem(s.getDeliveryLocation().getCoordinate().getX()*scalingFactor, s.getDeliveryLocation().getCoordinate().getY()*scalingFactor);
activities.add(dataItem2);
addLabel(s, dataItem2);
markItem(dataItem2,Activity.DELIVERY, job);
markItem(dataItem2,Activity.DELIVERY);
containsDeliveryAct = true;
}
else if(job instanceof Pickup){
@ -535,7 +526,7 @@ public class Plotter {
XYDataItem dataItem = new XYDataItem(coord.getX()*scalingFactor, coord.getY()*scalingFactor);
activities.add(dataItem);
addLabel(service, dataItem);
markItem(dataItem, Activity.PICKUP, job);
markItem(dataItem, Activity.PICKUP);
containsPickupAct = true;
}
else if(job instanceof Delivery){
@ -544,7 +535,7 @@ public class Plotter {
XYDataItem dataItem = new XYDataItem(coord.getX()*scalingFactor, coord.getY()*scalingFactor);
activities.add(dataItem);
addLabel(service, dataItem);
markItem(dataItem, Activity.DELIVERY, job);
markItem(dataItem, Activity.DELIVERY);
containsDeliveryAct = true;
}
else if(job instanceof Service){
@ -553,7 +544,7 @@ public class Plotter {
XYDataItem dataItem = new XYDataItem(coord.getX()*scalingFactor, coord.getY()*scalingFactor);
activities.add(dataItem);
addLabel(service, dataItem);
markItem(dataItem, Activity.SERVICE, job);
markItem(dataItem, Activity.SERVICE);
containsServiceAct = true;
}
else{
@ -591,18 +582,18 @@ public class Plotter {
private void retrieveActivities(VehicleRoutingProblem vrp) throws NoLocationFoundException{
activities = new XYSeries("activities", false, true);
for(Vehicle v : vrp.getVehicles()){
Coordinate startCoord = v.getStartLocationCoordinate();
if(startCoord == null) throw new NoLocationFoundException();
XYDataItem item = new XYDataItem(startCoord.getX()*scalingFactor, startCoord.getY()*scalingFactor);
markItem(item,Activity.START, null);
Coordinate start_coordinate = v.getStartLocation().getCoordinate();
if(start_coordinate == null) throw new NoLocationFoundException();
XYDataItem item = new XYDataItem(start_coordinate.getX()*scalingFactor, start_coordinate.getY()*scalingFactor);
markItem(item,Activity.START);
activities.add(item);
if(!v.getStartLocationId().equals(v.getEndLocationId())){
Coordinate endCoord = v.getEndLocationCoordinate();
if(endCoord == null) throw new NoLocationFoundException();
XYDataItem enditem = new XYDataItem(endCoord.getX()*scalingFactor,endCoord.getY()*scalingFactor);
markItem(enditem,Activity.END, null);
activities.add(enditem);
if(!v.getStartLocation().getId().equals(v.getEndLocation().getId())){
Coordinate end_coordinate = v.getEndLocation().getCoordinate();
if(end_coordinate == null) throw new NoLocationFoundException();
XYDataItem end_item = new XYDataItem(end_coordinate.getX()*scalingFactor,end_coordinate.getY()*scalingFactor);
markItem(end_item,Activity.END);
activities.add(end_item);
}
}
for(Job job : vrp.getJobs().values()){
@ -615,7 +606,7 @@ public class Plotter {
}
}
private void markItem(XYDataItem item, Activity activity, Job job) {
private void markItem(XYDataItem item, Activity activity) {
activitiesByDataItem.put(item,activity);
}