Search in sources :

Example 6 with QueryResult

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());
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) Test(org.junit.Test)

Example 7 with QueryResult

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;
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult)

Example 8 with QueryResult

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));
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) Test(org.junit.Test)

Example 9 with QueryResult

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);
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) Test(org.junit.Test)

Example 10 with QueryResult

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));
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Aggregations

QueryResult (com.graphhopper.storage.index.QueryResult)39 GHPoint (com.graphhopper.util.shapes.GHPoint)20 Test (org.junit.Test)20 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)4 LocationIndex (com.graphhopper.storage.index.LocationIndex)4 Weighting (com.graphhopper.routing.weighting.Weighting)3 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)3 GHRequest (com.graphhopper.GHRequest)2 GHResponse (com.graphhopper.GHResponse)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)2 GHPoint3D (com.graphhopper.util.shapes.GHPoint3D)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 IntObjectMap (com.carrotsearch.hppc.IntObjectMap)1 Stop (com.conveyal.gtfs.model.Stop)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GraphHopper (com.graphhopper.GraphHopper)1 GHIntObjectHashMap (com.graphhopper.coll.GHIntObjectHashMap)1