Search in sources :

Example 16 with Graph

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

the class PrincetonReaderTest method testRead.

@Test
public void testRead() {
    Graph graph = new GraphBuilder(encodingManager).create();
    new PrincetonReader(graph).setStream(PrincetonReader.class.getResourceAsStream("tinyEWD.txt")).read();
    assertEquals(8, graph.getNodes());
    EdgeExplorer explorer = graph.createEdgeExplorer(carOutEdges);
    assertEquals(2, count(explorer.setBaseNode(0)));
    assertEquals(3, count(explorer.setBaseNode(6)));
}
Also used : Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Example 17 with Graph

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

the class LocationIndexTreeTest method createTestGraphWithWayGeometry.

// -1    0   1 1.5
// --------------------
// 1|         --A
// |    -0--/   \
// 0|   / | B-\   \
// |  /  1/   3--4
// |  |/------/  /
// -1|  2---------/
// |
private Graph createTestGraphWithWayGeometry() {
    Graph graph = createGHStorage(encodingManager);
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0.5, -0.5);
    na.setNode(1, -0.5, -0.5);
    na.setNode(2, -1, -1);
    na.setNode(3, -0.4, 0.9);
    na.setNode(4, -0.6, 1.6);
    graph.edge(0, 1, 1, true);
    graph.edge(0, 2, 1, true);
    // insert A and B, without this we would get 0 for 0,0
    graph.edge(0, 4, 1, true).setWayGeometry(Helper.createPointList(1, 1));
    graph.edge(1, 3, 1, true).setWayGeometry(Helper.createPointList(0, 0));
    graph.edge(2, 3, 1, true);
    graph.edge(2, 4, 1, true);
    graph.edge(3, 4, 1, true);
    return graph;
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph)

Example 18 with Graph

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

the class LocationIndexTreeTest method createTestGraph.

// 0------\
// /|       \
// |1----3-\|
// |____/   4
// 2-------/
Graph createTestGraph(EncodingManager em) {
    Graph graph = createGHStorage(new RAMDirectory(), em, false);
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0.5, -0.5);
    na.setNode(1, -0.5, -0.5);
    na.setNode(2, -1, -1);
    na.setNode(3, -0.4, 0.9);
    na.setNode(4, -0.6, 1.6);
    graph.edge(0, 1, 1, true);
    graph.edge(0, 2, 1, true);
    graph.edge(0, 4, 1, true);
    graph.edge(1, 3, 1, true);
    graph.edge(2, 3, 1, true);
    graph.edge(2, 4, 1, true);
    graph.edge(3, 4, 1, true);
    return graph;
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) RAMDirectory(com.graphhopper.storage.RAMDirectory)

Example 19 with Graph

use of com.graphhopper.storage.Graph 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);
    g.edge(3, 4, 100, true).setName("street");
    g.edge(4, 5, 100, true).setName("4-5");
    EdgeIteratorState iter = g.edge(2, 4, 100, true);
    iter.setName("street");
    PointList list = new PointList();
    list.add(10.20, 10.05);
    iter.setWayGeometry(list);
    Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(2, 3);
    InstructionList wayList = p.calcInstructions(usTR);
    List<String> tmpList = pick("text", wayList.createJson());
    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.Test)

Example 20 with Graph

use of com.graphhopper.storage.Graph 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);
    g.edge(3, 4, 100, true).setName("3-4");
    g.edge(4, 5, 100, true).setName("4-5");
    EdgeIteratorState iter = g.edge(2, 4, 100, true);
    iter.setName("2-4");
    PointList list = new PointList();
    list.add(10.20, 10.05);
    iter.setWayGeometry(list);
    Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(2, 3);
    InstructionList wayList = p.calcInstructions(usTR);
    List<String> tmpList = pick("text", wayList.createJson());
    assertEquals(Arrays.asList("Continue onto 2-4", "Turn slight right onto 3-4", "Arrive at destination"), tmpList);
    p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(3, 5);
    wayList = p.calcInstructions(usTR);
    tmpList = pick("text", wayList.createJson());
    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.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