@Test public void testFindShortcuts_Roundabout() { LevelGraphStorage g = (LevelGraphStorage) createGraph(); EdgeSkipIterator iter1_1 = g.edge(1, 3, 1, true); EdgeSkipIterator iter1_2 = g.edge(3, 4, 1, true); EdgeSkipIterator iter2_1 = g.edge(4, 5, 1, false); EdgeSkipIterator iter2_2 = g.edge(5, 6, 1, false); EdgeSkipIterator iter3_1 = g.edge(6, 7, 1, true); EdgeSkipIterator iter3_2 = g.edge(6, 8, 2, false); g.edge(8, 4, 1, false); g.setLevel(3, 3); g.setLevel(5, 5); g.setLevel(7, 7); g.setLevel(8, 8); PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g); g.edge(1, 4, 2, prepare.scBothDir()).skippedEdges(iter1_1.edge(), iter1_2.edge()); int f = prepare.scOneDir(); g.edge(4, 6, 2, f).skippedEdges(iter2_1.edge(), iter2_2.edge()); g.edge(6, 4, 3, f).skippedEdges(iter3_1.edge(), iter3_2.edge()); prepare.initFromGraph(); // there should be two different shortcuts for both directions! Collection<Shortcut> sc = prepare.testFindShortcuts(4); assertEquals(2, sc.size()); }
@Test public void testMoreComplexGraph() { LevelGraph g = initShortcutsGraph(createGraph()); int old = g.getAllEdges().maxId(); PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g); prepare.doWork(); assertEquals(old + 8, g.getAllEdges().maxId()); }
@Test public void testAddShortcuts() { LevelGraph g = createExampleGraph(); int old = g.getAllEdges().maxId(); PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g); prepare.doWork(); assertEquals(old, g.getAllEdges().maxId()); }
@Override public PrepareContractionHierarchies prepareGraph(Graph g, FlagEncoder encoder, Weighting w) { PrepareContractionHierarchies ch = new PrepareContractionHierarchies(encoder, w).setGraph(g); // hack: prepare matrixgraph only once if (g != preparedMatrixGraph) ch.doWork(); return ch; }
@Test public void testUnpackingOrder_Fastest() { LevelGraphStorage g = (LevelGraphStorage) createGraph(); PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g); WeightCalculation calc = new FastestCalc(carEncoder); initUnpackingGraph(g, calc); RoutingAlgorithm algo = prepare.type(calc).vehicle(carEncoder).createAlgo(); Path p = algo.calcPath(10, 6); assertEquals(7, p.distance(), 1e-1); assertEquals(Helper.createTList(10, 0, 1, 2, 3, 4, 5, 6), p.calcNodes()); }
@Test public void testRoundaboutUnpacking() { LevelGraph g = createGraph(); initRoundaboutGraph(g); int old = g.getAllEdges().maxId(); PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g); prepare.doWork(); assertEquals(old + 25, g.getAllEdges().maxId()); RoutingAlgorithm algo = prepare.createAlgo(); Path p = algo.calcPath(4, 7); assertEquals(Helper.createTList(4, 5, 6, 7), p.calcNodes()); }
@Test public void testCircleBug() { LevelGraph g = createGraph(); // /--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 = new PrepareContractionHierarchies().graph(g); prepare.doWork(); assertEquals(0, prepare.shortcuts()); }
@Override public RoutingAlgorithmFactory createFactory( GraphHopperStorage ghStorage, AlgorithmOptions opts) { PrepareContractionHierarchies ch = new PrepareContractionHierarchies( new GHDirectory("", DAType.RAM_INT), ghStorage, getGraph(ghStorage, opts.getWeighting()), opts.getFlagEncoder(), opts.getWeighting(), TraversalMode.NODE_BASED); ch.doWork(); return ch; }
@Test public void testDirectedGraph2() { LevelGraph g = createGraph(); initDirected2(g); int old = GHUtility.count(g.getAllEdges()); PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g); prepare.doWork(); // PrepareTowerNodesShortcutsTest.printEdges(g); assertEquals(old + 15, GHUtility.count(g.getAllEdges())); RoutingAlgorithm algo = prepare.createAlgo(); Path p = algo.calcPath(0, 10); assertEquals(10, p.distance(), 1e-6); assertEquals(Helper.createTList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), p.calcNodes()); }
@Test public void testDirectedGraph() { LevelGraph g = createGraph(); 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); int old = GHUtility.count(g.getAllEdges()); PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g); prepare.doWork(); // PrepareTowerNodesShortcutsTest.printEdges(g); assertEquals(old + 3, GHUtility.count(g.getAllEdges())); RoutingAlgorithm algo = prepare.createAlgo(); Path p = algo.calcPath(4, 2); assertEquals(3, p.distance(), 1e-6); assertEquals(Helper.createTList(4, 3, 5, 2), p.calcNodes()); }
private void postProcessing() { encodingManager = graph.getEncodingManager(); if (chUsage) { PrepareContractionHierarchies tmpPrepareCH = new PrepareContractionHierarchies(); FlagEncoder encoder = encodingManager.getSingle(); if (chFast) tmpPrepareCH.setType(new FastestCalc(encoder)); else tmpPrepareCH.setType(new ShortestCalc()); tmpPrepareCH.setVehicle(encoder); tmpPrepareCH .setPeriodicUpdates(periodicUpdates) .setLazyUpdates(lazyUpdates) .setNeighborUpdates(neighborUpdates); prepare = tmpPrepareCH; prepare.setGraph(graph); } if ("false".equals(graph.getProperties().get("prepare.done"))) prepare(); }
public static RoutingAlgorithm[] createAlgos(final Graph g) { LevelGraph graphSimpleSC = (LevelGraphStorage) g.copyTo(new LevelGraphStorage(new RAMDirectory()).createNew(10)); PrepareSimpleShortcuts prepare = new PrepareSimpleShortcuts().setGraph(graphSimpleSC); prepare.doWork(); AStarBidirection astarSimpleSC = (AStarBidirection) prepare.createAStar(); astarSimpleSC.setApproximation(false); LevelGraph graphCH = (LevelGraphStorage) g.copyTo(new LevelGraphStorage(new RAMDirectory()).createNew(10)); PrepareContractionHierarchies prepareCH = new PrepareContractionHierarchies().setGraph(graphCH); prepareCH.doWork(); return new RoutingAlgorithm[] { new AStar(g), new AStarBidirection(g), new DijkstraBidirectionRef(g), new DijkstraBidirection(g), new DijkstraSimple(g), prepare.createAlgo(), astarSimpleSC, prepareCH.createAlgo() }; }
@Test public void testDirectedGraph3() { LevelGraph g = createGraph(); g.edge(0, 2, 2, true); g.edge(10, 2, 2, true); g.edge(11, 2, 2, true); // create a longer one directional edge => no longish one-dir shortcut should be created g.edge(2, 1, 2, true); g.edge(2, 1, 10, false); g.edge(1, 3, 2, true); g.edge(3, 4, 2, true); g.edge(3, 5, 2, true); g.edge(3, 6, 2, true); g.edge(3, 7, 2, true); PrepareContractionHierarchies prepare = new PrepareContractionHierarchies().graph(g); prepare.initFromGraph(); // find all shortcuts if we contract node 1 Collection<Shortcut> scs = prepare.testFindShortcuts(1); assertEquals(2, scs.size()); Iterator<Shortcut> iter = scs.iterator(); Shortcut sc1 = iter.next(); Shortcut sc2 = iter.next(); if (sc1.distance > sc2.distance) { Shortcut tmp = sc1; sc1 = sc2; sc2 = tmp; } assertTrue(sc1.toString(), sc1.from == 2 && sc1.to == 3); assertTrue(sc2.toString(), sc2.from == 2 && sc2.to == 3); assertEquals(sc1.toString(), 4, sc1.distance, 1e-4); assertEquals(sc2.toString(), 12, sc2.distance, 1e-4); }