This is a Jupyter Notebook accompanying a Lightning talk presented during JuliaCon2021

Simulating a public transportation system with OpenStreetMapX.jl

Przemysław Szufel

Co-authors: Nykyta Polituchyi, Kinga Siuta, Paweł Prałat

The research is financed by a NSERC, Canada, Alliance COVID-19" grant titled: "COVID-19: Agent-based framework for modelling pandemics in urban environment" and is done at Ryerson University, Canada with cooperation from Security Compass.

Any transportation network can be represented as a complex directed graph where vertices are spread an Euclidean space. The library provides a bridging functionality between real world spatial data available in the OpenStreetMap project and LightGraphs.jl and makes it possible to run real-life-sized experiment on transportation networks along with various visualizations.

This notebook can be downloaded in Jupyter ipynb format here (right-click to download). The source code uses a central_torontoF.osm file which you can also download here.

Firstly, let us start by installing the required Julia and Python packages. (If the packages are required uncomment the code below)

Now we are ready to load all required packages

We start by loading the file. Note that we trim the map file to have a fully connected road network.

The file was downloaded from the OpenStreetMap project web page. The steps included: (1) Select some area on map; (2) Click the "Export" button at the top of the page; (3) Click "Manually select a different area" to select the central Toronto area; (4) Press the "Export" button on the left (note that sometimes the Export link does not work - in this case click one of the Overpass API link below the Export button).

The central element of the MapData object is a LightGraphs' representation of the road network

The LightGraph graph is represented by nodes, each node id can be directly mapped to OpenStreetMap.

Furhther, those nodes can be presented as geographic coordinates

Now we will plot the TTC line

Let now us try to built a simple simulation model for agents travelling in the city.

We start by a data structure defining location of an agent traversing the graph:

We move to a definition of an Agent

Once the agent is defined let us define the enviroment where they can move around.

Now we define the plotting function:

Now we need to define how the agents move around

This steps the agents as long as at least Wagon no 1 has moved

Let us step the simulation few times and see how the agents move around the city

Now we run the simulation in a larger scale

Once you have run you will have a local anim_ttc.gif file - double click this cell to update the link that points to it Animation