Search in sources :

Example 21 with Dijkstra

use of com.graphhopper.routing.Dijkstra in project graphhopper by graphhopper.

the class GpxConversionsTest method testInstructionsWithTimeAndPlace.

@Test
public void testInstructionsWithTimeAndPlace() {
    Graph g = new GraphBuilder(carManager).create();
    // n-4-5   (n: pillar node)
    // |
    // 7-3-2-6
    // |
    // 1
    NodeAccess na = g.getNodeAccess();
    na.setNode(1, 15.0, 10);
    na.setNode(2, 15.1, 10);
    na.setNode(3, 15.1, 9.9);
    na.setNode(4, 15.2, 9.9);
    na.setNode(5, 15.2, 10);
    na.setNode(6, 15.1, 10.1);
    na.setNode(7, 15.1, 9.8);
    GHUtility.setSpeed(63, true, true, carEncoder, g.edge(1, 2).setDistance(7000).setName("1-2"));
    GHUtility.setSpeed(72, true, true, carEncoder, g.edge(2, 3).setDistance(8000).setName("2-3"));
    GHUtility.setSpeed(9, true, true, carEncoder, g.edge(2, 6).setDistance(10000).setName("2-6"));
    GHUtility.setSpeed(81, true, true, carEncoder, g.edge(3, 4).setDistance(9000).setName("3-4"));
    GHUtility.setSpeed(9, true, true, carEncoder, g.edge(3, 7).setDistance(10000).setName("3-7"));
    GHUtility.setSpeed(90, true, true, carEncoder, g.edge(4, 5).setDistance(10000).setName("4-5"));
    ShortestWeighting weighting = new ShortestWeighting(carEncoder);
    Path p = new Dijkstra(g, weighting, TraversalMode.NODE_BASED).calcPath(1, 5);
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, g, weighting, carManager, trMap.getWithFallBack(Locale.US));
    PointList points = p.calcPoints();
    assertEquals(4, wayList.size());
    assertEquals(34000, p.getDistance(), 1e-1);
    assertEquals(34000, sumDistances(wayList), 1e-1);
    assertEquals(5, points.size());
    assertEquals(1604120, p.getTime());
    assertEquals(Instruction.CONTINUE_ON_STREET, wayList.get(0).getSign());
    assertEquals(15, wayList.get(0).getPoints().getLat(0), 1e-3);
    assertEquals(10, wayList.get(0).getPoints().getLon(0), 1e-3);
    assertEquals(Instruction.TURN_LEFT, wayList.get(1).getSign());
    assertEquals(15.1, wayList.get(1).getPoints().getLat(0), 1e-3);
    assertEquals(10, wayList.get(1).getPoints().getLon(0), 1e-3);
    assertEquals(Instruction.TURN_RIGHT, wayList.get(2).getSign());
    assertEquals(15.1, wayList.get(2).getPoints().getLat(0), 1e-3);
    assertEquals(9.9, wayList.get(2).getPoints().getLon(0), 1e-3);
    String gpxStr = GpxConversions.createGPX(wayList, "test", (long) 0, false, true, true, true, Constants.VERSION, trMap.getWithFallBack(Locale.US));
    verifyGPX(gpxStr);
    // System.out.println(gpxStr);
    assertTrue(gpxStr.contains("<trkpt lat=\"15.0\" lon=\"10.0\"><time>1970-01-01T00:00:00Z</time>"), gpxStr);
    assertTrue(gpxStr.contains("<extensions>") && gpxStr.contains("</extensions>"), gpxStr);
    assertTrue(gpxStr.contains("<rtept lat=\"15.1\" lon=\"10.0\">"), gpxStr);
    assertTrue(gpxStr.contains("<gh:distance>8000.0</gh:distance>"), gpxStr);
    assertTrue(gpxStr.contains("<desc>turn left onto 2-3</desc>"), gpxStr);
    assertTrue(gpxStr.contains("<gh:sign>-2</gh:sign>"), gpxStr);
    assertTrue(gpxStr.contains("<gh:direction>N</gh:direction>"), gpxStr);
    assertTrue(gpxStr.contains("<gh:azimuth>0.0</gh:azimuth>"), gpxStr);
    assertFalse(gpxStr.contains("NaN"));
}
Also used : Path(com.graphhopper.routing.Path) NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Dijkstra(com.graphhopper.routing.Dijkstra) Test(org.junit.jupiter.api.Test)

Aggregations

Dijkstra (com.graphhopper.routing.Dijkstra)21 Path (com.graphhopper.routing.Path)16 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)14 Test (org.junit.jupiter.api.Test)12 Graph (com.graphhopper.storage.Graph)10 GraphBuilder (com.graphhopper.storage.GraphBuilder)10 NodeAccess (com.graphhopper.storage.NodeAccess)8 Weighting (com.graphhopper.routing.weighting.Weighting)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)3 Test (org.junit.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 DijkstraBidirectionCH (com.graphhopper.routing.DijkstraBidirectionCH)2 DijkstraOneToMany (com.graphhopper.routing.DijkstraOneToMany)2 RoutingAlgorithm (com.graphhopper.routing.RoutingAlgorithm)2 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)2 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)2 EncodingManager (com.graphhopper.routing.util.EncodingManager)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 Snap (com.graphhopper.storage.index.Snap)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2