Search in sources :

Example 21 with Graph

use of com.graphhopper.storage.Graph 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);
    g.edge(1, 2, 10000, true).setName("1-2");
    g.edge(2, 3, 10000, true).setName("2-3");
    g.edge(2, 6, 10000, true).setName("2-6");
    g.edge(3, 4, 10000, true).setName("3-4").setWayGeometry(waypoint);
    g.edge(3, 7, 10000, true).setName("3-7");
    g.edge(4, 5, 10000, true).setName("4-5");
    Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(1, 5);
    InstructionList wayList = p.calcInstructions(usTR);
    // query on first edge, get instruction for second edge
    assertEquals("2-3", wayList.find(15.05, 10, 1000).getName());
    // query east of first edge, get instruction for second edge
    assertEquals("2-3", wayList.find(15.05, 10.001, 1000).getName());
    // query south-west of node 3, get instruction for third edge
    assertEquals("3-4", wayList.find(15.099, 9.9, 1000).getName());
}
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.Test)

Example 22 with Graph

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

the class InstructionListTest method testWayList.

@SuppressWarnings("unchecked")
@Test
public void testWayList() {
    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);
    g.edge(0, 1, 10000, true).setName("0-1");
    g.edge(1, 2, 11000, true).setName("1-2");
    g.edge(0, 3, 11000, true);
    g.edge(1, 4, 10000, true).setName("1-4");
    g.edge(2, 5, 11000, true).setName("5-2");
    g.edge(3, 6, 11000, true).setName("3-6");
    g.edge(4, 7, 10000, true).setName("4-7");
    g.edge(5, 8, 10000, true).setName("5-8");
    g.edge(6, 7, 11000, true).setName("6-7");
    EdgeIteratorState iter = g.edge(7, 8, 10000, true);
    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
    g.edge(9, 10, 10000, true);
    EdgeIteratorState iter2 = g.edge(8, 9, 20000, true);
    list.clear();
    list.add(1.0, 1.3);
    iter2.setName("8-9");
    iter2.setWayGeometry(list);
    Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(0, 10);
    InstructionList wayList = p.calcInstructions(usTR);
    List<String> tmpList = pick("text", wayList.createJson());
    assertEquals(Arrays.asList("Continue onto 0-1", "Turn right onto 1-4", "Turn left onto 7-8", "Arrive at destination"), tmpList);
    wayList = p.calcInstructions(trMap.getWithFallBack(Locale.GERMAN));
    tmpList = pick("text", wayList.createJson());
    assertEquals(Arrays.asList("Dem Straßenverlauf von 0-1 folgen", "Rechts abbiegen auf 1-4", "Links abbiegen auf 7-8", "Ziel erreicht"), tmpList);
    assertEquals(70000.0, sumDistances(wayList), 1e-1);
    List<GPXEntry> gpxes = wayList.createGPXList();
    assertEquals(10, gpxes.size());
    // check order of tower nodes
    assertEquals(1, gpxes.get(0).getLon(), 1e-6);
    assertEquals(1.4, gpxes.get(gpxes.size() - 1).getLon(), 1e-6);
    // check order of pillar nodes
    assertEquals(1.15, gpxes.get(4).getLon(), 1e-6);
    assertEquals(1.16, gpxes.get(5).getLon(), 1e-6);
    assertEquals(1.16, gpxes.get(5).getLon(), 1e-6);
    compare(Arrays.asList(asL(1.2d, 1.0d), asL(1.2d, 1.1), asL(1.0, 1.1), asL(1.1, 1.4)), wayList.createStartPoints());
    p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(6, 2);
    assertEquals(42000, p.getDistance(), 1e-2);
    assertEquals(Helper.createTList(6, 7, 8, 5, 2), p.calcNodes());
    wayList = p.calcInstructions(usTR);
    tmpList = pick("text", wayList.createJson());
    assertEquals(Arrays.asList("Continue onto 6-7", "Turn left onto 5-8", "Arrive at destination"), tmpList);
    compare(Arrays.asList(asL(1d, 1d), asL(1d, 1.2), asL(1.2, 1.2)), wayList.createStartPoints());
    // special case of identical start and end
    p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(0, 0);
    wayList = p.calcInstructions(usTR);
    assertEquals(1, wayList.size());
    assertEquals("arrive at destination", wayList.get(0).getTurnDescription(usTR));
}
Also used : Path(com.graphhopper.routing.Path) NodeAccess(com.graphhopper.storage.NodeAccess) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Dijkstra(com.graphhopper.routing.Dijkstra) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Example 23 with Graph

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

