public static WeightApproximator getApproximation(String prop, AlgorithmOptions opts, NodeAccess na) { String approxAsStr = opts.getHints().get(prop + ".approximation", "BeelineSimplification"); double epsilon = opts.getHints().getDouble(prop + ".epsilon", 1); BeelineWeightApproximator approx = new BeelineWeightApproximator(na, opts.getWeighting()); approx.setEpsilon(epsilon); if ("BeelineSimplification".equals(approxAsStr)) approx.setDistanceCalc(Helper.DIST_PLANE); else if ("BeelineAccurate".equals(approxAsStr)) approx.setDistanceCalc(Helper.DIST_EARTH); else throw new IllegalArgumentException("Approximation " + approxAsStr + " not found in " + RoutingAlgorithmFactorySimple.class.getName()); return approx; } }
private AbstractBidirAlgo doCreateAlgo(Graph graph, AlgorithmOptions opts) { if (ASTAR_BI.equals(opts.getAlgorithm())) { return new AStarBidirectionCH(graph, prepareWeighting, traversalMode) .setApproximation(RoutingAlgorithmFactorySimple.getApproximation(ASTAR_BI, opts, graph.getNodeAccess())); } else if (DIJKSTRA_BI.equals(opts.getAlgorithm())) { if (opts.getHints().getBool("stall_on_demand", true)) { return new DijkstraBidirectionCH(graph, prepareWeighting, traversalMode); } else { return new DijkstraBidirectionCHNoSOD(graph, prepareWeighting, traversalMode); } } else { throw new IllegalArgumentException("Algorithm " + opts.getAlgorithm() + " not supported for Contraction Hierarchies. Try with ch.disable=true"); } }
public RoutingAlgorithm getDecoratedAlgorithm(Graph qGraph, RoutingAlgorithm algo, AlgorithmOptions opts) { int activeLM = Math.max(1, opts.getHints().getInt(Landmark.ACTIVE_COUNT, defaultActiveLandmarks)); if (algo instanceof AStar) { if (!lms.isInitialized()) throw new IllegalStateException("Initialize landmark storage before creating algorithms"); double epsilon = opts.getHints().getDouble(Parameters.Algorithms.AStar.EPSILON, 1); AStar astar = (AStar) algo; astar.setApproximation(new LMApproximator(qGraph, this.graph.getNodes(), lms, activeLM, lms.getFactor(), false). throw new IllegalStateException("Initialize landmark storage before creating algorithms"); double epsilon = opts.getHints().getDouble(Parameters.Algorithms.AStarBi.EPSILON, 1); AStarBidirection astarbi = (AStarBidirection) algo; astarbi.setApproximation(new LMApproximator(qGraph, this.graph.getNodes(), lms, activeLM, lms.getFactor(), false). throw new IllegalStateException("Initialize landmark storage before creating algorithms"); double epsilon = opts.getHints().getDouble(Parameters.Algorithms.AStarBi.EPSILON, 1); AlternativeRoute altRoute = (AlternativeRoute) algo; altRoute.setApproximation(new LMApproximator(qGraph, this.graph.getNodes(), lms, activeLM, lms.getFactor(), false).
altRouteAlgo.setMaxPaths(opts.getHints().getInt(MAX_PATHS, 2)); altRouteAlgo.setMaxWeightFactor(opts.getHints().getDouble(MAX_WEIGHT, 1.4)); altRouteAlgo.setMaxShareFactor(opts.getHints().getDouble(MAX_SHARE, 0.6)); altRouteAlgo.setMinPlateauFactor(opts.getHints().getDouble("alternative_route.min_plateau_factor", 0.2)); altRouteAlgo.setMaxExplorationFactor(opts.getHints().getDouble("alternative_route.max_exploration_factor", 1)); ra = altRouteAlgo;
@Override public List<Path> calcPaths(QueryGraph queryGraph, RoutingAlgorithmFactory algoFactory, AlgorithmOptions algoOpts) { pathList = new ArrayList<>(queryResults.size() - 1); AvoidEdgesWeighting avoidPathWeighting = new AvoidEdgesWeighting(algoOpts.getWeighting()); avoidPathWeighting.setEdgePenaltyFactor(5); algoOpts = AlgorithmOptions.start(algoOpts). algorithm(Parameters.Algorithms.ASTAR_BI). weighting(avoidPathWeighting).build(); algoOpts.getHints().put(Algorithms.AStarBi.EPSILON, 2); long visitedNodesSum = 0L; QueryResult start = queryResults.get(0); for (int qrIndex = 1; qrIndex < queryResults.size(); qrIndex++) { RoutingAlgorithm algo = algoFactory.createAlgo(queryGraph, algoOpts); // instead getClosestNode (which might be a virtual one and introducing unnecessary tails of the route) // use next tower node -> getBaseNode or getAdjNode // Later: remove potential route tail QueryResult startQR = queryResults.get(qrIndex - 1); int startNode = (startQR == start) ? startQR.getClosestNode() : startQR.getClosestEdge().getBaseNode(); QueryResult endQR = queryResults.get(qrIndex); int endNode = (endQR == start) ? endQR.getClosestNode() : endQR.getClosestEdge().getBaseNode(); Path path = algo.calcPath(startNode, endNode); visitedNodesSum += algo.getVisitedNodes(); pathList.add(path); // it is important to avoid previously visited nodes for future paths avoidPathWeighting.addEdges(path.calcEdges()); } ghResponse.getHints().put("visited_nodes.sum", visitedNodesSum); ghResponse.getHints().put("visited_nodes.average", (float) visitedNodesSum / (queryResults.size() - 1)); return pathList; }
private RoutingAlgorithm createCHAlgo(GraphHopperStorage graph, CHGraph chGraph, boolean withSOD, AlgorithmOptions algorithmOptions) { PrepareContractionHierarchies ch = new PrepareContractionHierarchies( chGraph, algorithmOptions.getWeighting(), TraversalMode.NODE_BASED); if (!withSOD) { algorithmOptions.getHints().put("stall_on_demand", false); } return ch.createAlgo(chGraph, algorithmOptions); } }
astarbiOpts.getHints().put(ASTAR_BI + ".approximation", "BeelineSimplification"); AlgorithmOptions dijkstrabiOpts = AlgorithmOptions.start(defaultOpts).algorithm(DIJKSTRA_BI).build(); prepare.add(new AlgoHelperEntry(ghStorage, astarbiOpts, idx, "astarbi|beeline|" + addStr + weighting));
opts.getHints().put("lm.recalc_count", 50); RoutingAlgorithm biDirAlgoWithLandmarks = prepare.getDecoratedAlgorithm(graph, new AStarBidirection(graph, weighting, tm), opts);
private WeightApproximator getApproximation( String prop, AlgorithmOptions opts, NodeAccess na ) { String approxAsStr = opts.getHints().get(prop + ".approximation", "BeelineSimplification"); double epsilon = opts.getHints().getDouble(prop + ".epsilon", 1); BeelineWeightApproximator approx = new BeelineWeightApproximator(na, opts.getWeighting()); approx.setEpsilon(epsilon); if ("BeelineSimplification".equals(approxAsStr)) approx.setDistanceCalc(Helper.DIST_PLANE); else if ("BeelineAccurate".equals(approxAsStr)) approx.setDistanceCalc(Helper.DIST_EARTH); else throw new IllegalArgumentException("Approximation " + approxAsStr + " not found in " + getClass().getName()); return approx; } }
public static WeightApproximator getApproximation(String prop, AlgorithmOptions opts, NodeAccess na) { String approxAsStr = opts.getHints().get(prop + ".approximation", "BeelineSimplification"); double epsilon = opts.getHints().getDouble(prop + ".epsilon", 1); BeelineWeightApproximator approx = new BeelineWeightApproximator(na, opts.getWeighting()); approx.setEpsilon(epsilon); if ("BeelineSimplification".equals(approxAsStr)) approx.setDistanceCalc(Helper.DIST_PLANE); else if ("BeelineAccurate".equals(approxAsStr)) approx.setDistanceCalc(Helper.DIST_EARTH); else throw new IllegalArgumentException("Approximation " + approxAsStr + " not found in " + RoutingAlgorithmFactorySimple.class.getName()); return approx; } }
public static WeightApproximator getApproximation(String prop, AlgorithmOptions opts, NodeAccess na) { String approxAsStr = opts.getHints().get(prop + ".approximation", "BeelineSimplification"); double epsilon = opts.getHints().getDouble(prop + ".epsilon", 1); BeelineWeightApproximator approx = new BeelineWeightApproximator(na, opts.getWeighting()); approx.setEpsilon(epsilon); if ("BeelineSimplification".equals(approxAsStr)) approx.setDistanceCalc(Helper.DIST_PLANE); else if ("BeelineAccurate".equals(approxAsStr)) approx.setDistanceCalc(Helper.DIST_EARTH); else throw new IllegalArgumentException("Approximation " + approxAsStr + " not found in " + RoutingAlgorithmFactorySimple.class.getName()); return approx; } }
private AbstractBidirAlgo doCreateAlgo(Graph graph, AlgorithmOptions opts) { if (ASTAR_BI.equals(opts.getAlgorithm())) { return new AStarBidirectionCH(graph, prepareWeighting, traversalMode) .setApproximation(RoutingAlgorithmFactorySimple.getApproximation(ASTAR_BI, opts, graph.getNodeAccess())); } else if (DIJKSTRA_BI.equals(opts.getAlgorithm())) { if (opts.getHints().getBool("stall_on_demand", true)) { return new DijkstraBidirectionCH(graph, prepareWeighting, traversalMode); } else { return new DijkstraBidirectionCHNoSOD(graph, prepareWeighting, traversalMode); } } else { throw new IllegalArgumentException("Algorithm " + opts.getAlgorithm() + " not supported for Contraction Hierarchies. Try with ch.disable=true"); } }
public RoutingAlgorithm getDecoratedAlgorithm(Graph qGraph, RoutingAlgorithm algo, AlgorithmOptions opts) { int activeLM = Math.max(1, opts.getHints().getInt(Landmark.ACTIVE_COUNT, defaultActiveLandmarks)); if (algo instanceof AStar) { if (!lms.isInitialized()) throw new IllegalStateException("Initialize landmark storage before creating algorithms"); double epsilon = opts.getHints().getDouble(Parameters.Algorithms.AStar.EPSILON, 1); AStar astar = (AStar) algo; astar.setApproximation(new LMApproximator(qGraph, this.graph.getNodes(), lms, activeLM, lms.getFactor(), false). throw new IllegalStateException("Initialize landmark storage before creating algorithms"); double epsilon = opts.getHints().getDouble(Parameters.Algorithms.AStarBi.EPSILON, 1); AStarBidirection astarbi = (AStarBidirection) algo; astarbi.setApproximation(new LMApproximator(qGraph, this.graph.getNodes(), lms, activeLM, lms.getFactor(), false). throw new IllegalStateException("Initialize landmark storage before creating algorithms"); double epsilon = opts.getHints().getDouble(Parameters.Algorithms.AStarBi.EPSILON, 1); AlternativeRoute altRoute = (AlternativeRoute) algo; altRoute.setApproximation(new LMApproximator(qGraph, this.graph.getNodes(), lms, activeLM, lms.getFactor(), false).
public RoutingAlgorithm getDecoratedAlgorithm(Graph qGraph, RoutingAlgorithm algo, AlgorithmOptions opts) { int activeLM = Math.max(1, opts.getHints().getInt(Landmark.ACTIVE_COUNT, defaultActiveLandmarks)); if (algo instanceof AStar) { if (!lms.isInitialized()) throw new IllegalStateException("Initalize landmark storage before creating algorithms"); double epsilon = opts.getHints().getDouble(Parameters.Algorithms.ASTAR + ".epsilon", 1); AStar astar = (AStar) algo; astar.setApproximation(new LMApproximator(qGraph, this.graph.getNodes(), lms, activeLM, lms.getFactor(), false). throw new IllegalStateException("Initalize landmark storage before creating algorithms"); double epsilon = opts.getHints().getDouble(Parameters.Algorithms.ASTAR_BI + ".epsilon", 1); AStarBidirection astarbi = (AStarBidirection) algo; astarbi.setApproximation(new LMApproximator(qGraph, this.graph.getNodes(), lms, activeLM, lms.getFactor(), false). throw new IllegalStateException("Initalize landmark storage before creating algorithms"); double epsilon = opts.getHints().getDouble(Parameters.Algorithms.ASTAR_BI + ".epsilon", 1); AlternativeRoute altRoute = (AlternativeRoute) algo; altRoute.setApproximation(new LMApproximator(qGraph, this.graph.getNodes(), lms, activeLM, lms.getFactor(), false).
altRouteAlgo.setMaxPaths(opts.getHints().getInt(MAX_PATHS, 2)); altRouteAlgo.setMaxWeightFactor(opts.getHints().getDouble(MAX_WEIGHT, 1.4)); altRouteAlgo.setMaxShareFactor(opts.getHints().getDouble(MAX_SHARE, 0.6)); altRouteAlgo.setMinPlateauFactor(opts.getHints().getDouble("alternative_route.min_plateau_factor", 0.2)); altRouteAlgo.setMaxExplorationFactor(opts.getHints().getDouble("alternative_route.max_exploration_factor", 1)); ra = altRouteAlgo;
altRouteAlgo.setMaxPaths(opts.getHints().getInt(MAX_PATHS, 2)); altRouteAlgo.setMaxWeightFactor(opts.getHints().getDouble(MAX_WEIGHT, 1.4)); altRouteAlgo.setMaxShareFactor(opts.getHints().getDouble(MAX_SHARE, 0.6)); altRouteAlgo.setMinPlateauFactor(opts.getHints().getDouble("alternative_route.min_plateau_factor", 0.2)); altRouteAlgo.setMaxExplorationFactor(opts.getHints().getDouble("alternative_route.max_exploration_factor", 1)); ra = altRouteAlgo;
algorithm(Parameters.Algorithms.ASTAR_BI). weighting(avoidPathWeighting).build(); algoOpts.getHints().put(Algorithms.ASTAR_BI + ".epsilon", 2);
@Override public List<Path> calcPaths(QueryGraph queryGraph, RoutingAlgorithmFactory algoFactory, AlgorithmOptions algoOpts) { pathList = new ArrayList<>(queryResults.size() - 1); AvoidEdgesWeighting avoidPathWeighting = new AvoidEdgesWeighting(algoOpts.getWeighting()); avoidPathWeighting.setEdgePenaltyFactor(5); algoOpts = AlgorithmOptions.start(algoOpts). algorithm(Parameters.Algorithms.ASTAR_BI). weighting(avoidPathWeighting).build(); algoOpts.getHints().put(Algorithms.ASTAR_BI + ".epsilon", 2); long visitedNodesSum = 0L; QueryResult start = queryResults.get(0); for (int qrIndex = 1; qrIndex < queryResults.size(); qrIndex++) { RoutingAlgorithm algo = algoFactory.createAlgo(queryGraph, algoOpts); // instead getClosestNode (which might be a virtual one and introducing unnecessary tails of the route) // use next tower node -> getBaseNode or getAdjNode // Later: remove potential route tail QueryResult startQR = queryResults.get(qrIndex - 1); int startNode = (startQR == start) ? startQR.getClosestNode() : startQR.getClosestEdge().getBaseNode(); QueryResult endQR = queryResults.get(qrIndex); int endNode = (endQR == start) ? endQR.getClosestNode() : endQR.getClosestEdge().getBaseNode(); Path path = algo.calcPath(startNode, endNode); visitedNodesSum += algo.getVisitedNodes(); pathList.add(path); // it is important to avoid previously visited nodes for future paths avoidPathWeighting.addEdges(path.calcEdges()); } ghResponse.getHints().put("visited_nodes.sum", visitedNodesSum); ghResponse.getHints().put("visited_nodes.average", (float) visitedNodesSum / (queryResults.size() - 1)); return pathList; }
@Override public List<Path> calcPaths(QueryGraph queryGraph, RoutingAlgorithmFactory algoFactory, AlgorithmOptions algoOpts) { pathList = new ArrayList<>(queryResults.size() - 1); AvoidEdgesWeighting avoidPathWeighting = new AvoidEdgesWeighting(algoOpts.getWeighting()); avoidPathWeighting.setEdgePenaltyFactor(5); algoOpts = AlgorithmOptions.start(algoOpts). algorithm(Parameters.Algorithms.ASTAR_BI). weighting(avoidPathWeighting).build(); algoOpts.getHints().put(Algorithms.AStarBi.EPSILON, 2); long visitedNodesSum = 0L; QueryResult start = queryResults.get(0); for (int qrIndex = 1; qrIndex < queryResults.size(); qrIndex++) { RoutingAlgorithm algo = algoFactory.createAlgo(queryGraph, algoOpts); // instead getClosestNode (which might be a virtual one and introducing unnecessary tails of the route) // use next tower node -> getBaseNode or getAdjNode // Later: remove potential route tail QueryResult startQR = queryResults.get(qrIndex - 1); int startNode = (startQR == start) ? startQR.getClosestNode() : startQR.getClosestEdge().getBaseNode(); QueryResult endQR = queryResults.get(qrIndex); int endNode = (endQR == start) ? endQR.getClosestNode() : endQR.getClosestEdge().getBaseNode(); Path path = algo.calcPath(startNode, endNode); visitedNodesSum += algo.getVisitedNodes(); pathList.add(path); // it is important to avoid previously visited nodes for future paths avoidPathWeighting.addEdges(path.calcEdges()); } ghResponse.getHints().put("visited_nodes.sum", visitedNodesSum); ghResponse.getHints().put("visited_nodes.average", (float) visitedNodesSum / (queryResults.size() - 1)); return pathList; }
altRouteAlgo.setMaxPaths(opts.getHints().getInt(MAX_PATHS, 2)); altRouteAlgo.setMaxWeightFactor(opts.getHints().getDouble(MAX_WEIGHT, 1.4)); altRouteAlgo.setMaxShareFactor(opts.getHints().getDouble(MAX_SHARE, 0.6)); altRouteAlgo.setMinPlateauFactor(opts.getHints().getDouble("alternative_route.min_plateau_factor", 0.2)); altRouteAlgo.setMaxExplorationFactor(opts.getHints().getDouble("alternative_route.max_exploration_factor", 1)); ra = altRouteAlgo;