Search in sources :

Example 1 with BidirRoutingAlgorithm

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

the class MapMatching method createRouter.

private BidirRoutingAlgorithm createRouter() {
    BidirRoutingAlgorithm router;
    if (landmarks != null) {
        AStarBidirection algo = new AStarBidirection(queryGraph, weighting, TraversalMode.EDGE_BASED) {

            @Override
            protected void initCollections(int size) {
                super.initCollections(50);
            }
        };
        int activeLM = Math.min(8, landmarks.getLandmarkCount());
        algo.setApproximation(LMApproximator.forLandmarks(queryGraph, landmarks, activeLM));
        algo.setMaxVisitedNodes(maxVisitedNodes);
        router = algo;
    } else {
        router = new DijkstraBidirectionRef(queryGraph, weighting, TraversalMode.EDGE_BASED) {

            @Override
            protected void initCollections(int size) {
                super.initCollections(50);
            }
        };
        router.setMaxVisitedNodes(maxVisitedNodes);
    }
    return router;
}
Also used : AStarBidirection(com.graphhopper.routing.AStarBidirection) DijkstraBidirectionRef(com.graphhopper.routing.DijkstraBidirectionRef) BidirRoutingAlgorithm(com.graphhopper.routing.BidirRoutingAlgorithm)

Example 2 with BidirRoutingAlgorithm

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

the class LowLevelAPIExample method useContractionHierarchiesToMakeQueriesFaster.

public static void useContractionHierarchiesToMakeQueriesFaster() {
    // Creating and saving the graph
    FlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = EncodingManager.create(encoder);
    Weighting weighting = new FastestWeighting(encoder);
    CHConfig chConfig = CHConfig.nodeBased("my_profile", weighting);
    GraphHopperStorage graph = new GraphBuilder(em).setRAM(graphLocation, true).create();
    graph.flush();
    // Set node coordinates and build location index
    NodeAccess na = graph.getNodeAccess();
    graph.edge(0, 1).set(encoder.getAccessEnc(), true).set(encoder.getAverageSpeedEnc(), 10).setDistance(1020);
    na.setNode(0, 15.15, 20.20);
    na.setNode(1, 15.25, 20.21);
    // Prepare the graph for fast querying ...
    graph.freeze();
    PrepareContractionHierarchies pch = PrepareContractionHierarchies.fromGraphHopperStorage(graph, chConfig);
    PrepareContractionHierarchies.Result pchRes = pch.doWork();
    RoutingCHGraph chGraph = graph.createCHGraph(pchRes.getCHStorage(), pchRes.getCHConfig());
    // create location index
    LocationIndexTree index = new LocationIndexTree(graph, graph.getDirectory());
    index.prepareIndex();
    // calculate a path with location index
    Snap fromSnap = index.findClosest(15.15, 20.20, EdgeFilter.ALL_EDGES);
    Snap toSnap = index.findClosest(15.25, 20.21, EdgeFilter.ALL_EDGES);
    QueryGraph queryGraph = QueryGraph.create(graph, fromSnap, toSnap);
    BidirRoutingAlgorithm algo = new CHRoutingAlgorithmFactory(chGraph, queryGraph).createAlgo(new PMap());
    Path path = algo.calcPath(fromSnap.getClosestNode(), toSnap.getClosestNode());
    assert Helper.round(path.getDistance(), -2) == 1000;
}
Also used : Path(com.graphhopper.routing.Path) PrepareContractionHierarchies(com.graphhopper.routing.ch.PrepareContractionHierarchies) PMap(com.graphhopper.util.PMap) Snap(com.graphhopper.storage.index.Snap) BidirRoutingAlgorithm(com.graphhopper.routing.BidirRoutingAlgorithm) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) CHRoutingAlgorithmFactory(com.graphhopper.routing.ch.CHRoutingAlgorithmFactory) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph)

Aggregations

BidirRoutingAlgorithm (com.graphhopper.routing.BidirRoutingAlgorithm)2 AStarBidirection (com.graphhopper.routing.AStarBidirection)1 DijkstraBidirectionRef (com.graphhopper.routing.DijkstraBidirectionRef)1 Path (com.graphhopper.routing.Path)1 CHRoutingAlgorithmFactory (com.graphhopper.routing.ch.CHRoutingAlgorithmFactory)1 PrepareContractionHierarchies (com.graphhopper.routing.ch.PrepareContractionHierarchies)1 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)1 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)1 Weighting (com.graphhopper.routing.weighting.Weighting)1 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)1 Snap (com.graphhopper.storage.index.Snap)1 PMap (com.graphhopper.util.PMap)1