Education

Using GraphHopper within Simulations

The simulation software AnyLogic uses GraphHopper to calculate and visualize shortest paths on real-world transport networks during a single simulation run. I have used this feature in multiple research projects (e.g. on disaster relief and sudden rail closures) to combine vehicle routing and simulation approaches in real-world settings. If you are starting to work with GraphHopper in AnyLogic, implementation guidelines to provide more flexibility and to improve run times are presented in this post.

Generate an offline network from OpenStreetMap

If a GIS Map shape is inserted in the simulation, agents and entities use real-world transport networks to move between locations. In the standard setting, routes are requested from an OSM server assuming car movements. While it is a good feature to test your simulation, it has two major disadvantages: (i) a working internet connection during your entire simulation experiment is required; and (ii) run times are substantially increased.

To enable a faster offline version of the routing procedure, data can be loaded from a pbf-file. To generate a routing graph, simply click on the ‘Specify routing graph’ button. Data can be downloaded from various sources; I mostly use GeoFabrik. Depending on the size of the network, a high amount of memory is required during the generation of the routing graph. For more details, refer to the corresponding AnyLogic-Help article.
AnyLogicRouting

Filter and reduce your network

In case you are running into memory issues or you need more flexibility concerning your routing graph (e.g., in my work on freight rail transport, ‘passenger only’ lines had to be removed from the network), it is recommended to filter and reduce your network file before generating the routing graph. This can further help to improve run times. Details on how to filter OSM-data files can be found here.

Custom routing graph

More flexibility concerning the implementation of your routing graph than what is offered by the GISMap shape in AnyLogic is often required. Examples are closing or penalizing certain arcs in the network or to animate the movement of your agents based on speed limits. To enables such details, you can simply create custom Java Classes for your routing graph and code all your requirements. For implementation details, refer to the GraphHopper library. This is of further importance to handle various exceptions and errors such as if no route between two locations can be found or invalid coordinates are given.

RoutingClasses

To visualize agent movements and routes, the GIS Map shape can still be used by generating a GISRoute based on the results of your custom routing graph.

Multimodality

With your custom routing graphs, you can further facilitate a range of additional features offered by GraphHopper. Consequently, you can implement different modes of transport (e.g., bike, rail, car) or restrict access for certain agents to particular parts of the network (e.g., due to driving bans in urban city centres for heavy vehicles).

References:
– OpenStreetMap: https://www.openstreetmap.org/
– GraphHopper – The GraphHopper Directions API Route Planning For Your Application: https://www.graphhopper.com/
– GeoFabrik – OpenStreetMap Data Extracts: http://download.geofabrik.de/
– AnyLogic – Multimethod Simulation Software: http://www.anylogic.com/

Image: BOKU

0 comments on “Using GraphHopper within Simulations

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.