the class InstructionListTest 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);
    g.edge(1, 2, 7000, true).setName("1-2").setFlags(flagsForSpeed(carManager, 70));
    g.edge(2, 3, 8000, true).setName("2-3").setFlags(flagsForSpeed(carManager, 80));
    g.edge(2, 6, 10000, true).setName("2-6").setFlags(flagsForSpeed(carManager, 10));
    g.edge(3, 4, 9000, true).setName("3-4").setFlags(flagsForSpeed(carManager, 90));
    g.edge(3, 7, 10000, true).setName("3-7").setFlags(flagsForSpeed(carManager, 10));
    g.edge(4, 5, 10000, true).setName("4-5").setFlags(flagsForSpeed(carManager, 100));
    Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(1, 5);
    InstructionList wayList = p.calcInstructions(usTR);
    assertEquals(4, wayList.size());
    List<GPXEntry> gpxList = wayList.createGPXList();
    assertEquals(34000, p.getDistance(), 1e-1);
    assertEquals(34000, sumDistances(wayList), 1e-1);
    assertEquals(5, gpxList.size());
    assertEquals(1604120, p.getTime());
    assertEquals(1604120, gpxList.get(gpxList.size() - 1).getTime());
    assertEquals(Instruction.CONTINUE_ON_STREET, wayList.get(0).getSign());
    assertEquals(15, wayList.get(0).getFirstLat(), 1e-3);
    assertEquals(10, wayList.get(0).getFirstLon(), 1e-3);
    assertEquals(Instruction.TURN_LEFT, wayList.get(1).getSign());
    assertEquals(15.1, wayList.get(1).getFirstLat(), 1e-3);
    assertEquals(10, wayList.get(1).getFirstLon(), 1e-3);
    assertEquals(Instruction.TURN_RIGHT, wayList.get(2).getSign());
    assertEquals(15.1, wayList.get(2).getFirstLat(), 1e-3);
    assertEquals(9.9, wayList.get(2).getFirstLon(), 1e-3);
    String gpxStr = wayList.createGPX("test", 0);
    verifyGPX(gpxStr);
    assertTrue(gpxStr, gpxStr.contains("<trkpt lat=\"15.0\" lon=\"10.0\"><time>1970-01-01T00:00:00Z</time>"));
    assertTrue(gpxStr, gpxStr.contains("<extensions>") && gpxStr.contains("</extensions>"));
    assertTrue(gpxStr, gpxStr.contains("<rtept lat=\"15.1\" lon=\"10.0\">"));
    assertTrue(gpxStr, gpxStr.contains("<gh:distance>8000.0</gh:distance>"));
    assertTrue(gpxStr, gpxStr.contains("<desc>turn left onto 2-3</desc>"));
    assertTrue(gpxStr, gpxStr.contains("<gh:sign>-2</gh:sign>"));
    assertTrue(gpxStr, gpxStr.contains("<gh:direction>N</gh:direction>"));
    assertTrue(gpxStr, gpxStr.contains("<gh:azimuth>0.0</gh:azimuth>"));
    assertFalse(gpxStr, 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.Test)

Example 24 with Graph

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

the class PathSimplificationTest method testScenario.

