Estimated RAM needed to instantiate two GraphHoppers simultaneously

Hi,

I have created an extended GraphHopper that integrates my own speed data to better the predictions of travel time. It is very accurate but quite slow when making predictions for travels with a distance greater than 100 Km. On the other hand, a GraphHopper with contraction hierarchy is incredibly fast and precise enough for long trips. Thus, my idea was to handle two different graphs (one with CH and other with my own speed data) and choose which one to use depending on the distance between the origin and the destination.

However, I have an “out of memory” error when I try to instantiate the two graphs. I am running my code in a 8 GB RAM computer. Anyone has an idea of how much RAM would I need to handle the two graphs simultaneously ?

Thanks,
José

GraphHopper is able to hold a base graph and the shortcuts that are necessary for CH at the same time, there is no need to create to graphs as this would duplicate a few structures. Memory usage is highly dependent on the used area and how many vehicles you have or need and of course how your speed customization looks so this is hard to guess.

Hi,

Thanks for your answer.
I basically store hourly speed values for each edge in a cache, and then I update the edge values of the graph depending on the required hour and the validity of the available data.
So, it is possible to enable and disable the CH contraction on the runtime and still be able to modify the edge speed values of the graph when the CH is disabled ?

In general: not yet as the normal edge weights are used from CH too. But you could implemented the custom edge speed values externally (like you said) and then it should work. How does your cache look like? If it is a HashMap then you should switch to an array or a DataAccess to make it more memory efficient.

My cache is a HashMap of type <int, double[]>, where the key correspond to the hour (from 0 to 23) and the value is an array containing the speed values to use for each edge. I use the edge id as the index for the array.

I have created an HourlyWeighting extending the AbstractAdjustedWeighting and implementing the calcWeight method. The HourlyWeighting takes, among others, an existing Weighting as an attribute (let’s call it superweighting). In my case, I pass to the HourlyWeighting a FastestWeighting as superweighting. In the implemented method calcWeight of the class HourlyWeighting I query the cache and I update (or not) the speed flag of the current edge. Then, I finally return the superweithning calcWeight so it calculates the fastest way with the updated values.

public double calcWeight(EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId) { updateSpeed(edgeState); return superWeighting.calcWeight(edgeState, reverse, prevOrNextEdgeId); }

So I guess this wouldn’t work if I enbable the CH contraction. That’s why I wanted to instantiate two different graphs.

This will be huge. You can use an array where you use edgeIds as array indices and safe lots of memory.

So I guess this wouldn’t work if I enbable the CH contraction. That’s why I wanted to instantiate two different graphs.

You can workaround the limitation but out of the box this is indeed not possible. See the new issue: Allow decoupling of normal graph weights when using CH · Issue #1067 · graphhopper/graphhopper · GitHub

Actually, I use Infinispan to manage the cache, and I can set a number of keys to keep in memory. Thus, I only keep one key-value pair in memory, corresponding to the demanded departure hour.

Thanks for the help and for the issue creation.