use of com.graphhopper.routing.querygraph.QueryGraph in project graphhopper by graphhopper.
the class QueryRoutingCHGraphTest method basic.
@Test
public void basic() {
// 0-1-2
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(10));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(10));
graph.freeze();
assertEquals(2, graph.getEdges());
CHConfig chConfig = CHConfig.edgeBased("x", weighting);
CHStorage chStore = graph.createCHStorage(chConfig);
RoutingCHGraph routingCHGraph = graph.createCHGraph(chStore, chConfig);
QueryGraph queryGraph = QueryGraph.create(graph, Collections.<Snap>emptyList());
QueryRoutingCHGraph queryCHGraph = new QueryRoutingCHGraph(routingCHGraph, queryGraph);
assertEquals(3, queryCHGraph.getNodes());
assertEquals(2, queryCHGraph.getEdges());
assertTrue(queryCHGraph.isEdgeBased());
assertTrue(queryCHGraph.hasTurnCosts());
assertNodesConnected(queryCHGraph, 0, 1, true);
assertNodesConnected(queryCHGraph, 1, 2, true);
RoutingCHEdgeIterator outIter = queryCHGraph.createOutEdgeExplorer().setBaseNode(0);
assertNextEdge(outIter, 0, 1, 0);
assertEnd(outIter);
RoutingCHEdgeIterator inIter = queryCHGraph.createInEdgeExplorer().setBaseNode(1);
assertNextEdge(inIter, 1, 2, 1);
assertNextEdge(inIter, 1, 0, 0);
assertEnd(inIter);
inIter = queryCHGraph.createInEdgeExplorer().setBaseNode(2);
assertNextEdge(inIter, 2, 1, 1);
assertEnd(inIter);
}
use of com.graphhopper.routing.querygraph.QueryGraph in project graphhopper by graphhopper.
the class QueryRoutingCHGraphTest method withVirtualEdgesAndShortcuts.
@Test
public void withVirtualEdgesAndShortcuts() {
// /---\
// 0-x-1-2
// 3
na.setNode(0, 50.00, 10.00);
na.setNode(1, 50.00, 10.10);
na.setNode(2, 50.00, 10.20);
EdgeIteratorState edge = addEdge(graph, 0, 1);
addEdge(graph, 1, 2);
graph.freeze();
assertEquals(2, graph.getEdges());
CHConfig chConfig = CHConfig.edgeBased("x", weighting);
CHStorage chStore = graph.createCHStorage(chConfig);
RoutingCHGraph routingCHGraph = graph.createCHGraph(chStore, chConfig);
CHStorageBuilder chBuilder = new CHStorageBuilder(chStore);
chBuilder.setIdentityLevels();
chBuilder.addShortcutEdgeBased(0, 2, PrepareEncoder.getScFwdDir(), 20, 0, 1, 0, 1);
Snap snap = new Snap(50.00, 10.05);
snap.setClosestEdge(edge);
snap.setWayIndex(0);
snap.setSnappedPosition(Snap.Position.EDGE);
snap.calcSnappedPoint(DistancePlaneProjection.DIST_PLANE);
QueryGraph queryGraph = QueryGraph.create(graph, Collections.singletonList(snap));
QueryRoutingCHGraph queryCHGraph = new QueryRoutingCHGraph(routingCHGraph, queryGraph);
assertEquals(4, queryCHGraph.getNodes());
assertEquals(3 + 4, queryCHGraph.getEdges());
assertNodesConnected(queryCHGraph, 0, 3, true);
assertNodesConnected(queryCHGraph, 3, 1, true);
assertNodesConnected(queryCHGraph, 1, 2, true);
// node 0 is not visible from node 0 via shortcut 0-2
// assertNodesConnected(queryCHGraph, 0, 2, false);
// at real nodes
RoutingCHEdgeIterator outIter = queryCHGraph.createOutEdgeExplorer().setBaseNode(0);
// note that orig edge of virtual edges corresponds to the id of the virtual edge on the base graph
assertNextEdge(outIter, 0, 3, 2);
assertNextShortcut(outIter, 0, 2, 0, 1);
assertEnd(outIter);
RoutingCHEdgeIterator inIter = queryCHGraph.createInEdgeExplorer().setBaseNode(2);
assertNextEdge(inIter, 2, 1, 1);
assertEnd(inIter);
// at virtual nodes
outIter = queryCHGraph.createOutEdgeExplorer().setBaseNode(3);
assertNextEdge(outIter, 3, 0, 2);
assertNextEdge(outIter, 3, 1, 3);
assertEnd(outIter);
inIter = queryCHGraph.createInEdgeExplorer().setBaseNode(3);
assertNextEdge(inIter, 3, 0, 2);
assertNextEdge(inIter, 3, 1, 3);
assertEnd(inIter);
}
use of com.graphhopper.routing.querygraph.QueryGraph in project graphhopper by graphhopper.
the class QueryRoutingCHGraphTest method getWeighting.
@Test
public void getWeighting() {
graph.freeze();
QueryGraph queryGraph = QueryGraph.create(graph, Collections.<Snap>emptyList());
CHConfig chConfig = CHConfig.edgeBased("x", weighting);
CHStorage chStore = graph.createCHStorage(chConfig);
RoutingCHGraph routingCHGraph = graph.createCHGraph(chStore, chConfig);
QueryRoutingCHGraph queryCHGraph = new QueryRoutingCHGraph(routingCHGraph, queryGraph);
// maybe query CH graph should return query graph weighting instead?
assertSame(weighting, queryCHGraph.getWeighting());
}
use of com.graphhopper.routing.querygraph.QueryGraph in project graphhopper by graphhopper.
the class QueryRoutingCHGraphTest method withShortcuts.
@Test
public void withShortcuts() {
// 0-1-2
// \-/
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(10));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(10));
graph.freeze();
assertEquals(2, graph.getEdges());
CHConfig chConfig = CHConfig.edgeBased("x", weighting);
CHStorage chStore = graph.createCHStorage(chConfig);
RoutingCHGraph routingCHGraph = graph.createCHGraph(chStore, chConfig);
CHStorageBuilder chBuilder = new CHStorageBuilder(chStore);
chBuilder.setIdentityLevels();
chBuilder.addShortcutEdgeBased(0, 2, PrepareEncoder.getScFwdDir(), 20, 0, 1, 0, 1);
QueryGraph queryGraph = QueryGraph.create(graph, Collections.emptyList());
QueryRoutingCHGraph queryCHGraph = new QueryRoutingCHGraph(routingCHGraph, queryGraph);
assertEquals(3, queryCHGraph.getNodes());
assertEquals(3, queryCHGraph.getEdges());
assertNodesConnected(queryCHGraph, 0, 1, true);
assertNodesConnected(queryCHGraph, 1, 2, true);
// the shortcut 0-2 is not visible from node 2
// assertNodesConnected(queryCHGraph, 0, 2, false);
RoutingCHEdgeIterator outIter = queryCHGraph.createOutEdgeExplorer().setBaseNode(0);
assertNextShortcut(outIter, 0, 2, 0, 1);
assertNextEdge(outIter, 0, 1, 0);
assertEnd(outIter);
RoutingCHEdgeIterator inIter = queryCHGraph.createInEdgeExplorer().setBaseNode(2);
assertNextEdge(inIter, 2, 1, 1);
assertEnd(inIter);
}
use of com.graphhopper.routing.querygraph.QueryGraph in project graphhopper by graphhopper.
the class QueryRoutingCHGraphTest method getWeight_withAccess.
@Test
public void getWeight_withAccess() {
na.setNode(0, 50.00, 10.00);
na.setNode(1, 50.00, 10.10);
double dist = DistancePlaneProjection.DIST_PLANE.calcDist(na.getLat(0), na.getLon(0), na.getLat(1), na.getLon(1));
EdgeIteratorState edge = graph.edge(0, 1).setDistance(dist);
// we set the access flags, but do use direction dependent speeds to make sure we are testing whether or not the
// access flags are respected and the weight calculation does not simply rely on the speed, see this forum issue
// https://discuss.graphhopper.com/t/speed-and-access-when-setbothdirections-true-false/5695
edge.set(encoder.getAccessEnc(), true, false);
edge.set(encoder.getAverageSpeedEnc(), 60, 60);
graph.freeze();
CHConfig chConfig = CHConfig.edgeBased("x", weighting);
CHStorage chStore = graph.createCHStorage(chConfig);
RoutingCHGraph routingCHGraph = graph.createCHGraph(chStore, chConfig);
// without query graph
// 0->1
RoutingCHEdgeIterator iter = routingCHGraph.createOutEdgeExplorer().setBaseNode(0);
assertNextEdge(iter, 0, 1, 0);
assertEquals(428.8483, iter.getWeight(false), 1.e-4);
assertEquals(Double.POSITIVE_INFINITY, iter.getWeight(true));
assertEnd(iter);
iter = routingCHGraph.createInEdgeExplorer().setBaseNode(1);
assertNextEdge(iter, 1, 0, 0);
assertEquals(Double.POSITIVE_INFINITY, iter.getWeight(false));
assertEquals(428.8483, iter.getWeight(true), 1.e-4);
assertEnd(iter);
// single edges
assertEquals(428.8483, routingCHGraph.getEdgeIteratorState(0, 1).getWeight(false), 1.e-4);
assertEquals(Double.POSITIVE_INFINITY, routingCHGraph.getEdgeIteratorState(0, 1).getWeight(true));
assertEquals(Double.POSITIVE_INFINITY, routingCHGraph.getEdgeIteratorState(0, 0).getWeight(false));
assertEquals(428.8483, routingCHGraph.getEdgeIteratorState(0, 0).getWeight(true), 1.e-4);
// with query graph
// 0-x->1
// 2
Snap snap = new Snap(50.00, 10.05);
snap.setClosestEdge(edge);
snap.setWayIndex(0);
snap.setSnappedPosition(Snap.Position.EDGE);
snap.calcSnappedPoint(DistancePlaneProjection.DIST_PLANE);
QueryGraph queryGraph = QueryGraph.create(graph, Collections.singletonList(snap));
QueryRoutingCHGraph queryCHGraph = new QueryRoutingCHGraph(routingCHGraph, queryGraph);
iter = queryCHGraph.createOutEdgeExplorer().setBaseNode(0);
assertNextEdge(iter, 0, 2, 1);
assertEquals(214.4241, iter.getWeight(false), 1.e-4);
assertEquals(Double.POSITIVE_INFINITY, iter.getWeight(true));
assertEnd(iter);
iter = queryCHGraph.createInEdgeExplorer().setBaseNode(1);
assertNextEdge(iter, 1, 2, 2);
assertEquals(Double.POSITIVE_INFINITY, iter.getWeight(false));
assertEquals(214.4241, iter.getWeight(true), 1.e-4);
assertEnd(iter);
// at virtual node
iter = queryCHGraph.createInEdgeExplorer().setBaseNode(2);
assertNextEdge(iter, 2, 0, 1);
assertEquals(Double.POSITIVE_INFINITY, iter.getWeight(false));
assertEquals(214.4241, iter.getWeight(true), 1.e-4);
assertNextEdge(iter, 2, 1, 2);
assertEquals(214.4241, iter.getWeight(false), 1.e-4);
assertEquals(Double.POSITIVE_INFINITY, iter.getWeight(true));
assertEnd(iter);
// single edges
assertEquals(214.4241, queryCHGraph.getEdgeIteratorState(1, 2).getWeight(false), 1.e-4);
assertEquals(Double.POSITIVE_INFINITY, queryCHGraph.getEdgeIteratorState(1, 2).getWeight(true));
assertEquals(Double.POSITIVE_INFINITY, queryCHGraph.getEdgeIteratorState(1, 0).getWeight(false));
assertEquals(214.4241, queryCHGraph.getEdgeIteratorState(1, 0).getWeight(true), 1.e-4);
}
Aggregations