/** * Queries the ch graph and checks if the graph's shortcuts match the given expected shortcuts. */ private void checkShortcuts(Shortcut... expectedShortcuts) { Set<Shortcut> expected = setOf(expectedShortcuts); if (expected.size() != expectedShortcuts.length) { fail("was given duplicate shortcuts"); } AllCHEdgesIterator iter = lg.getAllEdges(); Set<Shortcut> given = new HashSet<>(); while (iter.next()) { if (iter.isShortcut()) { given.add(new Shortcut( iter.getBaseNode(), iter.getAdjNode(), iter.getWeight(), iter.getDistance(), iter.isForward(encoder), iter.isBackward(encoder), iter.getSkippedEdge1(), iter.getSkippedEdge2())); } } assertEquals(expected, given); }
Weighting weighting = hopper.getCHFactoryDecorator().getWeightings().get(0); CHGraph lg = g.getGraph(CHGraph.class, weighting); fillAllowedEdges(lg.getAllEdges(), allowedEdges); printMiscUnitPerfTests(lg, isCH, encoder, count * 100, allowedEdges); printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH", vehicleStr, true, -1, true);
@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()); }
@Test public void testAddShortcutSkippedEdgesWriteRead() { 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); lg.shortcut(1, 4); AllCHEdgesIterator iter = lg.getAllEdges(); iter.next(); iter.next(); iter.next(); assertTrue(iter.isShortcut()); iter.setSkippedEdges(edge1.getEdge(), edge2.getEdge()); assertEquals(edge1.getEdge(), iter.getSkippedEdge1()); assertEquals(edge2.getEdge(), iter.getSkippedEdge2()); }
@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()); }
@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()); }
ghStorage.freeze(); assertEquals(2, GHUtility.count(g.getAllEdges())); assertEquals(1, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1))); EdgeIteratorState iter = GHUtility.getEdge(g, 0, 1);
assertEquals(1, GHUtility.count(chGraph.createEdgeExplorer().setBaseNode(2))); AllCHEdgesIterator iter = chGraph.getAllEdges(); assertTrue(iter.next()); assertFalse(iter.isShortcut());
@Override public void prepareContraction() { // todo: initializing meanDegree here instead of in initFromGraph() means that in the first round of calculating // node priorities all shortcut searches are cancelled immediately and all possible shortcuts are counted because // no witness path can be found. this is not really what we want, but changing it requires re-optimizing the // graph contraction parameters, because it affects the node contraction order. // when this is done there should be no need for this method any longer. meanDegree = prepareGraph.getAllEdges().length() / prepareGraph.getNodes(); }
void setOrigEdgeCount(int edgeId, int value) { edgeId -= maxEdgesCount; if (edgeId < 0) { // ignore setting as every normal edge has original edge count of 1 if (value != 1) throw new IllegalStateException("Trying to set original edge count for normal edge to a value = " + value + ", edge:" + (edgeId + maxEdgesCount) + ", max:" + maxEdgesCount + ", graph.max:" + prepareGraph.getAllEdges().length()); return; } long tmp = (long) edgeId * 4; originalEdges.ensureCapacity(tmp + 4); originalEdges.setInt(tmp, value); }