@Override protected void relaxNode(final Node outNode, final Node toNode, final RouterPriorityQueue<Node> pendingNodes) { this.controlCounter++; if (this.controlCounter == controlInterval) { int newLandmarkIndex = checkToAddLandmark(outNode, toNode); if (newLandmarkIndex > 0) { updatePendingNodes(newLandmarkIndex, toNode, pendingNodes); } this.controlCounter = 0; } super.relaxNode(outNode, toNode, pendingNodes); }
final PreProcessLandmarks.LandmarksData fromData = getPreProcessData(fromNode); final PreProcessLandmarks.LandmarksData toData = getPreProcessData(toNode); tmpTravTime = estimateRemainingTravelCost(fromData, toData, i); for (int j = 0; j < estTravelTimes.length; j++) { if (tmpTravTime > estTravelTimes[j]) {
@Override public Path calcLeastCostPath(final Node fromNode, final Node toNode, final double startTime, final Person person, final Vehicle vehicle) { this.controlCounter = 0; // reset counter for each calculated path! if (this.landmarks.length >= 2) { initializeActiveLandmarks(fromNode, toNode, 2); } else { initializeActiveLandmarks(fromNode, toNode, this.landmarks.length); } return super.calcLeastCostPath(fromNode, toNode, startTime, person, vehicle); }
PreProcessLandmarks.LandmarksData toRole = getPreProcessData(toNode); List<Double> newEstRemTravCosts = new ArrayList<>(); List<Node> nodesToBeUpdated = new ArrayList<>(); while (it.hasNext()) { Node node = it.next(); AStarNodeData data = getData(node); PreProcessLandmarks.LandmarksData ppRole = getPreProcessData(node); double estRemTravCost = data.getExpectedRemainingCost(); double newEstRemTravCost = estimateRemainingTravelCost(ppRole, toRole, newLandmarkIndex); if (newEstRemTravCost > estRemTravCost) { nodesToBeUpdated.add(node); AStarNodeData data = getData(node); data.setExpectedRemainingCost(newEstRemTravCosts.get(i)); pendingNodes.add(node, getPriority(data));
@Override public synchronized LeastCostPathCalculator createPathCalculator(final Network network, final TravelDisutility travelCosts, final TravelTime travelTimes) { PreProcessLandmarks preProcessLandmarks = this.preProcessData.get(network); if (preProcessLandmarks == null) { preProcessLandmarks = new PreProcessLandmarks(travelCosts); preProcessLandmarks.setNumberOfThreads(nThreads); preProcessLandmarks.run(network); this.preProcessData.put(network, preProcessLandmarks); } final double overdoFactor = 1.0; return new AStarLandmarks(network, preProcessLandmarks, travelCosts, travelTimes, overdoFactor); } }
@Override /*package*/ RouterPriorityQueue<? extends Node> createRouterPriorityQueue() { /* * Re-use existing BinaryMinHeap instead of creating a new one. For large networks (> 10^6 nodes and links) this reduced * the computation time by 40%! cdobler, oct'15 */ if (this.routingNetwork instanceof ArrayRoutingNetwork) { int size = this.routingNetwork.getNodes().size(); if (this.heap == null || this.maxSize != size) { this.maxSize = size; this.heap = new BinaryMinHeap<>(maxSize); return this.heap; } else { this.heap.reset(); return this.heap; } } else { return super.createRouterPriorityQueue(); } }
@Override public Path calcLeastCostPath(final Node fromNode, final Node toNode, final double startTime, final Person person, final Vehicle vehicle) { this.fastRouter.initialize(); this.routingNetwork.initialize(); RoutingNetworkNode routingNetworkFromNode = routingNetwork.getNodes().get(fromNode.getId()); RoutingNetworkNode routingNetworkToNode = routingNetwork.getNodes().get(toNode.getId()); return super.calcLeastCostPath(routingNetworkFromNode, routingNetworkToNode, startTime, person, vehicle); }
@Override protected LeastCostPathCalculator getLeastCostPathCalculator(Network network) { FreespeedTravelTimeAndDisutility travelTimeCostCalculator = new FreespeedTravelTimeAndDisutility(new PlanCalcScoreConfigGroup()); PreProcessLandmarks preProcessData = new PreProcessLandmarks(travelTimeCostCalculator); preProcessData.run(network); return new AStarLandmarks(network, preProcessData, travelTimeCostCalculator); }
/** * Checks whether there is a landmark in the set of the non-active landmarks that yields a better estimation than * the best active landmark. If there is, this landmark is added to the set of active landmark and its index is returned. * * @param fromNode The node for which we estimate the remaining travel time to the toNode. * @param toNode The target node. * @return The index of the landmark that has been added to the set of active landmarks, or -1 if no landmark was added. */ /*package*/ int checkToAddLandmark(final Node fromNode, final Node toNode) { double bestTravCostEst = estimateRemainingTravelCost(fromNode, toNode); PreProcessLandmarks.LandmarksData fromRole = getPreProcessData(fromNode); PreProcessLandmarks.LandmarksData toRole = getPreProcessData(toNode); int bestIndex = -1; for (int i = 0; i < this.landmarks.length; i++) { double tmpTravTime = estimateRemainingTravelCost(fromRole, toRole, i); if (tmpTravTime > bestTravCostEst) { bestIndex = i; bestTravCostEst = tmpTravTime; } } if (bestIndex != -1) { int[] newActiveLandmarks = new int[this.activeLandmarkIndexes.length + 1]; System.arraycopy(this.activeLandmarkIndexes, 0, newActiveLandmarks, 0, this.activeLandmarkIndexes.length); newActiveLandmarks[this.activeLandmarkIndexes.length] = bestIndex; this.activeLandmarkIndexes = newActiveLandmarks; } return bestIndex; }
/** * Estimates the remaining travel cost from fromNode to toNode using the landmarks on the network. * * @param fromNode The first node. * @param toNode The second node. * @return The travel cost when traveling between the two given nodes. */ @Override protected double estimateRemainingTravelCost(final Node fromNode, final Node toNode) { PreProcessLandmarks.LandmarksData fromRole = getPreProcessData(fromNode); PreProcessLandmarks.LandmarksData toRole = getPreProcessData(toNode); double tmpTravCost; double travCost = 0; for (int i = 0, n = this.activeLandmarkIndexes.length; i < n; i++) { tmpTravCost = estimateRemainingTravelCost(fromRole, toRole, this.activeLandmarkIndexes[i]); if (tmpTravCost > travCost) { travCost = tmpTravCost; } } tmpTravCost = super.estimateRemainingTravelCost(fromNode, toNode); if (travCost > tmpTravCost) { return travCost; } /* else */ return tmpTravCost; }