@Override public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) { return new DijkstraOneToMany(g, opts.getWeighting(), traversalMode); } };
@Override public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) { return new AStar(g, opts.getWeighting(), traversalMode); } };
@Override public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) { return new DijkstraBidirectionRef(g, opts.getWeighting(), traversalMode); } };
@Override public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) { return new AStarBidirection(g, opts.getWeighting(), traversalMode); } };
@Override public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) { return new Dijkstra(g, opts.getWeighting(), traversalMode); } };
Path calcPathViaQuery(GraphHopperStorage ghStorage, double fromLat, double fromLon, double toLat, double toLon) { return calcPathViaQuery(defaultOpts.getWeighting(), ghStorage, fromLat, fromLon, toLat, toLon); }
@Override public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) { RoutingAlgorithm algo = tmpFactory.createAlgo(g, opts); if (algo instanceof AStarBidirection) { return new DebugAStarBi(g, opts.getWeighting(), opts.getTraversalMode(), mg). setApproximation(((AStarBidirection) algo).getApproximation()); } else if (algo instanceof AStar) { return new DebugAStar(g, opts.getWeighting(), opts.getTraversalMode(), mg); } else if (algo instanceof DijkstraBidirectionRef) { return new DebugDijkstraBidirection(g, opts.getWeighting(), opts.getTraversalMode(), mg); } else if (algo instanceof Dijkstra) { return new DebugDijkstraSimple(g, opts.getWeighting(), opts.getTraversalMode(), mg); } return algo; } };
protected GraphHopperStorage createGHStorage(boolean is3D) { return createGHStorage(encodingManager, Arrays.asList(defaultOpts.getWeighting()), is3D); }
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; } }
@Override public RoutingAlgorithmFactory createFactory(GraphHopperStorage ghStorage, AlgorithmOptions opts) { ghStorage.freeze(); PrepareContractionHierarchies ch = PrepareContractionHierarchies.fromGraphHopperStorage( ghStorage, opts.getWeighting(), TraversalMode.NODE_BASED); ch.doWork(); return ch; }
protected final RoutingAlgorithm createAlgo(GraphHopperStorage ghStorage, AlgorithmOptions opts) { return createFactory(ghStorage, opts).createAlgo(getGraph(ghStorage, opts.getWeighting()), opts); }
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); } }
/** * This method clones the specified AlgorithmOption object with the possibility for further * changes. */ public static Builder start(AlgorithmOptions opts) { Builder b = new Builder(); if (opts.algorithm != null) b.algorithm(opts.getAlgorithm()); if (opts.traversalMode != null) b.traversalMode(opts.getTraversalMode()); if (opts.weighting != null) b.weighting(opts.getWeighting()); if (opts.maxVisitedNodes >= 0) b.maxVisitedNodes(opts.maxVisitedNodes); if (!opts.hints.isEmpty()) b.hints(opts.hints); return b; }
Path calcPath(GraphHopperStorage ghStorage, int fromNode1, int fromNode2, int toNode1, int toNode2) { // lookup two edges: fromNode1-fromNode2 and toNode1-toNode2 QueryResult from = newQR(ghStorage, fromNode1, fromNode2); QueryResult to = newQR(ghStorage, toNode1, toNode2); RoutingAlgorithmFactory factory = createFactory(ghStorage, defaultOpts); QueryGraph qGraph = new QueryGraph(getGraph(ghStorage, defaultOpts.getWeighting())).lookup(from, to); return factory.createAlgo(qGraph, defaultOpts).calcPath(from.getClosestNode(), to.getClosestNode()); }
@Test public void testCalcFootPath() { AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new ShortestWeighting(footEncoder)).build(); GraphHopperStorage ghStorage = createGHStorage(encodingManager, Arrays.asList(opts.getWeighting()), false); initFootVsCar(ghStorage); Path p1 = createAlgo(ghStorage, opts). calcPath(0, 7); assertEquals(p1.toString(), 17000, p1.getDistance(), 1e-6); assertEquals(p1.toString(), 12240 * 1000, p1.getTime()); assertEquals(IntArrayList.from(new int[]{0, 4, 5, 7}), p1.calcNodes()); }
@Test public void testMultipleVehicles_issue548() { FastestWeighting footWeighting = new FastestWeighting(footEncoder); AlgorithmOptions footOptions = AlgorithmOptions.start(). weighting(footWeighting).build(); FastestWeighting carWeighting = new FastestWeighting(carEncoder); AlgorithmOptions carOptions = AlgorithmOptions.start(). weighting(carWeighting).build(); GraphHopperStorage ghStorage = createGHStorage(encodingManager, Arrays.asList(footOptions.getWeighting(), carOptions.getWeighting()), false); initFootVsCar(ghStorage); // normal path would be 0-4-6-7 but block 4-6 GHUtility.getEdge(ghStorage, 4, 6).setFlags(carEncoder.setProperties(20, false, false)); RoutingAlgorithm algoFoot = createFactory(ghStorage, footOptions). createAlgo(getGraph(ghStorage, footWeighting), footOptions); RoutingAlgorithm algoCar = createFactory(ghStorage, carOptions). createAlgo(getGraph(ghStorage, carWeighting), carOptions); Path p1 = algoCar.calcPath(0, 7); assertEquals(IntArrayList.from(new int[]{0, 1, 5, 6, 7}), p1.calcNodes()); assertEquals(p1.toString(), 26000, p1.getDistance(), 1e-6); }
@Test public void testTwoWeightsPerEdge() { FlagEncoder encoder = new Bike2WeightFlagEncoder(); EncodingManager em = new EncodingManager(encoder); AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new FastestWeighting(encoder)).build(); GraphHopperStorage graph = createGHStorage(em, Arrays.asList(opts.getWeighting()), true); initEleGraph(graph); // force the other path GHUtility.getEdge(graph, 0, 3).setFlags(encoder.setProperties(10, false, true)); // for two weights per edge it happened that Path (and also the Weighting) read the wrong side // of the speed and read 0 => infinity weight => overflow of millis => negative millis! Path p = createAlgo(graph, opts). calcPath(0, 10); assertEquals(85124371, p.getTime()); assertEquals(425622, p.getDistance(), 1); assertEquals(85124.4, p.getWeight(), 1); }
@Test public void testBaseGraph() { CarFlagEncoder carFE = new CarFlagEncoder(); EncodingManager em = new EncodingManager(carFE); AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new ShortestWeighting(carFE)).build(); GraphHopperStorage ghStorage = createGHStorage(em, Arrays.asList(opts.getWeighting()), false); initDirectedAndDiffSpeed(ghStorage, carFE); // do CH preparation for car createFactory(ghStorage, opts); // use base graph for solving normal Dijkstra Path p1 = new RoutingAlgorithmFactorySimple().createAlgo(ghStorage, defaultOpts).calcPath(0, 3); assertEquals(IntArrayList.from(0, 1, 5, 2, 3), p1.calcNodes()); assertEquals(p1.toString(), 402.29, p1.getDistance(), 1e-2); assertEquals(p1.toString(), 144823, p1.getTime()); }
@Test public void testBaseGraphMultipleVehicles() { AlgorithmOptions footOptions = AlgorithmOptions.start(). weighting(new FastestWeighting(footEncoder)).build(); AlgorithmOptions carOptions = AlgorithmOptions.start(). weighting(new FastestWeighting(carEncoder)).build(); GraphHopperStorage g = createGHStorage(encodingManager, Arrays.asList(footOptions.getWeighting(), carOptions.getWeighting()), false); initFootVsCar(g); // do CH preparation for car RoutingAlgorithmFactory contractedFactory = createFactory(g, carOptions); // use contracted graph Path p1 = contractedFactory.createAlgo(getGraph(g, carOptions.getWeighting()), carOptions).calcPath(0, 7); assertEquals(IntArrayList.from(0, 4, 6, 7), p1.calcNodes()); assertEquals(p1.toString(), 15000, p1.getDistance(), 1e-6); // use base graph for solving normal Dijkstra via car Path p2 = new RoutingAlgorithmFactorySimple().createAlgo(g, carOptions).calcPath(0, 7); assertEquals(IntArrayList.from(0, 4, 6, 7), p2.calcNodes()); assertEquals(p2.toString(), 15000, p2.getDistance(), 1e-6); assertEquals(p2.toString(), 2700 * 1000, p2.getTime()); // use base graph for solving normal Dijkstra via foot Path p3 = new RoutingAlgorithmFactorySimple().createAlgo(g, footOptions).calcPath(0, 7); assertEquals(p3.toString(), 17000, p3.getDistance(), 1e-6); assertEquals(p3.toString(), 12240 * 1000, p3.getTime()); assertEquals(IntArrayList.from(0, 4, 5, 7), p3.calcNodes()); }
@Test public void testCalcFastestPath() { GraphHopperStorage graphShortest = createGHStorage(false); initDirectedAndDiffSpeed(graphShortest, carEncoder); Path p1 = createAlgo(graphShortest, defaultOpts). calcPath(0, 3); assertEquals(IntArrayList.from(new int[]{0, 1, 5, 2, 3}), p1.calcNodes()); assertEquals(p1.toString(), 402.3, p1.getDistance(), .1); assertEquals(p1.toString(), 144823, p1.getTime()); AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new FastestWeighting(carEncoder)).build(); GraphHopperStorage graphFastest = createGHStorage(encodingManager, Arrays.asList(opts.getWeighting()), false); initDirectedAndDiffSpeed(graphFastest, carEncoder); Path p2 = createAlgo(graphFastest, opts). calcPath(0, 3); assertEquals(IntArrayList.from(new int[]{0, 4, 6, 7, 5, 3}), p2.calcNodes()); assertEquals(p2.toString(), 1261.7, p2.getDistance(), 0.1); assertEquals(p2.toString(), 111442, p2.getTime()); }