@Override public synchronized LeastCostPathCalculator createPathCalculator(final Network network, final TravelDisutility travelCosts, final TravelTime travelTimes) { PreProcessEuclidean preProcessEuclidean = this.preProcessData.get(network); if (preProcessEuclidean == null) { preProcessEuclidean = new PreProcessEuclidean(travelCosts); preProcessEuclidean.run(network); this.preProcessData.put(network, preProcessEuclidean); } return new AStarEuclidean(network, preProcessEuclidean, travelCosts, travelTimes, overdoFactor); } }
@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); }
/** * Initializes the first node of a route. * * @param fromNode * The Node to be initialized. * @param toNode * The Node at which the route should end. * @param pendingNodes * The pending nodes so far. * @param toNode * The Node at which the route should end. * @param startTime * The time we start routing. */ @Override protected void initFromNode(final Node fromNode, final Node toNode, final double startTime, final RouterPriorityQueue<Node> pendingNodes) { AStarNodeData data = getData(fromNode); visitNode(fromNode, data, pendingNodes, startTime, 0, null); data.setExpectedRemainingCost(estimateRemainingTravelCost(fromNode, toNode)); }
final AStarNodeData data = getData(n); if (!data.isVisited(getIterationId())) { double remainingTravelCost = estimateRemainingTravelCost(n, toNode); visitNode(n, data, pendingNodes, currTime + travelTime, currCost + travelCost, remainingTravelCost, l); return true; final double totalCost = currCost + travelCost; if (totalCost < nCost) { revisitNode(n, data, pendingNodes, currTime + travelTime, totalCost, l); return true; } else if (totalCost == nCost) { revisitNode(n, data, pendingNodes, currTime + travelTime, totalCost, l); return true;
@Test public void testPersonAvailableForDisutility_AStarEuclidean() { Fixture f = new Fixture(); PreProcessEuclidean preprocess = new PreProcessEuclidean(f.costFunction); preprocess.run(f.network); AStarEuclidean router = new AStarEuclidean(f.network, preprocess, new FreeSpeedTravelTime()); router.calcLeastCostPath( f.network.getNodes().get(Id.create("2", Node.class)), f.network.getNodes().get(Id.create("1", Node.class)), 07*3600, f.person, f.vehicle); // hopefully there was no Exception until here... Assert.assertEquals(22, f.costFunction.cnt); // make sure the costFunction was actually used }
@Override protected PreProcessLandmarks.LandmarksData getPreProcessData(final Node n) { return (PreProcessLandmarks.LandmarksData) super.getPreProcessData(n); }
@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); }
/** * Estimates the remaining travel cost from fromNode to toNode using the euclidean distance between them. * * @param fromNode The first node. * @param toNode The second node. * @return The travel cost when traveling between the two given nodes. */ protected double estimateRemainingTravelCost(final Node fromNode, final Node toNode) { double dist = CoordUtils.calcEuclideanDistance(fromNode.getCoord(), toNode.getCoord()) * getMinTravelCostPerLength(); return dist * this.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; } // int maxSize = this.routingNetwork.getNodes().size(); // return new BinaryMinHeap<ArrayRoutingNetworkNode>(maxSize); } else { return super.createRouterPriorityQueue(); } }
/** * 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; }
@Test public void testPersonAvailableForDisutility_FastAStarEuclidean() { Fixture f = new Fixture(); PreProcessEuclidean preprocess = new PreProcessEuclidean(f.costFunction); preprocess.run(f.network); AStarEuclidean router = new AStarEuclidean(f.network, preprocess, new FreeSpeedTravelTime()); router.calcLeastCostPath( f.network.getNodes().get(Id.create("2", Node.class)), f.network.getNodes().get(Id.create("1", Node.class)), 07*3600, f.person, f.vehicle); // hopefully there was no Exception until here... Assert.assertEquals(22, f.costFunction.cnt); // make sure the costFunction was actually used }
@Override protected LeastCostPathCalculator getLeastCostPathCalculator(Network network) { FreespeedTravelTimeAndDisutility travelTimeCostCalculator = new FreespeedTravelTimeAndDisutility(new PlanCalcScoreConfigGroup()); PreProcessEuclidean preProcessData = new PreProcessEuclidean(travelTimeCostCalculator); preProcessData.run(network); return new AStarEuclidean(network, preProcessData, travelTimeCostCalculator); }
@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 = this.routingNetwork.getNodes().get(fromNode.getId()); RoutingNetworkNode routingNetworkToNode = this.routingNetwork.getNodes().get(toNode.getId()); return super.calcLeastCostPath(routingNetworkFromNode, routingNetworkToNode, startTime, person, vehicle); }