/** * 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(); } }
private void expandNodeData(final Map<Node, InitialNode> toNodes) { Set<Node> endNodes = new HashSet<>(toNodes.keySet()); double minCost = Double.POSITIVE_INFINITY; // do the real work while (endNodes.size() > 0) { Node outNode = pendingNodes.poll(); if (outNode == null) { // seems we have no more nodes left, but not yet reached all endNodes... endNodes.clear(); } else { DijkstraNodeData data = getData(outNode); boolean isEndNode = endNodes.remove(outNode); if (isEndNode) { InitialNode initData = toNodes.get(outNode); double cost = data.getCost() + initData.initialCost; if (cost < minCost) { minCost = cost; } } if (data.getCost() > minCost) { endNodes.clear(); // we can't get any better now } else { relaxNode(outNode, pendingNodes); } } } }
public TransitLeastCostPathTree(final Network network, final TransitTravelDisutility costFunction, final TravelTime timeFunction, final Map<Node, InitialNode> fromNodes, final Map<Node, InitialNode> toNodes, final Person person) { this.network = network; this.costFunction = costFunction; this.timeFunction = timeFunction; this.nodeData = new HashMap<>((int)(network.getNodes().size() * 1.1), 0.95f); //create tree this.resetNetworkVisited(); this.person = person; this.customDataManager.reset(); this.fromNodes = fromNodes; pendingNodes = (RouterPriorityQueue<Node>) createRouterPriorityQueue(); for (Map.Entry<Node, InitialNode> entry : fromNodes.entrySet()) { DijkstraNodeData data = getData(entry.getKey()); visitNode(entry.getKey(), data, pendingNodes, entry.getValue().initialTime, entry.getValue().initialCost, null); } expandNodeData(toNodes); }
expandNodeData(toNodes); DijkstraNodeData data = getData(currentNode); InitialNode initData = e.getValue(); double cost = data.getCost() + initData.initialCost; Link tmpLink = getData(minCostNode).getPrevLink(); while (tmpLink != null) { links.add(0, tmpLink); nodes.add(0, tmpLink.getFromNode()); tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); DijkstraNodeData startNodeData = getData(nodes.get(0)); DijkstraNodeData toNodeData = getData(minCostNode);
public TransitLeastCostPathTree(final Network network, final TransitTravelDisutility costFunction, final TravelTime timeFunction, final Map<Node, InitialNode> fromNodes, final Person person) { this.network = network; this.costFunction = costFunction; this.timeFunction = timeFunction; this.nodeData = new HashMap<>((int)(network.getNodes().size() * 1.1), 0.95f); //create tree this.resetNetworkVisited(); this.person = person; this.customDataManager.reset(); this.fromNodes = fromNodes; pendingNodes = (RouterPriorityQueue<Node>) createRouterPriorityQueue(); for (Map.Entry<Node, InitialNode> entry : fromNodes.entrySet()) { DijkstraNodeData data = getData(entry.getKey()); visitNode(entry.getKey(), data, pendingNodes, entry.getValue().initialTime, entry.getValue().initialCost, null); } // do the real work while (pendingNodes.size() > 0) { Node outNode = pendingNodes.poll(); relaxNode(outNode, pendingNodes); } }
/** * 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); } }
expandNodeData(toNodes); DijkstraNodeData data = getData(currentNode); InitialNode initData = e.getValue(); double cost = data.getCost() + initData.initialCost; TransitRouterNetworkLink link = (TransitRouterNetworkLink) getData(minCostNode).getPrevLink(); TransitRouterNetworkLink downstreamLink = null; Node previousFromNode = minCostNode; TransitRouterNetworkNode toNode = link.toNode; double travelTime = getData(toNode).getTime() - getData(fromNode).getTime(); Id<TransitLine> transitLineId = null; Id<TransitRoute> routeId = null; link = (TransitRouterNetworkLink) getData(fromNode).getPrevLink(); DijkstraNodeData startNodeData = getData(previousFromNode); DijkstraNodeData toNodeData = getData(minCostNode);
double travelTime = this.timeFunction.getLinkTravelTime(l, currTime, this.person, this.vehicle); 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())) {