@Override public void run() { // toString is not taken into account so we need to cheat, see http://stackoverflow.com/q/6113746/194609 for other options Thread.currentThread().setName(name); prepare.doWork(); properties.put(CH.PREPARE + "date." + name, createFormatter().format(new Date())); } }, name);
@Override public RoutingAlgorithmFactory createFactory(GraphHopperStorage ghStorage, AlgorithmOptions opts) { ghStorage.freeze(); PrepareContractionHierarchies ch = PrepareContractionHierarchies.fromGraphHopperStorage( ghStorage, opts.getWeighting(), TraversalMode.NODE_BASED); ch.doWork(); return ch; }
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 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 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 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 testBug178() { // 5--------6__ // | | \ // 0-1->-2--3--4 // \-<-/ // GraphHopperStorage g = createGHStorage(); CHGraph lg = g.getGraph(CHGraph.class); g.edge(1, 2, 1, false); g.edge(2, 1, 1, false); g.edge(5, 0, 1, true); g.edge(5, 6, 1, true); g.edge(0, 1, 1, true); g.edge(2, 3, 1, true); g.edge(3, 4, 1, true); g.edge(6, 3, 1, true); PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg); prepare.doWork(); assertEquals(2, prepare.getShortcuts()); }
@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 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 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()); }
@Override public void run() { // toString is not taken into account so we need to cheat, see http://stackoverflow.com/q/6113746/194609 for other options Thread.currentThread().setName(name); prepare.doWork(); properties.put(CH.PREPARE + "date." + name, createFormatter().format(new Date())); } }, name);
@Override public void run() { String errorKey = CH.PREPARE + "error." + name; try { // toString is not taken into account so we need to cheat, see http://stackoverflow.com/q/6113746/194609 for other options Thread.currentThread().setName(name); properties.put(errorKey, "CH preparation incomplete"); prepare.doWork(); properties.remove(errorKey); properties.put(CH.PREPARE + "date." + name, Helper.createFormatter().format(new Date())); } catch (Exception ex) { LOGGER.error("Problem while CH preparation " + name, ex); properties.put(errorKey, ex.getMessage()); } } });
@Override public void run() { String errorKey = "prepare.error." + name; try { properties.put(errorKey, "CH preparation incomplete"); // toString is not taken into account so we need to cheat, see http://stackoverflow.com/q/6113746/194609 for other options Thread.currentThread().setName(name); prepare.doWork(); properties.remove(errorKey); properties.put("prepare.date." + name, Helper.createFormatter().format(new Date())); } catch (Exception ex) { logger.error("Problem while CH preparation " + name, ex); properties.put(errorKey, ex.getMessage()); } } });