Search in sources :

Example 11 with RoutingAlgorithm

use of com.graphhopper.routing.RoutingAlgorithm 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)

Example 12 with RoutingAlgorithm

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

the class CHTurnCostTest method findPathUsingCH.

private Path findPathUsingCH(int from, int to, int[] contractionOrder) {
    prepareCH(contractionOrder);
    RoutingAlgorithm chAlgo = createAlgo();
    return chAlgo.calcPath(from, to);
}
Also used : RoutingAlgorithm(com.graphhopper.routing.RoutingAlgorithm)

Example 13 with RoutingAlgorithm

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

the class CHTurnCostTest method compareCHQueryWithDijkstra.

private void compareCHQueryWithDijkstra(int from, int to) {
    Path dijkstraPath = findPathUsingDijkstra(from, to);
    RoutingAlgorithm chAlgo = createAlgo();
    Path chPath = chAlgo.calcPath(from, to);
    boolean algosDisagree = Math.abs(dijkstraPath.getWeight() - chPath.getWeight()) > 1.e-2;
    if (checkStrict) {
        algosDisagree = algosDisagree || Math.abs(dijkstraPath.getDistance() - chPath.getDistance()) > 1.e-2 || Math.abs(dijkstraPath.getTime() - chPath.getTime()) > 1;
    }
    if (algosDisagree) {
        System.out.println("Graph that produced error:");
        GHUtility.printGraphForUnitTest(graph, encoder);
        fail("Dijkstra and CH did not find equal shortest paths for route from " + from + " to " + to + "\n" + " dijkstra: weight: " + dijkstraPath.getWeight() + ", distance: " + dijkstraPath.getDistance() + ", time: " + dijkstraPath.getTime() + ", nodes: " + dijkstraPath.calcNodes() + "\n" + "       ch: weight: " + chPath.getWeight() + ", distance: " + chPath.getDistance() + ", time: " + chPath.getTime() + ", nodes: " + chPath.calcNodes());
    }
}
Also used : Path(com.graphhopper.routing.Path) RoutingAlgorithm(com.graphhopper.routing.RoutingAlgorithm)

Example 14 with RoutingAlgorithm

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

the class PrepareContractionHierarchiesTest method checkPath.

private void checkPath(GraphHopperStorage g, CHConfig c, int expShortcuts, double expDistance, IntIndexedContainer expNodes, int[] nodeOrdering) {
    PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, c);
    useNodeOrdering(prepare, nodeOrdering);
    PrepareContractionHierarchies.Result result = prepare.doWork();
    assertEquals(expShortcuts, result.getShortcuts(), c.toString());
    RoutingCHGraph lg = g.createCHGraph(result.getCHStorage(), result.getCHConfig());
    RoutingAlgorithm algo = new CHRoutingAlgorithmFactory(lg).createAlgo(new PMap());
    Path path = algo.calcPath(3, 12);
    assertEquals(expDistance, path.getDistance(), 1e-5, path.toString());
    assertEquals(expNodes, path.calcNodes(), path.toString());
}
Also used : RoutingAlgorithm(com.graphhopper.routing.RoutingAlgorithm) Path(com.graphhopper.routing.Path)

Aggregations

RoutingAlgorithm (com.graphhopper.routing.RoutingAlgorithm)14 Path (com.graphhopper.routing.Path)12 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)6 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)6 Snap (com.graphhopper.storage.index.Snap)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ValueSource (org.junit.jupiter.params.provider.ValueSource)6 Test (org.junit.jupiter.api.Test)5 QueryRoutingCHGraph (com.graphhopper.routing.querygraph.QueryRoutingCHGraph)3 Dijkstra (com.graphhopper.routing.Dijkstra)2 BooleanEncodedValue (com.graphhopper.routing.ev.BooleanEncodedValue)2 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)2 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 Random (java.util.Random)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 AStar (com.graphhopper.routing.AStar)1 AlgorithmOptions (com.graphhopper.routing.AlgorithmOptions)1 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)1