Path calcPathViaQuery(GraphHopperStorage ghStorage, double fromLat, double fromLon, double toLat, double toLon) { return calcPathViaQuery(defaultOpts.getWeighting(), ghStorage, fromLat, fromLon, toLat, toLon); }
@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 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 testViaEdges_SpecialCases() { GraphHopperStorage graph = createGHStorage(false); // 0->1\ // | 2 // 4<-3/ graph.edge(0, 1, 7, false); graph.edge(1, 2, 7, true); graph.edge(2, 3, 7, true); graph.edge(3, 4, 7, false); graph.edge(4, 0, 7, true); updateDistancesFor(graph, 4, 0, 0); updateDistancesFor(graph, 0, 0.00010, 0); updateDistancesFor(graph, 1, 0.00010, 0.0001); updateDistancesFor(graph, 2, 0.00005, 0.00015); updateDistancesFor(graph, 3, 0, 0.0001); // 0-1 to 3-4 Path p = calcPathViaQuery(graph, 0.00010, 0.00001, 0, 0.00009); assertEquals(IntArrayList.from(new int[]{5, 1, 2, 3, 6}), p.calcNodes()); assertEquals(p.toString(), 26.81, p.getDistance(), .1); // overlapping edges: 2-3 and 3-2 p = calcPathViaQuery(graph, 0.000049, 0.00014, 0.00001, 0.0001); assertEquals(IntArrayList.from(new int[]{5, 6}), p.calcNodes()); assertEquals(p.toString(), 6.2, p.getDistance(), .1); // 'from' and 'to' edge share one node '2': 1-2 to 3-2 p = calcPathViaQuery(graph, 0.00009, 0.00011, 0.00001, 0.00011); assertEquals(p.toString(), IntArrayList.from(new int[]{6, 2, 5}), p.calcNodes()); assertEquals(p.toString(), 12.57, p.getDistance(), .1); }
@Test public void testViaEdges_FromEqualsTo() { GraphHopperStorage ghStorage = createTestStorage(); // identical tower nodes Path p = calcPathViaQuery(ghStorage, 0.001, 0.000, 0.001, 0.000); assertTrue(p.isFound()); assertEquals(IntArrayList.from(new int[]{0}), p.calcNodes()); // assertEquals(1, p.calcPoints().size()); assertEquals(p.toString(), 0, p.getDistance(), 1e-4); // identical query points on edge p = calcPath(ghStorage, 0, 1, 0, 1); assertTrue(p.isFound()); assertEquals(IntArrayList.from(new int[]{8}), p.calcNodes()); // assertEquals(1, p.calcPoints().size()); assertEquals(p.toString(), 0, p.getDistance(), 1e-4); // very close p = calcPathViaQuery(ghStorage, 0.00092, 0, 0.00091, 0); assertEquals(IntArrayList.from(new int[]{8, 9}), p.calcNodes()); assertEquals(p.toString(), 1.11, p.getDistance(), .1); }