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); } }
void checkPath(GraphHopperStorage g, Weighting w, int expShortcuts, double expDistance, IntIndexedContainer expNodes) { CHGraph lg = g.getGraph(CHGraph.class, w); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg, w); prepare.doWork(); assertEquals(w.toString(), expShortcuts, prepare.getShortcuts()); RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, w, tMode)); Path p = algo.calcPath(3, 12); assertEquals(w.toString(), expDistance, p.getDistance(), 1e-5); assertEquals(w.toString(), expNodes, p.calcNodes()); }
@Test public void testUnpackingOrder() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); initUnpackingGraph(g, lg, weighting); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode)); Path p = algo.calcPath(10, 6); assertEquals(7, p.getDistance(), 1e-5); assertEquals(IntArrayList.from(10, 0, 1, 2, 3, 4, 5, 6), p.calcNodes()); }
@Test public void testUnpackingOrder_Fastest() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); Weighting w = new FastestWeighting(carEncoder); initUnpackingGraph(g, lg, w); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode)); Path p = algo.calcPath(10, 6); assertEquals(7, p.getDistance(), 1e-1); assertEquals(IntArrayList.from(10, 0, 1, 2, 3, 4, 5, 6), p.calcNodes()); }
@Test public void testRoundaboutUnpacking() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); initRoundaboutGraph(g); int oldCount = g.getAllEdges().length(); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); prepare.doWork(); assertEquals(oldCount, g.getEdges()); assertEquals(oldCount + 23, lg.getEdges()); RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode)); Path p = algo.calcPath(4, 7); assertEquals(IntArrayList.from(4, 5, 6, 7), p.calcNodes()); }
@Test public void testDirectedGraph2() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); initDirected2(g); int oldCount = GHUtility.count(g.getAllEdges()); assertEquals(19, oldCount); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); prepare.doWork(); // PrepareTowerNodesShortcutsTest.printEdges(g); assertEquals(oldCount, g.getAllEdges().length()); assertEquals(oldCount, GHUtility.count(g.getAllEdges())); long numShortcuts = 9; assertEquals(numShortcuts, prepare.getShortcuts()); assertEquals(oldCount + numShortcuts, lg.getEdges()); assertEquals(oldCount + numShortcuts, GHUtility.count(lg.getAllEdges())); RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode)); Path p = algo.calcPath(0, 10); assertEquals(10, p.getDistance(), 1e-6); assertEquals(IntArrayList.from(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), p.calcNodes()); }
@Test public void testDirectedGraph() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); g.edge(5, 4, 3, false); g.edge(4, 5, 10, false); g.edge(2, 4, 1, false); g.edge(5, 2, 1, false); g.edge(3, 5, 1, false); g.edge(4, 3, 1, false); g.freeze(); int oldCount = GHUtility.count(lg.getAllEdges()); assertEquals(6, oldCount); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); prepare.doWork(); assertEquals(2, prepare.getShortcuts()); assertEquals(oldCount + 2, GHUtility.count(lg.getAllEdges())); RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode)); Path p = algo.calcPath(4, 2); assertEquals(3, p.getDistance(), 1e-6); assertEquals(IntArrayList.from(4, 3, 5, 2), p.calcNodes()); }
Path p = new PrepareContractionHierarchies( g2, weighting, TraversalMode.NODE_BASED). createAlgo(g2, opts).calcPath(0, 7);