use of com.graphhopper.storage.Graph in project graphhopper by graphhopper.
the class LocationIndexTreeTest method testSnappedPointAndGeometry.
@Test
public void testSnappedPointAndGeometry() {
Graph graph = createTestGraph(encodingManager);
LocationIndex index = createIndex(graph, -1);
// query directly the tower node
QueryResult res = index.findClosest(-0.4, 0.9, EdgeFilter.ALL_EDGES);
assertTrue(res.isValid());
assertEquals(new GHPoint(-0.4, 0.9), res.getSnappedPoint());
res = index.findClosest(-0.6, 1.6, EdgeFilter.ALL_EDGES);
assertTrue(res.isValid());
assertEquals(new GHPoint(-0.6, 1.6), res.getSnappedPoint());
// query the edge (1,3). The edge (0,4) has 27674 as distance
res = index.findClosest(-0.2, 0.3, EdgeFilter.ALL_EDGES);
assertTrue(res.isValid());
assertEquals(26936, res.getQueryDistance(), 1);
assertEquals(new GHPoint(-0.441624, 0.317259), res.getSnappedPoint());
}
use of com.graphhopper.storage.Graph in project graphhopper by graphhopper.
the class LocationIndexTreeTest method testMoreReal.
@Test
public void testMoreReal() {
Graph graph = createGHStorage(new EncodingManager("car"));
NodeAccess na = graph.getNodeAccess();
na.setNode(1, 51.2492152, 9.4317166);
na.setNode(0, 52, 9);
na.setNode(2, 51.2, 9.4);
na.setNode(3, 49, 10);
graph.edge(1, 0, 1000, true);
graph.edge(0, 2, 1000, true);
graph.edge(0, 3, 1000, true).setWayGeometry(Helper.createPointList(51.21, 9.43));
LocationIndex index = createIndex(graph, -1);
assertEquals(2, findID(index, 51.2, 9.4));
}
use of com.graphhopper.storage.Graph in project graphhopper by graphhopper.
the class BreadthFirstSearchTest method testBFS.
@Test
public void testBFS() {
BreadthFirstSearch bfs = new BreadthFirstSearch() {
@Override
public boolean goFurther(int v) {
counter++;
assertTrue("v " + v + " is already contained in set. iteration:" + counter, !set.contains(v));
set.add(v);
list.add(v);
return super.goFurther(v);
}
};
Graph g = new GraphBuilder(new EncodingManager("car")).create();
g.edge(0, 1, 85, true);
g.edge(0, 2, 217, true);
g.edge(0, 3, 173, true);
g.edge(0, 5, 173, true);
g.edge(1, 6, 75, true);
g.edge(2, 7, 51, true);
g.edge(3, 8, 23, true);
g.edge(4, 8, 793, true);
g.edge(8, 10, 343, true);
g.edge(6, 9, 72, true);
g.edge(9, 10, 8, true);
g.edge(5, 10, 1, true);
bfs.start(g.createEdgeExplorer(), 0);
assertTrue(counter > 0);
assertEquals(g.getNodes(), counter);
assertEquals("[0, 5, 3, 2, 1, 10, 8, 7, 6, 9, 4]", list.toString());
}
use of com.graphhopper.storage.Graph in project graphhopper by graphhopper.
the class BreadthFirstSearchTest method testBFS2.
@Test
public void testBFS2() {
BreadthFirstSearch bfs = new BreadthFirstSearch() {
@Override
public boolean goFurther(int v) {
counter++;
assertTrue("v " + v + " is already contained in set. iteration:" + counter, !set.contains(v));
set.add(v);
list.add(v);
return super.goFurther(v);
}
};
Graph g = new GraphBuilder(new EncodingManager("car")).create();
g.edge(1, 2, 1, false);
g.edge(2, 3, 1, false);
g.edge(3, 4, 1, false);
g.edge(1, 5, 1, false);
g.edge(5, 6, 1, false);
g.edge(6, 4, 1, false);
bfs.start(g.createEdgeExplorer(), 1);
assertTrue(counter > 0);
assertEquals("[1, 5, 2, 6, 3, 4]", list.toString());
}
use of com.graphhopper.storage.Graph in project graphhopper by graphhopper.
the class DepthFirstSearchTest method testDFS1.
@Test
public void testDFS1() {
DepthFirstSearch dfs = new DepthFirstSearch() {
@Override
public boolean goFurther(int v) {
counter++;
assertTrue("v " + v + " is already contained in set. iteration:" + counter, !set.contains(v));
set.add(v);
list.add(v);
return super.goFurther(v);
}
};
EncodingManager em = new EncodingManager("car");
FlagEncoder fe = em.getEncoder("car");
Graph g = new GraphBuilder(em).create();
g.edge(1, 2, 1, false);
g.edge(1, 5, 1, false);
g.edge(1, 4, 1, false);
g.edge(2, 3, 1, false);
g.edge(3, 4, 1, false);
g.edge(5, 6, 1, false);
g.edge(6, 4, 1, false);
dfs.start(g.createEdgeExplorer(new DefaultEdgeFilter(fe, false, true)), 1);
assertTrue(counter > 0);
assertEquals("[1, 2, 3, 4, 5, 6]", list.toString());
}
Aggregations