Search in sources :

Example 86 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class PathTest method testCalcInstructionForMotorwayFork.

@Test
public void testCalcInstructionForMotorwayFork() {
    final Graph graph = new GraphBuilder(carManager).create();
    final NodeAccess na = graph.getNodeAccess();
    // Actual example: point=48.909071%2C8.647136&point=48.908789%2C8.649244
    // 1-2 & 2-4 is a motorway, 2-3 is a motorway_link
    // We should skip the instruction here
    // 1 ---- 2 ---- 4
    // \
    // 3
    na.setNode(1, 48.909071, 8.647136);
    na.setNode(2, 48.908962, 8.647978);
    na.setNode(3, 48.908867, 8.648155);
    na.setNode(4, 48.908789, 8.649244);
    EnumEncodedValue<RoadClass> roadClassEnc = carManager.getEnumEncodedValue(RoadClass.KEY, RoadClass.class);
    BooleanEncodedValue roadClassLinkEnc = carManager.getBooleanEncodedValue(RoadClassLink.KEY);
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(5)).setName("A 8").set(roadClassEnc, RoadClass.MOTORWAY).set(roadClassLinkEnc, false);
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 4).setDistance(5)).setName("A 8").set(roadClassEnc, RoadClass.MOTORWAY).set(roadClassLinkEnc, false);
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 3).setDistance(5)).set(roadClassEnc, RoadClass.MOTORWAY).set(roadClassLinkEnc, true);
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    Path p = new Dijkstra(graph, weighting, TraversalMode.NODE_BASED).calcPath(1, 4);
    assertTrue(p.isFound());
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, p.graph, weighting, carManager, tr);
    assertEquals(2, wayList.size());
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.jupiter.api.Test)

Example 87 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class PathTest method testCalcInstructionContinueLeavingStreet.

@Test
public void testCalcInstructionContinueLeavingStreet() {
    final Graph g = new GraphBuilder(carManager).create();
    final NodeAccess na = g.getNodeAccess();
    // When leaving the current street via a Continue, we should show it
    // 3
    // \
    // 4 - 2   --  1
    na.setNode(1, 48.982618, 13.122021);
    na.setNode(2, 48.982565, 13.121597);
    na.setNode(3, 48.982611, 13.121012);
    na.setNode(4, 48.982565, 13.121002);
    GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 2).setDistance(5)).setName("Regener Weg");
    GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 4).setDistance(5));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 3).setDistance(5)).setName("Regener Weg");
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    Path p = new Dijkstra(g, weighting, TraversalMode.NODE_BASED).calcPath(1, 4);
    assertTrue(p.isFound());
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, p.graph, weighting, carManager, tr);
    assertEquals(3, wayList.size());
    assertEquals(-7, wayList.get(1).getSign());
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.jupiter.api.Test)

Example 88 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class PathTest method testCalcInstructionsRoundaboutIssue353.

@Test
public void testCalcInstructionsRoundaboutIssue353() {
    final Graph graph = new GraphBuilder(carManager).create();
    final NodeAccess na = graph.getNodeAccess();
    // 
    // 8
    // \
    // 5
    // /  \
    // 11- 1 - 2    4 - 7
    // |     \  /
    // 10 -9 -3
    // \    |
    // --- 6
    na.setNode(1, 52.514, 13.348);
    na.setNode(2, 52.514, 13.349);
    na.setNode(3, 52.5135, 13.35);
    na.setNode(4, 52.514, 13.351);
    na.setNode(5, 52.5145, 13.351);
    na.setNode(6, 52.513, 13.35);
    na.setNode(7, 52.514, 13.352);
    na.setNode(8, 52.515, 13.351);
    na.setNode(9, 52.5135, 13.349);
    na.setNode(10, 52.5135, 13.348);
    na.setNode(11, 52.514, 13.347);
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 1).setDistance(5)).setName("MainStreet 2 1");
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 11).setDistance(5)).setName("MainStreet 1 11");
    // roundabout
    EdgeIteratorState tmpEdge;
    tmpEdge = GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 9).setDistance(2)).setName("3-9");
    BooleanEncodedValue carManagerRoundabout = carManager.getBooleanEncodedValue(Roundabout.KEY);
    tmpEdge.set(carManagerRoundabout, true);
    tmpEdge = GHUtility.setSpeed(60, true, false, encoder, graph.edge(9, 10).setDistance(2)).setName("9-10");
    tmpEdge.set(carManagerRoundabout, true);
    tmpEdge = GHUtility.setSpeed(60, true, false, encoder, graph.edge(6, 10).setDistance(2)).setName("6-10");
    tmpEdge.set(carManagerRoundabout, true);
    tmpEdge = GHUtility.setSpeed(60, true, false, encoder, graph.edge(10, 1).setDistance(2)).setName("10-1");
    tmpEdge.set(carManagerRoundabout, true);
    tmpEdge = GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 2).setDistance(5)).setName("2-3");
    tmpEdge.set(carManagerRoundabout, true);
    tmpEdge = GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 3).setDistance(5)).setName("3-4");
    tmpEdge.set(carManagerRoundabout, true);
    tmpEdge = GHUtility.setSpeed(60, true, false, encoder, graph.edge(5, 4).setDistance(5)).setName("4-5");
    tmpEdge.set(carManagerRoundabout, true);
    tmpEdge = GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 5).setDistance(5)).setName("5-2");
    tmpEdge.set(carManagerRoundabout, true);
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 7).setDistance(5)).setName("MainStreet 4 7");
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(5, 8).setDistance(5)).setName("5-8");
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 6).setDistance(5)).setName("3-6");
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    Path p = new Dijkstra(graph, weighting, TraversalMode.NODE_BASED).calcPath(6, 11);
    assertTrue(p.isFound());
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, p.graph, weighting, carManager, tr);
    List<String> tmpList = getTurnDescriptions(wayList);
    assertEquals(Arrays.asList("At roundabout, take exit 1 onto MainStreet 1 11", "arrive at destination"), tmpList);
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.jupiter.api.Test)

