Search in sources :

Example 1 with HeadingResolver

use of com.graphhopper.routing.HeadingResolver in project graphhopper by graphhopper.

the class QueryGraphTest method testEnforceHeading.

@Test
public void testEnforceHeading() {
    // setup graph
    // ____
    // |    |
    // x    |
    // |    |
    // 0    1
    NodeAccess na = g.getNodeAccess();
    na.setNode(0, 0, 0);
    na.setNode(1, 0, 2);
    GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(10)).setWayGeometry(Helper.createPointList(2, 0, 2, 2));
    EdgeIteratorState edge = GHUtility.getEdge(g, 0, 1);
    // snap on first vertical part of way (upward, base is in south)
    Snap snap = fakeEdgeSnap(edge, 1.5, 0, 0);
    QueryGraph queryGraph = lookup(snap);
    // enforce going out north
    HeadingResolver headingResolver = new HeadingResolver(queryGraph);
    IntArrayList unfavoredEdges = headingResolver.getEdgesWithDifferentHeading(snap.getClosestNode(), 0);
    queryGraph.unfavorVirtualEdges(unfavoredEdges);
    // test penalized south
    boolean expect = true;
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(1, 2)));
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(1, 0)));
    queryGraph.clearUnfavoredStatus();
    // test cleared edges south
    expect = false;
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(1, 2)));
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(1, 0)));
    // enforce going south (same as coming in from north)
    unfavoredEdges = headingResolver.getEdgesWithDifferentHeading(snap.getClosestNode(), 180);
    queryGraph.unfavorVirtualEdges(unfavoredEdges);
    // test penalized north
    expect = true;
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(2, 1)));
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(2, 2)));
    // snap on second vertical part of way (downward, base is in north)
    // ____
    // |    |
    // |    x
    // |    |
    // 0    1
    snap = fakeEdgeSnap(edge, 1.5, 2, 2);
    queryGraph = lookup(Arrays.asList(snap));
    // enforce north
    unfavoredEdges = headingResolver.getEdgesWithDifferentHeading(snap.getClosestNode(), 180);
    queryGraph.unfavorVirtualEdges(unfavoredEdges);
    // test penalized south
    expect = true;
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(2, 1)));
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(2, 2)));
    queryGraph.clearUnfavoredStatus();
    // enforce south
    unfavoredEdges = headingResolver.getEdgesWithDifferentHeading(snap.getClosestNode(), 0);
    queryGraph.unfavorVirtualEdges(unfavoredEdges);
    // test penalized north
    expect = true;
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(1, 0)));
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(1, 2)));
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) Snap(com.graphhopper.storage.index.Snap) HeadingResolver(com.graphhopper.routing.HeadingResolver) Test(org.junit.jupiter.api.Test)

Aggregations

IntArrayList (com.carrotsearch.hppc.IntArrayList)1 HeadingResolver (com.graphhopper.routing.HeadingResolver)1 Snap (com.graphhopper.storage.index.Snap)1 Test (org.junit.jupiter.api.Test)1