protected final RoutingAlgorithm createAlgo(GraphHopperStorage ghStorage, AlgorithmOptions opts) { return createFactory(ghStorage, opts).createAlgo(getGraph(ghStorage, opts.getWeighting()), opts); }
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 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); }
Path calcPathViaQuery(Weighting weighting, GraphHopperStorage ghStorage, double fromLat, double fromLon, double toLat, double toLon) { LocationIndex index = new LocationIndexTree(ghStorage, new RAMDirectory()); index.prepareIndex(); QueryResult from = index.findClosest(fromLat, fromLon, EdgeFilter.ALL_EDGES); QueryResult to = index.findClosest(toLat, toLon, EdgeFilter.ALL_EDGES); // correct order for CH: in factory do prepare and afterwards wrap in query graph AlgorithmOptions opts = AlgorithmOptions.start().weighting(weighting).build(); RoutingAlgorithmFactory factory = createFactory(ghStorage, opts); QueryGraph qGraph = new QueryGraph(getGraph(ghStorage, weighting)).lookup(from, to); return factory.createAlgo(qGraph, opts). calcPath(from.getClosestNode(), to.getClosestNode()); }
@Test public void testWithCoordinates() { Weighting weighting = new ShortestWeighting(carEncoder); GraphHopperStorage graph = createGHStorage(encodingManager, Arrays.asList(weighting), false); graph.edge(0, 1, 2, true).setWayGeometry(Helper.createPointList(1.5, 1)); graph.edge(2, 3, 2, true).setWayGeometry(Helper.createPointList(0, 1.5)); graph.edge(3, 4, 2, true).setWayGeometry(Helper.createPointList(0, 2)); // duplicate but the second edge is longer graph.edge(0, 2, 1.2, true); graph.edge(0, 2, 1.5, true).setWayGeometry(Helper.createPointList(0.5, 0)); graph.edge(1, 3, 1.3, true).setWayGeometry(Helper.createPointList(0.5, 1.5)); graph.edge(1, 4, 1, true); updateDistancesFor(graph, 0, 1, 0.6); updateDistancesFor(graph, 1, 1, 1.5); updateDistancesFor(graph, 2, 0, 0); updateDistancesFor(graph, 3, 0, 1); updateDistancesFor(graph, 4, 0, 2); AlgorithmOptions opts = new AlgorithmOptions(DIJKSTRA_BI, weighting); RoutingAlgorithmFactory prepare = createFactory(graph, opts); Path p = prepare.createAlgo(getGraph(graph, opts.getWeighting()), opts).calcPath(4, 0); assertEquals(IntArrayList.from(new int[]{4, 1, 0}), p.calcNodes()); assertEquals(Helper.createPointList(0, 2, 1, 1.5, 1.5, 1, 1, 0.6), p.calcPoints()); assertEquals(274128, p.calcPoints().calcDistance(new DistanceCalcEarth()), 1); p = prepare.createAlgo(getGraph(graph, opts.getWeighting()), opts).calcPath(2, 1); assertEquals(IntArrayList.from(new int[]{2, 0, 1}), p.calcNodes()); assertEquals(Helper.createPointList(0, 0, 1, 0.6, 1.5, 1, 1, 1.5), p.calcPoints()); assertEquals(279482, p.calcPoints().calcDistance(new DistanceCalcEarth()), 1); }
QueryGraph qGraph = new QueryGraph(getGraph(graph, fakeWeighting)).lookup(from, to); p = factory.createAlgo(qGraph, fakeOpts).calcPath(from.getClosestNode(), to.getClosestNode()); assertEquals(IntArrayList.from(new int[]{12, 0, 1, 2, 11, 7, 10, 13}), p.calcNodes());