I've been testing graphhopper on Android for some weeks on different devices. Today I got an OutOfMemory error during GraphHopper load(...) function executing. This happens on Xiaomi Mi4 phone. Graph is exported for car, bike and foot with fastest and shortest weightings. All graph files are over 1,17GB.
I tried this: To save memory, I removed all files specific to other vehicles than car: nodes_ch_fastest_bike, shortcuts_fastest_bike, shortcuts_fastest_foot etc.
and modified 2 lines in properties file:
I removed flag encoders other than car:
graph.flag_encoders=car|speed_factor=5.0|speed_bits=5|turn_costs=false|version=1
and removed weightings other than car
graph.ch.weightings=[fastest|car, shortest|car]
Now it loaded properly :-)
The question is, can I safely modify properties file this way (maybe deleting files was unnecessary?) to load only vehicle data selected by user (if user changes vehicle during app runtime, graph is closed then properties file is modified to set proper encoders and weightings and graph is loaded again).
I 've noticed, that remaining files except names, that is: nodes, edges, geometry, location_index prepared for graph supporting all vehicles (car, bike, foot) vary in size comparing to graph files prepared only for car. I suppose it's related to encoding. Although it seems to work properly, I don't know the exact graph structure and I would like to avoid any inconsistency.
Thanks
UPDATE: I tested it and this workaround works for car, but fails sometimes when calculating route for bike and car vehicles (both shortest and fastest weighting). The exception:
java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:309) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) at java.util.concurrent.FutureTask.setException(FutureTask.java:223) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.IllegalStateException: Calculating time should not require to read speed from edge in wrong direction. Reverse:true, fwd:false, bwd:false at com.graphhopper.routing.Path.calcMillis(Path.java:253) at com.graphhopper.routing.ch.Path4CH.expandEdge(Path4CH.java:56) at com.graphhopper.routing.ch.Path4CH.expandEdge(Path4CH.java:96) at com.graphhopper.routing.ch.Path4CH.expandEdge(Path4CH.java:96) at com.graphhopper.routing.ch.Path4CH.expandEdge(Path4CH.java:103) at com.graphhopper.routing.ch.Path4CH.expandEdge(Path4CH.java:96) at com.graphhopper.routing.ch.Path4CH.expandEdge(Path4CH.java:96) at com.graphhopper.routing.ch.Path4CH.expandEdge(Path4CH.java:96) at com.graphhopper.routing.ch.Path4CH.expandEdge(Path4CH.java:103) at com.graphhopper.routing.ch.Path4CH.processEdge(Path4CH.java:46) at com.graphhopper.routing.PathBidirRef.extract(PathBidirRef.java:92) at com.graphhopper.routing.DijkstraBidirectionRef.extractPath(DijkstraBidirectionRef.java:130) at com.graphhopper.routing.AbstractBidirAlgo.calcPath(AbstractBidirAlgo.java:64) at com.graphhopper.routing.AbstractRoutingAlgorithm.calcPaths(AbstractRoutingAlgorithm.java:120) at com.graphhopper.routing.template.ViaRoutingTemplate.calcPaths(ViaRoutingTemplate.java:110) at com.graphhopper.GraphHopper.calcPaths(GraphHopper.java:1098) at com.graphhopper.GraphHopper.route(GraphHopper.java:1003)