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)));
}
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;
}
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;
}
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);
}
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);
}
Aggregations