Search in sources :

Example 11 with GraphBuilder

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

the class PathTest method testCalcInstructionsEnterMotorway.

@Test
public void testCalcInstructionsEnterMotorway() {
    final Graph graph = new GraphBuilder(carManager).create();
    final NodeAccess na = graph.getNodeAccess();
    // Actual example: point=48.630533%2C9.459416&point=48.630544%2C9.459829
    // 1 -2 -3 is a motorway and tagged as oneway
    // 1 ->- 2 ->- 3
    // /
    // 4
    na.setNode(1, 48.630647, 9.459041);
    na.setNode(2, 48.630586, 9.459604);
    na.setNode(3, 48.630558, 9.459851);
    na.setNode(4, 48.63054, 9.459406);
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 2).setDistance(5)).setName("A 8");
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 3).setDistance(5)).setName("A 8");
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 2).setDistance(5)).setName("A 8");
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    Path p = new Dijkstra(graph, weighting, TraversalMode.NODE_BASED).calcPath(4, 3);
    assertTrue(p.isFound());
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, p.graph, weighting, carManager, tr);
    // no turn instruction for entering the highway
    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 12 with GraphBuilder

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

the class PathTest method testUTurnLeft.

@Test
public void testUTurnLeft() {
    final Graph g = new GraphBuilder(carManager).create();
    final NodeAccess na = g.getNodeAccess();
    // Real Situation: point=48.402116%2C9.994367&point=48.402198%2C9.99507
    // 7
    // |
    // 4----5----6
    // |
    // 1----2----3
    na.setNode(1, 48.402116, 9.994367);
    na.setNode(2, 48.402198, 9.99507);
    na.setNode(3, 48.402344, 9.996266);
    na.setNode(4, 48.402191, 9.994351);
    na.setNode(5, 48.402298, 9.995053);
    na.setNode(6, 48.402422, 9.996067);
    na.setNode(7, 48.402604, 9.994962);
    GHUtility.setSpeed(60, 0, encoder, g.edge(1, 2).setDistance(5).setName("Olgastraße"), g.edge(2, 3).setDistance(5).setName("Olgastraße"), g.edge(6, 5).setDistance(5).setName("Olgastraße"), g.edge(5, 4).setDistance(5).setName("Olgastraße"));
    GHUtility.setSpeed(60, 60, encoder, g.edge(2, 5).setDistance(5).setName("Neithardtstraße"), g.edge(5, 7).setDistance(5).setName("Neithardtstraße"));
    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(Instruction.U_TURN_LEFT, 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 13 with GraphBuilder

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

the class PathTest method testCalcInstructionSlightTurn.

@Test
public void testCalcInstructionSlightTurn() {
    final Graph g = new GraphBuilder(carManager).create();
    final NodeAccess na = g.getNodeAccess();
    // Real Situation: point=48.411927%2C15.599197&point=48.412094%2C15.598816
    // When reaching this Crossing, you cannot know if you should turn left or right
    // Google Maps and Bing show a turn, OSRM does not
    // 1 ---2--- 3
    // \
    // 4
    na.setNode(1, 48.412094, 15.598816);
    na.setNode(2, 48.412055, 15.599068);
    na.setNode(3, 48.412034, 15.599411);
    na.setNode(4, 48.411927, 15.599197);
    GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 2).setDistance(5)).setName("Stöhrgasse");
    GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 3).setDistance(5));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 4).setDistance(5)).setName("Stöhrgasse");
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    Path p = new Dijkstra(g, weighting, TraversalMode.NODE_BASED).calcPath(4, 1);
    assertTrue(p.isFound());
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, p.graph, weighting, carManager, tr);
    assertEquals(3, wayList.size());
    assertEquals(-1, 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 14 with GraphBuilder

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

the class PathTest method generatePathDetailsGraph.

private Graph generatePathDetailsGraph() {
    final Graph graph = new GraphBuilder(carManager).create();
    final NodeAccess na = graph.getNodeAccess();
    na.setNode(1, 52.514, 13.348);
    na.setNode(2, 52.514, 13.349);
    na.setNode(3, 52.514, 13.350);
    na.setNode(4, 52.515, 13.349);
    na.setNode(5, 52.516, 13.3452);
    na.setNode(6, 52.516, 13.344);
    ReaderWay w = new ReaderWay(1);
    w.setTag("highway", "tertiary");
    w.setTag("maxspeed", "50");
    EdgeIteratorState tmpEdge;
    tmpEdge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(5)).setName("1-2");
    assertNotEquals(EncodingManager.Access.CAN_SKIP, ((AbstractFlagEncoder) encoder).getAccess(w));
    IntsRef relFlags = carManager.createRelationFlags();
    tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
    tmpEdge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 5).setDistance(5)).setName("4-5");
    tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
    w.setTag("maxspeed", "100");
    tmpEdge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 3).setDistance(5)).setName("2-3");
    tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
    w.setTag("maxspeed", "10");
    tmpEdge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 4).setDistance(10)).setName("3-4");
    tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
    tmpEdge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(5, 6).setDistance(0.01)).setName("3-4");
    tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
    return graph;
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef)

Example 15 with GraphBuilder

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

the class PathTest method testCalcInstructionsOntoOneway.

@Test
public void testCalcInstructionsOntoOneway() {
    final Graph g = new GraphBuilder(carManager).create();
    final NodeAccess na = g.getNodeAccess();
    // Actual example: point=-33.824566%2C151.187834&point=-33.82441%2C151.188231
    // 1 -2 -3 is a oneway
    // 1 ->- 2 ->- 3
    // |
    // 4
    na.setNode(1, -33.824245, 151.187866);
    na.setNode(2, -33.824335, 151.188017);
    na.setNode(3, -33.824415, 151.188177);
    na.setNode(4, -33.824437, 151.187925);
    GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 2).setDistance(5)).setName("Pacific Highway");
    GHUtility.setSpeed(60, true, false, encoder, g.edge(2, 3).setDistance(5)).setName("Pacific Highway");
    GHUtility.setSpeed(60, true, true, encoder, g.edge(4, 2).setDistance(5)).setName("Greenwich Road");
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    Path p = new Dijkstra(g, weighting, TraversalMode.NODE_BASED).calcPath(4, 3);
    assertTrue(p.isFound());
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, p.graph, weighting, carManager, tr);
    assertEquals(3, wayList.size());
    assertEquals(2, 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