@Override protected Path constructPath(Node fromNode, Node toNode, double startTime, double arrivalTime) { ArrayList<Node> nodes = new ArrayList<Node>(); ArrayList<Link> links = new ArrayList<Link>(); nodes.add(0, toNode); Link tmpLink = getData(toNode).getPrevLink(); // Only this part has been adapted. Could probably also be changed in the super class. while (tmpLink != null) { links.add(0, tmpLink); nodes.add(0, tmpLink.getFromNode()); tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); } // Ignore the initial time and cost of the start node! DijkstraNodeData startNodeData = getData(nodes.get(0)); DijkstraNodeData toNodeData = getData(toNode); Path path = new Path(nodes, links, toNodeData.getTime() - startNodeData.getTime(), toNodeData.getCost() - startNodeData.getCost()); // double travelTime = arrivalTime - startTime; // Path path = new Path(nodes, links, travelTime, toNodeData.getCost()); return path; }
@Override protected void visitNode(final Node n, final DijkstraNodeData data, final RouterPriorityQueue<Node> pendingNodes, final double time, final double cost, final Link outLink) { data.visit(outLink, cost, time, this.iterationID); //if (outLink != null) log.info("OutLink: " + outLink.getId()+ " Node " + n.getId() + " costs " + cost + " time " + time/60.0); pendingNodes.add(n, getPriority(data)); }
@Override public NodeData createNodeData() { return new DijkstraNodeData(); } }
/** * Expands the given Node in the routing algorithm; may be overridden in * sub-classes. * * @param outNode * The Node to be expanded. * @param pendingNodes * The set of pending nodes so far. */ protected void relaxNode(final Node outNode, final RouterPriorityQueue<Node> pendingNodes) { DijkstraNodeData outData = getData(outNode); double currTime = outData.getTime(); double currCost = outData.getCost(); for (Link l : outNode.getOutLinks().values()) { relaxNodeLogic(l, pendingNodes, currTime, currCost); } }
@Override protected Path constructPath(Node fromNode, Node toNode, double startTime, double arrivalTime) { LinkedList<Link> links = new LinkedList<>(); Link tmpLink = getData(toNode).getPrevLink(); if (tmpLink != null) { while (tmpLink.getFromNode() != fromNode) { links.add(tmpLink); tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); } links.add(tmpLink); } return new Path(null, ImmutableList.copyOf(links.descendingIterator()), arrivalTime - startTime, getData(toNode).getCost()); } }
final double travelCost = this.costFunction.getLinkTravelDisutility(l, currTime, this.person, this.vehicle); final DijkstraNodeData data = getData(n); if (!data.isVisited(getIterationId())) { visitNode(n, data, pendingNodes, currTime + travelTime, currCost + travelCost, l); return true; final double nCost = data.getCost(); final double totalCost = currCost + travelCost; if (totalCost < nCost) { Link prevLink = data.getPrevLink(); if (prevLink != null && prevLink.getId().compareTo(l.getId()) > 0) { revisitNode(n, data, pendingNodes, currTime + travelTime, totalCost, l);
/** * This method should only be called from outside after calcLeastCostPath(...) has * been executed. After that, the paths between the multiple start and/or end nodes * can be constructed using this method. * * Is there a way to check whether this method is called as intended?? * cdobler, oct'13 */ public Path constructPath(Node fromNode, Node toNode, double startTime) { if (toNode == null || fromNode == null) return null; else { DijkstraNodeData toData = getData(toNode); if (!toData.isVisited(this.getIterationId())) return null; DijkstraNodeData fromData = getData(fromNode); if (!fromData.isVisited(this.getIterationId())) return null; double arrivalTime = toData.getTime(); // now construct and return the path return constructPath(fromNode, toNode, startTime, arrivalTime); } }
/** * The value used to sort the pending nodes during routing. * This implementation compares the total effective travel cost * to sort the nodes in the pending nodes queue during routing. */ protected double getPriority(final DijkstraNodeData data) { return data.getCost(); }
public double getTime(Node toNode) { return getData(toNode).getTime(); }
Link tmpLink = getData(toNode).getPrevLink(); if (tmpLink != null) { while (tmpLink.getFromNode() != fromNode) { links.add(((RoutingNetworkLink) tmpLink).getLink()); nodes.add(((RoutingNetworkLink) tmpLink).getLink().getToNode()); tmpLink = getData(tmpLink.getFromNode()).getPrevLink();
/** * Resets all nodes in the network as if they have not been visited yet. */ private void resetNetworkVisited() { for (Node node : this.network.getNodes().values()) { DijkstraNodeData data = getData(node); data.resetVisited(); } }
/** * Expands the given Node in the routing algorithm; may be overridden in * sub-classes. * * @param outNode * The Node to be expanded. * @param toNode * The target Node of the route. * @param pendingNodes * The set of pending nodes so far. */ protected void relaxNode(final Node outNode, final Node toNode, final RouterPriorityQueue<Node> pendingNodes) { DijkstraNodeData outData = getData(outNode); double currTime = outData.getTime(); double currCost = outData.getCost(); if (this.pruneDeadEnds) { PreProcessDijkstra.DeadEndData ddOutData = getPreProcessData(outNode); for (Link l : outNode.getOutLinks().values()) { relaxNodeLogic(l, pendingNodes, currTime, currCost, toNode, ddOutData); } } else { // this.pruneDeadEnds == false for (Link l : outNode.getOutLinks().values()) { relaxNodeLogic(l, pendingNodes, currTime, currCost, toNode, null); } } }
/** * Constructs the path after the algorithm has been run. * * @param fromNode * The node where the path starts. * @param toNode * The node where the path ends. * @param startTime * The time when the trip starts. */ protected Path constructPath(Node fromNode, Node toNode, double startTime, double arrivalTime) { List<Node> nodes = new ArrayList<>(); List<Link> links = new ArrayList<>(); nodes.add(0, toNode); Link tmpLink = getData(toNode).getPrevLink(); if (tmpLink != null) { while (tmpLink.getFromNode() != fromNode) { links.add(0, tmpLink); nodes.add(0, tmpLink.getFromNode()); tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); } links.add(0, tmpLink); nodes.add(0, tmpLink.getFromNode()); } DijkstraNodeData toNodeData = getData(toNode); Path path = new Path(nodes, links, arrivalTime - startTime, toNodeData.getCost()); return path; }
double travelCost = this.costFunction.getLinkTravelDisutility(l, currTime, this.person, this.vehicle, this.customDataManager); DijkstraNodeData data = getData(n); double nCost = data.getCost(); if (!data.isVisited(getIterationId())) { visitNode(n, data, pendingNodes, currTime + travelTime, currCost + travelCost, l); this.customDataManager.storeTmpData();
/** * The value used to sort the pending nodes during routing. * This implementation compares the total effective travel cost * to sort the nodes in the pending nodes queue during routing. */ protected double getPriority(final DijkstraNodeData data) { return data.getCost(); }
public Path getLeastCostPath(Node toNode) { return constructPath(fromNode, toNode, startTime, getData(toNode).getTime()); }
/** * Resets all nodes in the network as if they have not been visited yet. */ private void resetNetworkVisited() { for (Node node : this.network.getNodes().values()) { DijkstraNodeData data = getData(node); data.resetVisited(); } }
@Override public Path calcLeastCostPath(final Node fromNode, final Node toNode, final double startTime, final Person person, final Vehicle vehicle) { // yyyyyy could you please explain why this needs to be re-implemented? I would feel better if this would just use the method of // the original class. kai, jan'13 // now construct the path ArrayList<Node> nodes = new ArrayList<Node>(); ArrayList<Link> links = new ArrayList<Link>(); nodes.add(0, toNode); Link tmpLink = getData(toNode).getPrevLink(); if (tmpLink != null) { while (tmpLink.getFromNode() != fromNode) { links.add(0, tmpLink); nodes.add(0, tmpLink.getFromNode()); tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); } links.add(0, tmpLink); nodes.add(0, tmpLink.getFromNode()); } // arrival time was not ok in earlier versions! DijkstraNodeData toNodeData = getData(toNode); double arrivalTime = toNodeData.getTime(); Path path = new Path(nodes, links, arrivalTime - startTime, toNodeData.getCost()); return path; }