Search in sources :

Example 16 with QueryRoutingCHGraph

use of com.graphhopper.routing.querygraph.QueryRoutingCHGraph in project graphhopper by graphhopper.

the class CHTurnCostTest method testRouteViaVirtualNode_withAlternative.

@ParameterizedTest
@ValueSource(strings = { DIJKSTRA_BI, ASTAR_BI })
public void testRouteViaVirtualNode_withAlternative(String algo) {
    // 3
    // 0-x-1
    // \  |
    // \-2
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 0).setDistance(1));
    updateDistancesFor(graph, 0, 0.01, 0.00);
    updateDistancesFor(graph, 1, 0.01, 0.02);
    updateDistancesFor(graph, 2, 0.00, 0.02);
    graph.freeze();
    automaticPrepareCH();
    LocationIndexTree index = new LocationIndexTree(graph, new RAMDirectory());
    index.prepareIndex();
    Snap snap = index.findClosest(0.01, 0.01, EdgeFilter.ALL_EDGES);
    QueryGraph queryGraph = QueryGraph.create(graph, snap);
    assertEquals(3, snap.getClosestNode());
    assertEquals(0, snap.getClosestEdge().getEdge());
    QueryRoutingCHGraph routingCHGraph = new QueryRoutingCHGraph(chGraph, queryGraph);
    RoutingAlgorithm chAlgo = new CHRoutingAlgorithmFactory(routingCHGraph).createAlgo(new PMap().putObject(ALGORITHM, algo));
    Path path = chAlgo.calcPath(1, 0);
    assertEquals(IntArrayList.from(1, 3, 0), path.calcNodes());
}
Also used : RoutingAlgorithm(com.graphhopper.routing.RoutingAlgorithm) Path(com.graphhopper.routing.Path) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) Snap(com.graphhopper.storage.index.Snap) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)16 QueryRoutingCHGraph (com.graphhopper.routing.querygraph.QueryRoutingCHGraph)16 Snap (com.graphhopper.storage.index.Snap)12 Test (org.junit.jupiter.api.Test)11 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)7 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)5 Path (com.graphhopper.routing.Path)3 RoutingAlgorithm (com.graphhopper.routing.RoutingAlgorithm)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 PMap (com.graphhopper.util.PMap)2 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)1 GraphHopper (com.graphhopper.GraphHopper)1 GraphHopperConfig (com.graphhopper.GraphHopperConfig)1 GHBitSet (com.graphhopper.coll.GHBitSet)1 GHTBitSet (com.graphhopper.coll.GHTBitSet)1 CHProfile (com.graphhopper.config.CHProfile)1 LMProfile (com.graphhopper.config.LMProfile)1