use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class QueryGraphTest method testunfavorVirtualEdgePair.
@Test
public void testunfavorVirtualEdgePair() {
initHorseshoeGraph(g);
EdgeIteratorState edge = GHUtility.getEdge(g, 0, 1);
// query result on first vertical part of way (upward)
QueryResult qr = fakeEdgeQueryResult(edge, 1.5, 0, 0);
QueryGraph queryGraph = new QueryGraph(g);
queryGraph.lookup(Arrays.asList(qr));
// enforce coming in north
queryGraph.unfavorVirtualEdgePair(2, 1);
// test penalized south
VirtualEdgeIteratorState incomingEdge = (VirtualEdgeIteratorState) queryGraph.getEdgeIteratorState(1, 2);
VirtualEdgeIteratorState incomingEdgeReverse = (VirtualEdgeIteratorState) queryGraph.getEdgeIteratorState(1, incomingEdge.getBaseNode());
// expect incoming and reverse incoming edge to be avoided
boolean expect = true;
assertEquals(expect, incomingEdge.getBool(EdgeIteratorState.K_UNFAVORED_EDGE, !expect));
assertEquals(expect, incomingEdgeReverse.getBool(EdgeIteratorState.K_UNFAVORED_EDGE, !expect));
assertEquals(new LinkedHashSet<>(Arrays.asList(incomingEdge, incomingEdgeReverse)), queryGraph.getUnfavoredVirtualEdges());
queryGraph.clearUnfavoredStatus();
// expect incoming and reverse incoming edge not to be avoided
expect = false;
assertEquals(expect, incomingEdge.getBool(EdgeIteratorState.K_UNFAVORED_EDGE, !expect));
assertEquals(expect, incomingEdgeReverse.getBool(EdgeIteratorState.K_UNFAVORED_EDGE, !expect));
assertEquals(new LinkedHashSet<>(), queryGraph.getUnfavoredVirtualEdges());
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class QueryGraphTest method fakeEdgeQueryResult.
private QueryResult fakeEdgeQueryResult(EdgeIteratorState edge, double lat, double lon, int wayIndex) {
QueryResult qr = new QueryResult(lat, lon);
qr.setClosestEdge(edge);
qr.setWayIndex(wayIndex);
qr.setSnappedPosition(EDGE);
qr.calcSnappedPoint(new DistanceCalc2D());
return qr;
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class QueryGraphTest method testEnforceHeading.
@Test
public void testEnforceHeading() {
initHorseshoeGraph(g);
EdgeIteratorState edge = GHUtility.getEdge(g, 0, 1);
// query result on first vertical part of way (upward)
QueryResult qr = fakeEdgeQueryResult(edge, 1.5, 0, 0);
QueryGraph queryGraph = new QueryGraph(g);
queryGraph.lookup(Arrays.asList(qr));
// enforce going out north
queryGraph.enforceHeading(qr.getClosestNode(), 0., false);
// test penalized south
boolean expect = true;
assertEquals(expect, isAvoidEdge(queryGraph, QueryGraph.VE_BASE_REV, !expect));
assertEquals(expect, isAvoidEdge(queryGraph, QueryGraph.VE_BASE, !expect));
queryGraph.clearUnfavoredStatus();
// test cleared edges south
expect = false;
assertEquals(expect, isAvoidEdge(queryGraph, QueryGraph.VE_BASE_REV, !expect));
assertEquals(expect, isAvoidEdge(queryGraph, QueryGraph.VE_BASE, !expect));
// enforce coming in north
queryGraph.enforceHeading(qr.getClosestNode(), 180., true);
// test penalized south
expect = true;
assertEquals(expect, isAvoidEdge(queryGraph, QueryGraph.VE_BASE_REV, !expect));
assertEquals(expect, isAvoidEdge(queryGraph, QueryGraph.VE_BASE, !expect));
// query result on second vertical part of way (downward)
qr = fakeEdgeQueryResult(edge, 1.5, 2, 2);
queryGraph = new QueryGraph(g);
queryGraph.lookup(Arrays.asList(qr));
// enforce going north
queryGraph.enforceHeading(qr.getClosestNode(), 0., false);
// test penalized south
expect = true;
assertEquals(expect, isAvoidEdge(queryGraph, QueryGraph.VE_ADJ, !expect));
assertEquals(expect, isAvoidEdge(queryGraph, QueryGraph.VE_ADJ_REV, !expect));
queryGraph.clearUnfavoredStatus();
// enforce coming in north
queryGraph.enforceHeading(qr.getClosestNode(), 180., true);
// test penalized south
expect = true;
assertEquals(expect, isAvoidEdge(queryGraph, QueryGraph.VE_ADJ, !expect));
assertEquals(expect, isAvoidEdge(queryGraph, QueryGraph.VE_ADJ_REV, !expect));
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class QueryGraphTest method testUseMeanElevation.
@Test
public void testUseMeanElevation() {
g.close();
g = new GraphHopperStorage(new RAMDirectory(), encodingManager, true, new GraphExtension.NoOpExtension()).create(100);
NodeAccess na = g.getNodeAccess();
na.setNode(0, 0, 0, 0);
na.setNode(1, 0, 0.0001, 20);
EdgeIteratorState edge = g.edge(0, 1);
EdgeIteratorState edgeReverse = edge.detach(true);
DistanceCalc2D distCalc = new DistanceCalc2D();
QueryResult qr = new QueryResult(0, 0.00005);
qr.setClosestEdge(edge);
qr.setWayIndex(0);
qr.setSnappedPosition(EDGE);
qr.calcSnappedPoint(distCalc);
assertEquals(10, qr.getSnappedPoint().getEle(), 1e-1);
qr = new QueryResult(0, 0.00005);
qr.setClosestEdge(edgeReverse);
qr.setWayIndex(0);
qr.setSnappedPosition(EDGE);
qr.calcSnappedPoint(distCalc);
assertEquals(10, qr.getSnappedPoint().getEle(), 1e-1);
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class QueryGraphTest method testAvoidDuplicateVirtualNodesIfIdentical.
@Test
public void testAvoidDuplicateVirtualNodesIfIdentical() {
initGraph(g);
EdgeIteratorState edgeState = GHUtility.getEdge(g, 0, 2);
QueryResult res1 = createLocationResult(0.5, 0, edgeState, 0, EDGE);
QueryResult res2 = createLocationResult(0.5, 0, edgeState, 0, EDGE);
QueryGraph queryGraph = new QueryGraph(g);
queryGraph.lookup(Arrays.asList(res1, res2));
assertEquals(new GHPoint(0.5, 0), res1.getSnappedPoint());
assertEquals(new GHPoint(0.5, 0), res2.getSnappedPoint());
assertEquals(3, res1.getClosestNode());
assertEquals(3, res2.getClosestNode());
// force skip due to **tower** node snapping in phase 2, but no virtual edges should be created for res1
edgeState = GHUtility.getEdge(g, 0, 1);
res1 = createLocationResult(1, 0, edgeState, 0, EDGE);
// now create virtual edges
edgeState = GHUtility.getEdge(g, 0, 2);
res2 = createLocationResult(0.5, 0, edgeState, 0, EDGE);
queryGraph = new QueryGraph(g);
queryGraph.lookup(Arrays.asList(res1, res2));
// make sure only one virtual node was created
assertEquals(queryGraph.getNodes(), g.getNodes() + 1);
EdgeIterator iter = queryGraph.createEdgeExplorer().setBaseNode(0);
assertEquals(GHUtility.asSet(1, 3), GHUtility.getNeighbors(iter));
}
Aggregations