Search in sources :

Example 6 with TurnCostExtension

use of com.graphhopper.storage.TurnCostExtension in project graphhopper by graphhopper.

the class EdgeBasedRoutingAlgorithmTest method testTurnCostsBug_991.

@Test
public void testTurnCostsBug_991() {
    final GraphHopperStorage g = createStorage(createEncodingManager(false));
    initGraph(g);
    TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
    long tflags = carEncoder.getTurnFlags(false, 2);
    tcs.addTurnInfo(getEdge(g, 5, 2).getEdge(), 2, getEdge(g, 2, 3).getEdge(), tflags);
    tcs.addTurnInfo(getEdge(g, 2, 0).getEdge(), 0, getEdge(g, 0, 1).getEdge(), tflags);
    tcs.addTurnInfo(getEdge(g, 5, 6).getEdge(), 6, getEdge(g, 6, 3).getEdge(), tflags);
    tflags = carEncoder.getTurnFlags(false, 1);
    tcs.addTurnInfo(getEdge(g, 6, 7).getEdge(), 7, getEdge(g, 7, 4).getEdge(), tflags);
    Path p = createAlgo(g, AlgorithmOptions.start().weighting(new TurnWeighting(new FastestWeighting(carEncoder), tcs) {

        @Override
        public double calcTurnWeight(int edgeFrom, int nodeVia, int edgeTo) {
            if (edgeFrom >= 0)
                assertNotNull("edge " + edgeFrom + " to " + nodeVia + " does not exist", g.getEdgeIteratorState(edgeFrom, nodeVia));
            if (edgeTo >= 0)
                assertNotNull("edge " + edgeTo + " to " + nodeVia + " does not exist", g.getEdgeIteratorState(edgeTo, nodeVia));
            return super.calcTurnWeight(edgeFrom, nodeVia, edgeTo);
        }
    }.setDefaultUTurnCost(40)).traversalMode(TraversalMode.EDGE_BASED_2DIR).build()).calcPath(5, 1);
    assertEquals(Helper.createTList(5, 6, 7, 4, 3, 1), p.calcNodes());
    assertEquals(301, p.getTime(), .1);
}
Also used : TurnWeighting(com.graphhopper.routing.weighting.TurnWeighting) TurnCostExtension(com.graphhopper.storage.TurnCostExtension) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Aggregations

TurnCostExtension (com.graphhopper.storage.TurnCostExtension)6 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)5 Test (org.junit.Test)5 TurnWeighting (com.graphhopper.routing.weighting.TurnWeighting)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)1 PathWrapper (com.graphhopper.PathWrapper)1 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)1 GHPoint (com.graphhopper.util.shapes.GHPoint)1 ArrayList (java.util.ArrayList)1