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;
}
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;
}
Aggregations