@Override protected CHGraph getGraph(GraphHopperStorage ghStorage, Weighting weighting) { return ghStorage.getGraph(CHGraph.class, weighting); }
public static PrepareContractionHierarchies fromGraphHopperStorage(GraphHopperStorage ghStorage, Weighting weighting, TraversalMode traversalMode) { return new PrepareContractionHierarchies(ghStorage.getGraph(CHGraph.class, weighting), weighting, traversalMode); }
protected CHGraph getGraph(GraphHopperStorage ghStorage) { return ghStorage.getGraph(CHGraph.class); }
protected Graph getGraph(GraphHopperStorage ghStorage, Weighting weighting) { return ghStorage.getGraph(Graph.class, weighting); }
/** * Creates a CHGraph */ public CHGraph chGraphCreate(Weighting singleCHWeighting) { return setCHGraph(singleCHWeighting).create().getGraph(CHGraph.class, singleCHWeighting); }
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 testReturnsCorrectWeighting() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); assertSame(weighting, prepare.getWeighting()); }
@Override protected void prepareCH() { StopWatch sw = new StopWatch().start(); super.prepareCH(); put(Parameters.CH.PREPARE + "time", sw.stop().getMillis()); int edges = getGraphHopperStorage().getAllEdges().length(); if (getCHFactoryDecorator().hasWeightings()) { Weighting weighting = getCHFactoryDecorator().getWeightings().get(0); int edgesAndShortcuts = getGraphHopperStorage().getGraph(CHGraph.class, weighting).getEdges(); put(Parameters.CH.PREPARE + "shortcuts", edgesAndShortcuts - edges); } }
@Test public void testNoCreateCalled() throws IOException { GraphHopperStorage gs = new GraphBuilder(encodingManager).build(); try { ((BaseGraph) gs.getGraph(Graph.class)).ensureNodeIndex(123); assertFalse("AssertionError should be raised", true); } catch (AssertionError err) { assertTrue(true); } catch (Exception ex) { assertFalse("AssertionError should be raised, but was " + ex.toString(), true); } finally { gs.close(); } }
@Test public void testAddShortcuts() { GraphHopperStorage g = createExampleGraph(); CHGraph lg = g.getGraph(CHGraph.class); int old = lg.getEdges(); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); prepare.doWork(); assertEquals(old + 2, lg.getEdges()); }
@Test public void testIdentical() { GraphHopperStorage store = new GraphHopperStorage(new RAMDirectory(), encodingManager, true, new GraphExtension.NoOpExtension()); assertEquals(store.getNodes(), store.getGraph(Graph.class).getNodes()); assertEquals(store.getAllEdges().length(), store.getGraph(Graph.class).getAllEdges().length()); }
@Test public void testMoreComplexGraph() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); initShortcutsGraph(lg); int oldCount = g.getAllEdges().length(); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); prepare.doWork(); assertEquals(oldCount, g.getEdges()); assertEquals(oldCount + 7, lg.getEdges()); }
@Test public void testBigDataEdge() { Directory dir = new RAMDirectory(); GraphHopperStorage graph = new GraphHopperStorage(dir, encodingManager, false, new GraphExtension.NoOpExtension()); graph.create(defaultSize); ((BaseGraph) graph.getGraph(Graph.class)).setEdgeCount(Integer.MAX_VALUE / 2); assertTrue(graph.getAllEdges().next()); graph.close(); }
@Test public void testCircleBug() { GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); // /--1 // -0--/ // | g.edge(0, 1, 10, true); g.edge(0, 1, 4, true); g.edge(0, 2, 10, true); g.edge(0, 3, 10, true); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); prepare.doWork(); assertEquals(0, prepare.getShortcuts()); }
@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 testShortestPathSkipNode() { createExampleGraph(); final double normalDist = new Dijkstra(graph, weighting, traversalMode).calcPath(4, 2).getDistance(); DijkstraOneToMany algo = new DijkstraOneToMany(graph, weighting, traversalMode); CHGraph lg = graph.getGraph(CHGraph.class); setMaxLevelOnAllNodes(); algo.setEdgeFilter(createIgnoreNodeFilter(3)); algo.setWeightLimit(100); int nodeEntry = algo.findEndNode(4, 2); assertTrue(algo.getWeight(nodeEntry) > normalDist); algo.clear(); algo.setMaxVisitedNodes(1); nodeEntry = algo.findEndNode(4, 2); assertEquals(-1, nodeEntry); }
@Test public void testSimpleShortcutCreationAndTraversal() { graph = createGHStorage(); graph.edge(1, 3, 10, true); graph.edge(3, 4, 10, true); graph.freeze(); CHGraph lg = graph.getGraph(CHGraph.class); lg.shortcut(1, 4).setWeight(3).setFlags(carEncoder.setProperties(10, true, true)); EdgeExplorer vehicleOutExplorer = lg.createEdgeExplorer(DefaultEdgeFilter.outEdges(carEncoder)); // iteration should result in same nodes even if reusing the iterator assertEquals(GHUtility.asSet(3, 4), GHUtility.getNeighbors(vehicleOutExplorer.setBaseNode(1))); assertEquals(GHUtility.asSet(3, 4), GHUtility.getNeighbors(vehicleOutExplorer.setBaseNode(1))); }
@Test public void testAddShortcutSkippedEdgesWriteRead_writeWithCHEdgeIterator() { graph = createGHStorage(); final EdgeIteratorState edge1 = graph.edge(1, 3, 10, true); final EdgeIteratorState edge2 = graph.edge(3, 4, 10, true); graph.freeze(); CHGraph lg = graph.getGraph(CHGraph.class); CHEdgeIteratorState shortcut = lg.shortcut(1, 4); shortcut.setSkippedEdges(edge1.getEdge(), edge2.getEdge()); AllCHEdgesIterator iter = lg.getAllEdges(); iter.next(); iter.next(); iter.next(); assertTrue(iter.isShortcut()); assertEquals(edge1.getEdge(), iter.getSkippedEdge1()); assertEquals(edge2.getEdge(), iter.getSkippedEdge2()); }