Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove CH from GraphHopperStorage, allow delta import of CHs #2481

Merged
merged 3 commits into from
Dec 8, 2021

Conversation

easbar
Copy link
Member

@easbar easbar commented Dec 4, 2021

Fixes #2388 and #2453.

Our current API to create CH graphs is this:

// encoding manager
FlagEncoder encoder = new CarFlagEncoder();
EncodingManager encodingManager = EncodingManager.create(encoder);
// before we even create the base graph we have to setup the CH graphs and corresponding Weightings
Weighting fastestWeighting = new FastestWeighting(encoder);
CHConfig chConfig = CHConfig.nodeBased("car", weighting);
GraphHopperStorage ghStorage = new GraphBuilder(encodingManager).addCHConfig(chConfig).create();
// run CH preparation
PrepareContractionHierarchies pch = PrepareContractionHierarchies.fromGraphHopperStorage(ghStorage, chConfig);
pch.doWork();
// get the resulting (now no longer empty) CH graph from GHStorage
RoutingCHGraph chGraph = ghStorage.getRoutingCHGraph("car");

with the present PR this becomes:

// encoding manager
FlagEncoder encoder = new CarFlagEncoder();
EncodingManager encodingManager = EncodingManager.create(encoder);
// create the base graph (not related to CH at all)
GraphHopperStorage ghStorage = new GraphBuilder(encodingManager).create();
ghStorage.freeze(); // once all edges were added to the base graph it is finished and we freeze it
// now we can add CHs on top of our base graph 
Weighting fastestWeighting = new FastestWeighting(encoder);
CHConfig chConfig = CHConfig.nodeBased("car", weighting);
PrepareContractionHierarchies pch = PrepareContractionHierarchies.fromGraphHopperStorage(ghStorage, chConfig);
PrepareContractionHierarchies.Result result = pch.doWork();
// ... the result of the preparation is the CHStorage, i.e. basically the CH levels and created shortcuts 
CHStorage chStorage = result.getCHStorage();
// we can obtain a CH graph from this:
RoutingCHGraph chGraph = ghStorage.createCHGraph(chStorage, chConfig);

// instead of using `PrepareContractionHierarchies` to build a CH we can also obtain a `CHStorage` using:
ghStorage.createCHStorage(chConfig);

I think this is a big improvement, because we no longer need to setup CHs even before the base graph was built. With this PR and some recent commits it was easy to implement CH delta imports (#2453). The base graph is also no longer coupled to CH.

I'm still not entirely happy with this API, because we still need to call ghStorage.createCHStorage/Graph to create the CH structures. This is because CHStorage depends on the number of nodes of the frozen base graph and RoutingCHGraph needs a reference to the BaseGraph, which is private and only visible for GraphHopperStorage. Long-term I actually think we should remove GraphHopperStorage entirely and make BaseGraph public instead, but I'd like to do this in another PR.

Comment on lines +1130 to +1131
chGraphs.values().forEach(RoutingCHGraph::close);
landmarks.values().forEach(LandmarkStorage::close);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far we only called ghStorage.close() here which 'closed' the base graph and the CH graphs, but not LM! Now we explicitly close CH and LM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove everything related to CH from GraphHopperStorage
1 participant