@Test
public void testScenario() {
    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);
    ReaderWay w = new ReaderWay(1);
    w.setTag("highway", "tertiary");
    w.setTag("maxspeed", "10");
    EdgeIteratorState tmpEdge;
    tmpEdge = g.edge(0, 1, 10000, true).setName("0-1");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(1, 2, 11000, true).setName("1-2");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    w.setTag("maxspeed", "20");
    tmpEdge = g.edge(0, 3, 11000, true);
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(1, 4, 10000, true).setName("1-4");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(2, 5, 11000, true).setName("5-2");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    w.setTag("maxspeed", "30");
    tmpEdge = g.edge(3, 6, 11000, true).setName("3-6");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(4, 7, 10000, true).setName("4-7");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(5, 8, 10000, true).setName("5-8");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    w.setTag("maxspeed", "40");
    tmpEdge = g.edge(6, 7, 11000, true).setName("6-7");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(7, 8, 10000, true);
    PointList list = new PointList();
    list.add(1.0, 1.15);
    list.add(1.0, 1.16);
    tmpEdge.setWayGeometry(list);
    tmpEdge.setName("7-8");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    w.setTag("maxspeed", "50");
    // missing edge name
    tmpEdge = g.edge(9, 10, 10000, true);
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(8, 9, 20000, true);
    list.clear();
    list.add(1.0, 1.3);
    list.add(1.0, 1.3001);
    list.add(1.0, 1.3002);
    list.add(1.0, 1.3003);
    tmpEdge.setName("8-9");
    tmpEdge.setWayGeometry(list);
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    // Path is: [0 0-1, 3 1-4, 6 4-7, 9 7-8, 11 8-9, 10 9-10]
    Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(0, 10);
    InstructionList wayList = p.calcInstructions(usTR);
    Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(DETAILS.AVERAGE_SPEED), new PathDetailsBuilderFactory(), 0);
    PathWrapper pathWrapper = new PathWrapper();
    pathWrapper.setInstructions(wayList);
    pathWrapper.addPathDetails(details);
    pathWrapper.setPoints(p.calcPoints());
    int numberOfPoints = p.calcPoints().size();
    DouglasPeucker douglasPeucker = new DouglasPeucker();
    // Do not simplify anything
    douglasPeucker.setMaxDistance(0);
    PathSimplification ps = new PathSimplification(pathWrapper, douglasPeucker, true);
    ps.simplify();
    assertEquals(numberOfPoints, pathWrapper.getPoints().size());
    pathWrapper = new PathWrapper();
    pathWrapper.setInstructions(wayList);
    pathWrapper.addPathDetails(details);
    pathWrapper.setPoints(p.calcPoints());
    douglasPeucker.setMaxDistance(100000000);
    ps = new PathSimplification(pathWrapper, douglasPeucker, true);
    ps.simplify();
    assertTrue(numberOfPoints > pathWrapper.getPoints().size());
}
Also used : Path(com.graphhopper.routing.Path) NodeAccess(com.graphhopper.storage.NodeAccess) ReaderWay(com.graphhopper.reader.ReaderWay) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Dijkstra(com.graphhopper.routing.Dijkstra) Graph(com.graphhopper.storage.Graph) PathWrapper(com.graphhopper.PathWrapper) PathDetailsBuilderFactory(com.graphhopper.util.details.PathDetailsBuilderFactory) GraphBuilder(com.graphhopper.storage.GraphBuilder) List(java.util.List) Test(org.junit.Test)

Example 25 with Graph

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

the class RoutingAlgorithmWithOSMIT method testMonacoFoot.

@Test
public void testMonacoFoot() {
    Graph g = runAlgo(testCollector, DIR + "/monaco.osm.gz", "target/monaco-gh", createMonacoFoot(), "foot", true, "foot", "shortest", false);
    assertEquals(testCollector.toString(), 0, testCollector.errors.size());
    // see testMonaco for a similar ID test
    assertEquals(GHUtility.asSet(2, 909, 571), GHUtility.getNeighbors(g.createEdgeExplorer().setBaseNode(10)));
    assertEquals(GHUtility.asSet(444, 956, 740), GHUtility.getNeighbors(g.createEdgeExplorer().setBaseNode(441)));
    assertEquals(GHUtility.asSet(911, 404, 122, 914), GHUtility.getNeighbors(g.createEdgeExplorer().setBaseNode(912)));
    assertEquals(43.743705, g.getNodeAccess().getLat(100), 1e-6);
    assertEquals(7.426362, g.getNodeAccess().getLon(702), 1e-6);
}
Also used : Graph(com.graphhopper.storage.Graph) Test(org.junit.Test)

Aggregations

Graph (com.graphhopper.storage.Graph)47 Test (org.junit.Test)40 GraphBuilder (com.graphhopper.storage.GraphBuilder)21 NodeAccess (com.graphhopper.storage.NodeAccess)18 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)9 EdgeExplorer (com.graphhopper.util.EdgeExplorer)8 Dijkstra (com.graphhopper.routing.Dijkstra)7 Path (com.graphhopper.routing.Path)7 EncodingManager (com.graphhopper.routing.util.EncodingManager)6 RAMDirectory (com.graphhopper.storage.RAMDirectory)5 ReaderWay (com.graphhopper.reader.ReaderWay)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)4 GHRequest (com.graphhopper.GHRequest)3 GHResponse (com.graphhopper.GHResponse)3 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)3 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 CHGraph (com.graphhopper.storage.CHGraph)3 BBox (com.graphhopper.util.shapes.BBox)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3