use of com.graphhopper.routing.QueryGraph in project graphhopper by graphhopper.
the class GraphHopperStorageCHTest method testQueryGraph.
@Test
public void testQueryGraph() {
graph = createGHStorage();
CHGraph chGraph = getGraph(graph);
NodeAccess na = chGraph.getNodeAccess();
na.setNode(0, 1.00, 1.00);
na.setNode(1, 1.02, 1.00);
na.setNode(2, 1.04, 1.00);
EdgeIteratorState edge1 = chGraph.edge(0, 1);
chGraph.edge(1, 2);
graph.freeze();
chGraph.shortcut(0, 1);
QueryGraph qGraph = new QueryGraph(chGraph);
QueryResult fromRes = createQR(1.004, 1.01, 0, edge1);
QueryResult toRes = createQR(1.019, 1.00, 0, edge1);
qGraph.lookup(fromRes, toRes);
Graph baseGraph = qGraph.getBaseGraph();
EdgeExplorer explorer = baseGraph.createEdgeExplorer();
assertTrue(chGraph.getNodes() < qGraph.getNodes());
assertTrue(baseGraph.getNodes() == qGraph.getNodes());
// traverse virtual edges and normal edges but no shortcuts!
assertEquals(GHUtility.asSet(fromRes.getClosestNode()), GHUtility.getNeighbors(explorer.setBaseNode(0)));
assertEquals(GHUtility.asSet(toRes.getClosestNode(), 2), GHUtility.getNeighbors(explorer.setBaseNode(1)));
// get neighbors from virtual nodes
assertEquals(GHUtility.asSet(0, toRes.getClosestNode()), GHUtility.getNeighbors(explorer.setBaseNode(fromRes.getClosestNode())));
assertEquals(GHUtility.asSet(1, fromRes.getClosestNode()), GHUtility.getNeighbors(explorer.setBaseNode(toRes.getClosestNode())));
}
Aggregations