@Test public void testTarjan() { GraphHopperStorage g = createSubnetworkTestStorage(); // Requires a single vehicle type, otherwise we throw. final EdgeFilter filter = DefaultEdgeFilter.outEdges(carFlagEncoder); TarjansSCCAlgorithm tarjan = new TarjansSCCAlgorithm(g, filter, false); List<IntArrayList> components = tarjan.findComponents(); assertEquals(4, components.size()); assertEquals(IntArrayList.from(13, 5, 3, 7, 0), components.get(0)); assertEquals(IntArrayList.from(2, 4, 12, 11, 8, 1), components.get(1)); assertEquals(IntArrayList.from(10, 14, 6), components.get(2)); assertEquals(IntArrayList.from(15, 9), components.get(3)); }
@Test public void testUseCache() { RoutingAlgorithm algo = createAlgo(createTestStorage()); Path p = algo.calcPath(0, 4); assertEquals(IntArrayList.from(new int[]{0, 4}), p.calcNodes()); // expand SPT p = algo.calcPath(0, 7); assertEquals(IntArrayList.from(new int[]{0, 4, 5, 7}), p.calcNodes()); // use SPT p = algo.calcPath(0, 2); assertEquals(IntArrayList.from(new int[]{0, 1, 2}), p.calcNodes()); }
@Test public void testIssue182() { GraphHopperStorage storage = createGHStorage(false); initGraph(storage); RoutingAlgorithm algo = createAlgo(storage); Path p = algo.calcPath(0, 8); assertEquals(IntArrayList.from(new int[]{0, 7, 8}), p.calcNodes()); // expand SPT p = algo.calcPath(0, 10); assertEquals(IntArrayList.from(new int[]{0, 1, 2, 3, 4, 10}), p.calcNodes()); }
public void testCorrectWeight(GraphHopperStorage g) { Path p = createAlgo(g).calcPath(45, 72); assertEquals(IntArrayList.from(new int[]{45, 44, 54, 64, 74, 73, 72}), p.calcNodes()); assertEquals(38f, p.getDistance(), 1e-3); }
@Test public void testQueryGraphAndFastest() { Weighting weighting = new FastestWeighting(carEncoder); GraphHopperStorage graph = createGHStorage(encodingManager, Arrays.asList(weighting), false); initDirectedAndDiffSpeed(graph, carEncoder); Path p = calcPathViaQuery(weighting, graph, 0.002, 0.0005, 0.0017, 0.0031); assertEquals(IntArrayList.from(new int[]{8, 1, 5, 3, 9}), p.calcNodes()); assertEquals(602.98, p.getDistance(), 1e-1); }
@Test public void testReverseSpatialKey() { LocationIndexTree index = createIndex(createTestGraph(encodingManager), 200); assertEquals(IntArrayList.from(new int[]{64, 64, 64, 4}), index.getEntries()); // 10111110111110101010 String str44 = "00000000000000000000000000000000000000000000"; assertEquals(str44 + "01010101111101111101", BitUtil.BIG.toBitString(index.createReverseKey(1.7, 0.099))); }
@Test public void testViaEdges_WithCoordinates() { GraphHopperStorage ghStorage = createTestStorage(); Path p = calcPath(ghStorage, 0, 1, 2, 3); assertEquals(IntArrayList.from(new int[]{8, 1, 2, 9}), p.calcNodes()); assertEquals(p.toString(), 56.7, p.getDistance(), .1); }
public void testBug1(GraphHopperStorage g) { Path p = createAlgo(g).calcPath(34, 36); assertEquals(IntArrayList.from(new int[]{34, 35, 36}), p.calcNodes()); assertEquals(3, p.calcNodes().size()); assertEquals(17, p.getDistance(), 1e-5); }
@Test public void testViaEdges_BiGraph() { GraphHopperStorage graph = createGHStorage(false); initBiGraph(graph); // 0-7 to 4-3 Path p = calcPathViaQuery(graph, 0.0009, 0, 0.001, 0.001105); assertEquals(p.toString(), IntArrayList.from(new int[]{10, 7, 6, 8, 3, 9}), p.calcNodes()); assertEquals(p.toString(), 324.11, p.getDistance(), 0.01); // 0-1 to 2-3 p = calcPathViaQuery(graph, 0.001, 0.0001, 0.010, 0.0011); assertEquals(p.toString(), IntArrayList.from(new int[]{0, 7, 6, 8, 3, 9}), p.calcNodes()); assertEquals(p.toString(), 1335.35, p.getDistance(), 0.01); }
@Test public void testCalcIf1EdgeAway() { Path p = createAlgo(createTestStorage()).calcPath(1, 2); assertEquals(IntArrayList.from(new int[]{1, 2}), p.calcNodes()); assertEquals(p.toString(), 35.1, p.getDistance(), .1); }
@Test public void testWikipediaShortestPath() { GraphHopperStorage ghStorage = createWikipediaTestGraph(); Path p = createAlgo(ghStorage).calcPath(0, 4); assertEquals(p.toString(), IntArrayList.from(new int[]{0, 2, 5, 4}), p.calcNodes()); assertEquals(p.toString(), 20, p.getDistance(), 1e-4); }
@Test public void testDirectedGraphBug2() { GraphHopperStorage graph = createGHStorage(false); graph.edge(0, 1, 1, false); graph.edge(1, 2, 1, false); graph.edge(2, 3, 1, false); graph.edge(3, 1, 4, true); Path p = createAlgo(graph).calcPath(0, 3); assertEquals(IntArrayList.from(new int[]{0, 1, 2, 3}), p.calcNodes()); }
@Test public void testCalcShortestPath() { GraphHopperStorage ghStorage = createTestStorage(); RoutingAlgorithm algo = createAlgo(ghStorage); Path p = algo.calcPath(0, 7); assertEquals(p.toString(), IntArrayList.from(new int[]{0, 4, 5, 7}), p.calcNodes()); assertEquals(p.toString(), 62.1, p.getDistance(), .1); }
@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 testCalcShortestPath_sourceEqualsTarget() { GraphHopperStorage graph = createGHStorage(false); graph.edge(0, 1, 1, true); graph.edge(1, 2, 2, true); RoutingAlgorithm algo = createAlgo(graph); Path p = algo.calcPath(0, 0); assertEquals(p.toString(), IntArrayList.from(new int[]{0}), p.calcNodes()); assertEquals(p.toString(), 0, p.getDistance(), 1.e-6); }
@Test public void testCalcFootPath() { AlgorithmOptions opts = AlgorithmOptions.start(). weighting(new ShortestWeighting(footEncoder)).build(); GraphHopperStorage ghStorage = createGHStorage(encodingManager, Arrays.asList(opts.getWeighting()), false); initFootVsCar(ghStorage); Path p1 = createAlgo(ghStorage, opts). calcPath(0, 7); assertEquals(p1.toString(), 17000, p1.getDistance(), 1e-6); assertEquals(p1.toString(), 12240 * 1000, p1.getTime()); assertEquals(IntArrayList.from(new int[]{0, 4, 5, 7}), p1.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 testBidirectionalLinear() { //3--2--1--4--5 GraphHopperStorage graph = createGHStorage(false); graph.edge(2, 1, 2, true); graph.edge(2, 3, 11, true); graph.edge(5, 4, 6, true); graph.edge(4, 1, 9, true); Path p = createAlgo(graph).calcPath(3, 5); assertEquals(p.toString(), 28, p.getDistance(), 1e-4); assertEquals(IntArrayList.from(new int[]{3, 2, 1, 4, 5}), p.calcNodes()); }