Search in sources :

Example 71 with GraphBuilder

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

the class InstructionListTest method testFind.

@Test
public void testFind() {
    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);
    PointList waypoint = new PointList();
    waypoint.add(15.2, 9.9);
    na.setNode(4, 15.2, 10);
    na.setNode(5, 15.2, 10.1);
    na.setNode(6, 15.1, 10.1);
    na.setNode(7, 15.1, 9.8);
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 2).setDistance(10000)).setName("1-2");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 3).setDistance(10000)).setName("2-3");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 6).setDistance(10000)).setName("2-6");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 4).setDistance(10000)).setName("3-4").setWayGeometry(waypoint);
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 7).setDistance(10000)).setName("3-7");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(4, 5).setDistance(10000)).setName("4-5");
    ShortestWeighting weighting = new ShortestWeighting(carEncoder);
    Path p = new Dijkstra(g, weighting, tMode).calcPath(1, 5);
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, g, weighting, carManager, usTR);
    // query on first edge, get instruction for second edge
    assertEquals("2-3", Instructions.find(wayList, 15.05, 10, 1000).getName());
    // query east of first edge, get instruction for second edge
    assertEquals("2-3", Instructions.find(wayList, 15.05, 10.001, 1000).getName());
    // query south-west of node 3, get instruction for third edge
    assertEquals("3-4", Instructions.find(wayList, 15.099, 9.9, 1000).getName());
    // too far away
    assertNull(Instructions.find(wayList, 50.8, 50.25, 1000));
}
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)

Example 72 with GraphBuilder

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

the class InstructionListTest method testWayList2.

@Test
public void testWayList2() {
    Graph g = new GraphBuilder(carManager).create();
    // 2
    // \.  5
    // \/
    // 4
    // /
    // 3
    NodeAccess na = g.getNodeAccess();
    na.setNode(2, 10.3, 10.15);
    na.setNode(3, 10.0, 10.08);
    na.setNode(4, 10.1, 10.10);
    na.setNode(5, 10.2, 10.13);
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 4).setDistance(100)).setName("3-4");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(4, 5).setDistance(100)).setName("4-5");
    EdgeIteratorState iter = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 4).setDistance(100));
    iter.setName("2-4");
    PointList list = new PointList();
    list.add(10.20, 10.05);
    iter.setWayGeometry(list);
    ShortestWeighting weighting = new ShortestWeighting(carEncoder);
    Path p = new Dijkstra(g, weighting, tMode).calcPath(2, 3);
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, g, weighting, carManager, usTR);
    List<String> tmpList = getTurnDescriptions(wayList);
    assertEquals(Arrays.asList("continue onto 2-4", "turn slight right onto 3-4", "arrive at destination"), tmpList);
    p = new Dijkstra(g, weighting, tMode).calcPath(3, 5);
    wayList = InstructionsFromEdges.calcInstructions(p, g, weighting, carManager, usTR);
    tmpList = getTurnDescriptions(wayList);
    assertEquals(Arrays.asList("continue onto 3-4", "keep right onto 4-5", "arrive at destination"), tmpList);
}
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)

Example 73 with GraphBuilder

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

the class InstructionListTest method testNoInstructionIfSameStreet.

// TODO is this problem fixed with the new instructions?
// problem: we normally don't want instructions if streetname stays but here it is suboptimal:
@Test
public void testNoInstructionIfSameStreet() {
    Graph g = new GraphBuilder(carManager).create();
    // 2
    // \.  5
    // \/
    // 4
    // /
    // 3
    NodeAccess na = g.getNodeAccess();
    na.setNode(2, 10.3, 10.15);
    na.setNode(3, 10.0, 10.05);
    na.setNode(4, 10.1, 10.10);
    na.setNode(5, 10.2, 10.15);
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 4).setDistance(100)).setName("street");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(4, 5).setDistance(100)).setName("4-5");
    EdgeIteratorState iter = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 4).setDistance(100));
    iter.setName("street");
    PointList list = new PointList();
    list.add(10.20, 10.05);
    iter.setWayGeometry(list);
    ShortestWeighting weighting = new ShortestWeighting(carEncoder);
    Path p = new Dijkstra(g, weighting, tMode).calcPath(2, 3);
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, g, weighting, carManager, usTR);
    List<String> tmpList = getTurnDescriptions(wayList);
    assertEquals(Arrays.asList("continue onto street", "turn right onto street", "arrive at destination"), tmpList);
}
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)

Example 74 with GraphBuilder

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

the class InstructionListTest method createTestGraph.

Graph createTestGraph() {
    Graph g = new GraphBuilder(carManager).create();
    // 0-1-2
    // | | |
    // 3-4-5  9-10
    // | | |  |
    // 6-7-8--*
    NodeAccess na = g.getNodeAccess();
    na.setNode(0, 1.2, 1.0);
    na.setNode(1, 1.2, 1.1);
    na.setNode(2, 1.2, 1.2);
    na.setNode(3, 1.1, 1.0);
    na.setNode(4, 1.1, 1.1);
    na.setNode(5, 1.1, 1.2);
    na.setNode(9, 1.1, 1.3);
    na.setNode(10, 1.1, 1.4);
    na.setNode(6, 1.0, 1.0);
    na.setNode(7, 1.0, 1.1);
    na.setNode(8, 1.0, 1.2);
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(0, 1).setDistance(10000)).setName("0-1");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 2).setDistance(11000)).setName("1-2");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(0, 3).setDistance(11000));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 4).setDistance(10000)).setName("1-4");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 5).setDistance(11000)).setName("5-2");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 6).setDistance(11000)).setName("3-6");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(4, 7).setDistance(10000)).setName("4-7");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(5, 8).setDistance(10000)).setName("5-8");
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(6, 7).setDistance(11000)).setName("6-7");
    EdgeIteratorState iter = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(7, 8).setDistance(10000));
    PointList list = new PointList();
    list.add(1.0, 1.15);
    list.add(1.0, 1.16);
    iter.setWayGeometry(list);
    iter.setName("7-8");
    // missing edge name
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(9, 10).setDistance(10000));
    EdgeIteratorState iter2 = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(8, 9).setDistance(20000));
    list.clear();
    list.add(1.0, 1.3);
    iter2.setName("8-9");
    iter2.setWayGeometry(list);
    return g;
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder)

Example 75 with GraphBuilder

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

the class InstructionListTest method testNoInstructionIfSlightTurnAndAlternativeIsSharp.

@Test
public void testNoInstructionIfSlightTurnAndAlternativeIsSharp() {
    Graph g = new GraphBuilder(carManager).create();
    // Real World Example: https://graphhopper.com/maps/?point=51.734514%2C9.225571&point=51.734643%2C9.22541
    // https://github.com/graphhopper/graphhopper/issues/1441
    // From 1 to 3
    // 
    // 3
    // |
    // 2
    // /\
    // 4  1
    NodeAccess na = g.getNodeAccess();
    na.setNode(1, 51.734514, 9.225571);
    na.setNode(2, 51.73458, 9.225442);
    na.setNode(3, 51.734643, 9.22541);
    na.setNode(4, 51.734451, 9.225436);
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 2).setDistance(10));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 3).setDistance(10));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 4).setDistance(10));
    ShortestWeighting weighting = new ShortestWeighting(carEncoder);
    Path p = new Dijkstra(g, weighting, tMode).calcPath(1, 3);
    InstructionList wayList = InstructionsFromEdges.calcInstructions(p, g, weighting, carManager, usTR);
    List<String> tmpList = getTurnDescriptions(wayList);
    assertEquals(Arrays.asList("continue", "arrive at destination"), tmpList);
}
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

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