Search in sources :

Example 1 with DefaultTurnCostProvider

use of com.graphhopper.routing.weighting.DefaultTurnCostProvider in project graphhopper by graphhopper.

the class AlternativeRouteEdgeCHTest method testAssumptions.

@Test
public void testAssumptions() {
    GraphHopperStorage g = createTestGraph(em);
    TurnCostProvider turnCostProvider = new DefaultTurnCostProvider(carFE, g.getTurnCostStorage());
    CHConfig chConfig = CHConfig.edgeBased("profile", new FastestWeighting(carFE, turnCostProvider));
    CHStorage chStorage = g.createCHStorage(chConfig);
    RoutingCHGraph chGraph = g.createCHGraph(chStorage, chConfig);
    DijkstraBidirectionEdgeCHNoSOD router = new DijkstraBidirectionEdgeCHNoSOD(chGraph);
    Path path = router.calcPath(5, 10);
    assertTrue(path.isFound());
    assertEquals(IntArrayList.from(5, 6, 7, 8, 4, 10), path.calcNodes());
    assertEquals(50000.0, path.getDistance(), 0.0);
    // 6 -> 3 -> 4 is forbidden
    g = createTestGraph(em);
    RoutingCHGraph routingCHGraph = prepareCH(g);
    router = new DijkstraBidirectionEdgeCHNoSOD(routingCHGraph);
    path = router.calcPath(5, 3, ANY_EDGE, GHUtility.getEdge(g, 2, 3).getEdge());
    assertEquals(IntArrayList.from(5, 1, 9, 2, 3), path.calcNodes());
    assertEquals(40000.0, path.getDistance(), 0.0);
// We can specifically route to the desired in-edge at node 3
// which does not lie upstream of the turn-restriction.
}
Also used : TurnCostProvider(com.graphhopper.routing.weighting.TurnCostProvider) DefaultTurnCostProvider(com.graphhopper.routing.weighting.DefaultTurnCostProvider) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) DefaultTurnCostProvider(com.graphhopper.routing.weighting.DefaultTurnCostProvider) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultTurnCostProvider

use of com.graphhopper.routing.weighting.DefaultTurnCostProvider in project graphhopper by graphhopper.

the class QueryRoutingCHGraphTest method setup.

@BeforeEach
public void setup() {
    encoder = new CarFlagEncoder(5, 5, 5, true);
    encodingManager = EncodingManager.create(encoder);
    graph = new GraphBuilder(encodingManager).create();
    weighting = new FastestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage()));
    na = graph.getNodeAccess();
}
Also used : FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) DefaultTurnCostProvider(com.graphhopper.routing.weighting.DefaultTurnCostProvider) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with DefaultTurnCostProvider

use of com.graphhopper.routing.weighting.DefaultTurnCostProvider in project graphhopper by graphhopper.

the class EdgeBasedNodeContractorTest method initialize.

private void initialize() {
    encoder = new CarFlagEncoder(5, 5, maxCost);
    EncodingManager encodingManager = EncodingManager.create(encoder);
    graph = new GraphBuilder(encodingManager).create();
    chConfigs = Arrays.asList(CHConfig.edgeBased("p1", new ShortestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage()))), CHConfig.edgeBased("p2", new ShortestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage(), 60))));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) DefaultTurnCostProvider(com.graphhopper.routing.weighting.DefaultTurnCostProvider) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting)

Example 4 with DefaultTurnCostProvider

use of com.graphhopper.routing.weighting.DefaultTurnCostProvider in project graphhopper by graphhopper.

the class AccessFilterTest method testAccept_fwdLoopShortcut_acceptedByInExplorer.