Example 89 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class PathTest method testUTurnRight.

@Test
public void testUTurnRight() {
    final Graph g = new GraphBuilder(carManager).create();
    final NodeAccess na = g.getNodeAccess();
    // Real Situation: point=-33.885758,151.181472&point=-33.885692,151.181445
    // 7
    // |
    // 4----5----6
    // |
    // 3----2----1
    na.setNode(1, -33.885758, 151.181472);
    na.setNode(2, -33.885852, 151.180968);
    na.setNode(3, -33.885968, 151.180501);
    na.setNode(4, -33.885883, 151.180442);
    na.setNode(5, -33.885772, 151.180941);
    na.setNode(6, -33.885692, 151.181445);
    na.setNode(7, -33.885692, 151.181445);
    GHUtility.setSpeed(60, 0, encoder, g.edge(1, 2).setDistance(5).setName("Parramatta Road"), g.edge(2, 3).setDistance(5).setName("Parramatta Road"), g.edge(4, 5).setDistance(5).setName("Parramatta Road"), g.edge(5, 6).setDistance(5).setName("Parramatta Road"));
    GHUtility.setSpeed(60, 60, encoder, g.edge(2, 5).setDistance(5).setName("Larkin Street"), g.edge(5, 7).setDistance(5).setName("Larkin Street"));
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    Path p = new Dijkstra(g, weighting, TraversalMode.NODE_BASED).calcPath(1, 6);
    assertTrue(p.isFound());
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, p.graph, weighting, carManager, tr);
    assertEquals(3, wayList.size());
    assertEquals(Instruction.U_TURN_RIGHT, wayList.get(1).getSign());
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.jupiter.api.Test)

Example 90 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class PathTest method testCalcInstructionsMotorwayJunction.

@Test
public void testCalcInstructionsMotorwayJunction() {
    final Graph g = new GraphBuilder(carManager).create();
    final NodeAccess na = g.getNodeAccess();
    // Actual example: point=48.70672%2C9.164266&point=48.706805%2C9.162995
    // A typical motorway junction, when following 1-2-3, there should be a keep right at 2
    // -- 4
    // /
    // 1 -- 2 -- 3
    na.setNode(1, 48.70672, 9.164266);
    na.setNode(2, 48.706741, 9.163719);
    na.setNode(3, 48.706805, 9.162995);
    na.setNode(4, 48.706705, 9.16329);
    GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 2).setDistance(5)).setName("A 8");
    GHUtility.setSpeed(60, true, false, encoder, g.edge(2, 3).setDistance(5)).setName("A 8");
    GHUtility.setSpeed(60, true, false, encoder, g.edge(2, 4).setDistance(5)).setName("A 8");
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    Path p = new Dijkstra(g, weighting, TraversalMode.NODE_BASED).calcPath(1, 3);
    assertTrue(p.isFound());
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, p.graph, weighting, carManager, tr);
    assertEquals(3, wayList.size());
    // TODO this should be a keep_right
    assertEquals(0, wayList.get(1).getSign());
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.jupiter.api.Test)

Aggregations

GraphBuilder (com.graphhopper.storage.GraphBuilder)98 Test (org.junit.jupiter.api.Test)60 Graph (com.graphhopper.storage.Graph)48 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)40 NodeAccess (com.graphhopper.storage.NodeAccess)30 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)22 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)21 EncodingManager (com.graphhopper.routing.util.EncodingManager)19 Test (org.junit.Test)16 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)15 RepeatedTest (org.junit.jupiter.api.RepeatedTest)14 ConnectedComponents (com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents)12 Dijkstra (com.graphhopper.routing.Dijkstra)10 Path (com.graphhopper.routing.Path)10 ReaderWay (com.graphhopper.reader.ReaderWay)9 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)8 BeforeEach (org.junit.jupiter.api.BeforeEach)7 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)6 IntsRef (com.graphhopper.storage.IntsRef)6 Random (java.util.Random)6