private void markEdgeInserted(String edgeId) { graph.getEdge(edgeId).addAttribute("ui.class", "inserted"); graph.getEdge(edgeId).removeAttribute("ui.class"); }
private void markEdgeRemoved(String edgeId) { graph.getEdge(edgeId).addAttribute("ui.class", "removed"); }
private void markPickup(String id) { graph.getNode(id).addAttribute("ui.class", "pickup"); }
private void renderShipment(Graph g, Shipment shipment, Label label, boolean renderShipments) { Node n1 = g.addNode(makeId(shipment.getId(), shipment.getPickupLocation().getId())); if (label.equals(Label.ID)) n1.addAttribute("ui.label", shipment.getId()); n1.addAttribute("x", shipment.getPickupLocation().getCoordinate().getX()); n1.addAttribute("y", shipment.getPickupLocation().getCoordinate().getY()); n1.setAttribute("ui.class", "pickup"); Node n2 = g.addNode(makeId(shipment.getId(), shipment.getDeliveryLocation().getId())); if (label.equals(Label.ID)) n2.addAttribute("ui.label", shipment.getId()); n2.addAttribute("x", shipment.getDeliveryLocation().getCoordinate().getX()); n2.addAttribute("y", shipment.getDeliveryLocation().getCoordinate().getY()); n2.setAttribute("ui.class", "delivery"); if (renderShipments) { 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 removeNodeAndBelongingEdges(String nodeId, VehicleRoute fromRoute) { Node node = graph.getNode(nodeId); markRemoved(node); Edge entering = getEnteringEdge(nodeId); removeEdge(entering.getId()); if (node.getLeavingEdgeSet().isEmpty()) { if (fromRoute.getVehicle().isReturnToDepot()) throw new IllegalStateException("leaving edge is missing"); return; } Edge leaving = getLeavingEdge(nodeId); removeEdge((leaving.getId())); Node from = entering.getNode0(); Node to = leaving.getNode1(); if (!fromRoute.getActivities().isEmpty()) { addEdge(makeEdgeId(from, to), from.getId(), to.getId()); } }
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 void addNode(String nodeId, Coordinate nodeCoord) { Node node = graph.addNode(nodeId); node.addAttribute("x", nodeCoord.getX()); node.addAttribute("y", nodeCoord.getY()); }
private Edge getLeavingEdge(String toNodeId) { Collection<Edge> edges = graph.getNode(toNodeId).getLeavingEdgeSet(); if (edges.size() == 1) return edges.iterator().next(); else { for (Edge e : edges) { if (e.getId().startsWith("shipment")) { continue; } return e; } } return null; }
public static Graph createMultiGraph(String name, String style) { Graph g = new MultiGraph(name); g.addAttribute("ui.quality"); g.addAttribute("ui.antialias"); g.addAttribute("ui.stylesheet", style); return g; }
private Edge getEnteringEdge(String toNodeId) { Collection<Edge> enteringEdges = graph.getNode(toNodeId).getEnteringEdgeSet(); if (enteringEdges.size() == 1) return enteringEdges.iterator().next(); else { for (Edge e : enteringEdges) { if (e.getId().startsWith("shipment")) { continue; } return e; } } return null; }
private void addJob(Job job) { if (job instanceof Service) { Service service = (Service) job; addNode(service.getId(), service.getLocation().getCoordinate()); markService(service); } else if (job instanceof Shipment) { Shipment shipment = (Shipment) job; String fromNodeId = getFromNodeId(shipment); addNode(fromNodeId, shipment.getPickupLocation().getCoordinate()); String toNodeId = getToNodeId(shipment); addNode(toNodeId, shipment.getDeliveryLocation().getCoordinate()); markShipment(shipment); if (renderShipments) { Edge e = graph.addEdge("shipment_" + fromNodeId + "_" + toNodeId, fromNodeId, toNodeId, true); e.addAttribute("ui.class", "shipment"); } } }
private void markRemoved(Node node) { node.setAttribute("ui.class", "removed"); }
@Override public void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) { if (!record()) return; fileSink.stepBegins(graph.getId(), 0, RECREATE); } }
private void removeEdge(String edgeId) { markEdgeRemoved(edgeId); graph.removeEdge(edgeId); }
private void addEdge(String edgeId, String fromNode, String toNode) { graph.addEdge(edgeId, fromNode, toNode, true); markEdgeInserted(edgeId); }
private void markDelivery(String id) { graph.getNode(id).addAttribute("ui.class", "delivery"); }
private void addVehicle(Vehicle vehicle) { String startId = makeStartId(vehicle); Node node = graph.addNode(startId); 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.getEndLocation().getCoordinate().getX()); endNode.addAttribute("y", vehicle.getEndLocation().getCoordinate().getY()); endNode.addAttribute("ui.class", "depot"); } }
@Override public void informInsertionEnds(Collection<VehicleRoute> vehicleRoutes) { if (!record()) return; fileSink.stepBegins(graph.getId(), 0, CLEAR_SOLUTION); removeRoutes(vehicleRoutes); }