@Test
public void testAccept_fwdLoopShortcut_acceptedByInExplorer() {
    // 0-1
    // \|
    // 2
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 1).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 2).setDistance(2));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 0).setDistance(3));
    graph.freeze();
    // add loop shortcut in 'fwd' direction
    CHConfig chConfig = CHConfig.edgeBased("profile", new ShortestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage())));
    CHStorage chStore = graph.createCHStorage(chConfig);
    CHStorageBuilder chBuilder = new CHStorageBuilder(chStore);
    chBuilder.setIdentityLevels();
    chBuilder.addShortcutEdgeBased(0, 0, PrepareEncoder.getScFwdDir(), 5, 0, 2, 0, 2);
    RoutingCHGraph chGraph = graph.createCHGraph(chStore, chConfig);
    RoutingCHEdgeExplorer outExplorer = chGraph.createOutEdgeExplorer();
    RoutingCHEdgeExplorer inExplorer = chGraph.createInEdgeExplorer();
    IntSet inEdges = new IntHashSet();
    IntSet outEdges = new IntHashSet();
    RoutingCHEdgeIterator outIter = outExplorer.setBaseNode(0);
    while (outIter.next()) {
        outEdges.add(outIter.getEdge());
    }
    RoutingCHEdgeIterator inIter = inExplorer.setBaseNode(0);
    while (inIter.next()) {
        inEdges.add(inIter.getEdge());
    }
    // the loop should be accepted by in- and outExplorers
    assertEquals(IntHashSet.from(0, 3), outEdges, "Wrong outgoing edges");
    assertEquals(IntHashSet.from(2, 3), inEdges, "Wrong incoming edges");
}
Also used : IntSet(com.carrotsearch.hppc.IntSet) IntHashSet(com.carrotsearch.hppc.IntHashSet) DefaultTurnCostProvider(com.graphhopper.routing.weighting.DefaultTurnCostProvider) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultTurnCostProvider

use of com.graphhopper.routing.weighting.DefaultTurnCostProvider in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworksTest method testPrepareSubnetwork_withTurnCosts.

@Test
public void testPrepareSubnetwork_withTurnCosts() {
    EncodingManager em = createEncodingManager("car|turn_costs=true");
    FlagEncoder encoder = em.fetchEdgeEncoders().iterator().next();
    // since the middle edge is blocked the upper component is a subnetwork (regardless of turn costs)
    GraphHopperStorage g = createSubnetworkTestStorage(em);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(createJob(em, encoder, new DefaultTurnCostProvider(encoder, g.getTurnCostStorage(), 0))));
    instance.setMinNetworkSize(4);
    assertEquals(3, instance.doWork());
    assertEquals(IntArrayList.from(7, 8, 9), getSubnetworkEdges(g, encoder));
    // if we open the edge it won't be a subnetwork anymore
    g = createSubnetworkTestStorage(em);
    EdgeIteratorState edge = GHUtility.getEdge(g, 3, 4);
    GHUtility.setSpeed(10, true, true, encoder, edge);
    instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(createJob(em, encoder, new DefaultTurnCostProvider(encoder, g.getTurnCostStorage(), 0))));
    instance.setMinNetworkSize(4);
    assertEquals(0, instance.doWork());
    assertEquals(IntArrayList.from(), getSubnetworkEdges(g, encoder));
    // ... and now for something interesting: if we open the edge *and* apply turn restrictions it will be a
    // subnetwork again
    g = createSubnetworkTestStorage(em);
    edge = GHUtility.getEdge(g, 3, 4);
    GHUtility.setSpeed(10, true, true, encoder, edge);
    DecimalEncodedValue turnCostEnc = em.getDecimalEncodedValue(TurnCost.key(encoder.toString()));
    g.getTurnCostStorage().set(turnCostEnc, 0, 4, 7, 1);
    g.getTurnCostStorage().set(turnCostEnc, 0, 4, 9, 1);
    instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(createJob(em, encoder, new DefaultTurnCostProvider(encoder, g.getTurnCostStorage(), 0))));
    instance.setMinNetworkSize(4);
    assertEquals(3, instance.doWork());
    assertEquals(IntArrayList.from(7, 8, 9), getSubnetworkEdges(g, encoder));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) DefaultTurnCostProvider(com.graphhopper.routing.weighting.DefaultTurnCostProvider) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultTurnCostProvider (com.graphhopper.routing.weighting.DefaultTurnCostProvider)10 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)6 Test (org.junit.jupiter.api.Test)5 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)3 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)3 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)2 EncodingManager (com.graphhopper.routing.util.EncodingManager)2 TurnCostProvider (com.graphhopper.routing.weighting.TurnCostProvider)2 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntSet (com.carrotsearch.hppc.IntSet)1 PrepareContractionHierarchies (com.graphhopper.routing.ch.PrepareContractionHierarchies)1 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)1 Weighting (com.graphhopper.routing.weighting.Weighting)1 Graph (com.graphhopper.storage.Graph)1 TurnCostStorage (com.graphhopper.storage.TurnCostStorage)1 Snap (com.graphhopper.storage.index.Snap)1 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)1