@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 void run(final Network network) { super.run(network); if (!checkLinkLengths(network)) { log.warn("There are links with stored length smaller than their Euclidean distance in this network. Thus, A* cannot guarantee to calculate the least-cost paths between two nodes."); } updateMinTravelCostPerLength(network); }
/** * @param network Where we do the routing. * @param preProcessData The pre-process data (containing the landmarks etc.). * @param timeFunction Determines the travel time on each link. * @param overdoFactor The factor which is multiplied with the output of the A* heuristic function. The higher * the overdo factor the greedier the router, i.e. it visits less nodes during routing and is thus faster, but * for an overdo factor > 1, it is not guaranteed that the router returns the least-cost paths. Rather it tends * to return distance-minimal paths. */ AStarEuclidean(final Network network, final PreProcessEuclidean preProcessData, final TravelTime timeFunction, final double overdoFactor) { this(network, preProcessData, preProcessData.getCostFunction(), timeFunction, overdoFactor); }
private void updateMinTravelCostPerLength(final Network network) { for (Link link : network.getLinks().values()) { double minCost = this.costFunction.getLinkMinimumTravelDisutility(link) / link.getLength(); if (getMinTravelCostPerLength() > minCost) { setMinTravelCostPerLength(minCost); } } }
@Override public synchronized LeastCostPathCalculator createPathCalculator(final Network network, final TravelDisutility travelCosts, final TravelTime travelTimes) { RoutingNetwork routingNetwork = this.routingNetworks.get(network); PreProcessEuclidean preProcessEuclidean = this.preProcessData.get(network); if (routingNetwork == null) { routingNetwork = this.routingNetworkFactory.createRoutingNetwork(network); if (preProcessEuclidean == null) { preProcessEuclidean = new PreProcessEuclidean(travelCosts); preProcessEuclidean.run(network); this.preProcessData.put(network, preProcessEuclidean); for (RoutingNetworkNode node : routingNetwork.getNodes().values()) { node.setDeadEndData(preProcessEuclidean.getNodeData(node.getNode())); } } this.routingNetworks.put(network, routingNetwork); } FastRouterDelegateFactory fastRouterFactory = new ArrayFastRouterDelegateFactory(); return new FastAStarEuclidean(routingNetwork, preProcessEuclidean, travelCosts, travelTimes, overdoFactor, fastRouterFactory); } }
@Override public void run(final Network network) { super.run(network);
/** * @param network Where we do the routing. * @param preProcessData The pre-process data (containing the landmarks etc.). * @param timeFunction Determines the travel time on each link. * @param costFunction Calculates the travel cost on links. * @param overdoFactor The factor which is multiplied with the output of the A* heuristic function. The higher * the overdo factor the greedier the router, i.e. it visits less nodes during routing and is thus faster, but * for an overdo factor > 1, it is not guaranteed that the router returns the least-cost paths. Rather it tends * to return distance-minimal paths. */ AStarEuclidean(final Network network, final PreProcessEuclidean preProcessData, final TravelDisutility costFunction, final TravelTime timeFunction, final double overdoFactor) { super(network, costFunction, timeFunction, preProcessData); setMinTravelCostPerLength(preProcessData.getMinTravelCostPerLength()); this.overdoFactor = overdoFactor; }
@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); }
@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 }
@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 }