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 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); } }