rafapereirabr / otp-travel-time-matrix

Tutorial with reproducible example to estimate a travel time matrix using OpenTripPlanner and Python
52 stars 24 forks source link

Tutorial with reproducible example to estimate a travel time matrix using OpenTripPlanner and Python

This repository aims to provide a reproducible example of how to build an Origin-Destination travel time matrix using OpenTripPlanner (OTP) and Python. The Python scripts presented here can still be improved and it would be great to have your contributions, specially if you have ideas on how to improve the speed/efficiency of the code, or include a progress bar etc !

Input

Output


This repository should help you build a travel time matrix in 4 simple steps

Step 1: Install Jython 2.7 in your computer

Here you find the executable jar for installing Jython

Step 2: Download files to your folder

Most of the files you need are in this repository already. The other files you can download from here:

Step 3: Build Graph.obj

Open your Command Prompt and run this line to set the directory where you've saved the files

cd C:\Users\rafa\Desktop\otp-travel-time-matrix

Now run this line to build the Graph.obj. Once OTP has built the Graph.obj, move it to the subdirectory portland.

java –Xmx10G -jar otp-1.3.0-shaded.jar --cache C:\Users\rafa\Desktop\otp-travel-time-matrix --basePath C:\Users\rafa\Desktop\otp-travel-time-matrix --build C:\Users\rafa\Desktop\otp-travel-time-matrix

Step 4: Run the Python script

Three options here:

4.1 A simple script like python_script.py will return a travel time matrix for one single deaprture time (e.g. at 10:00:00 on 15-November-2015)

c:\jython2.7.0\bin\jython.exe -J-XX:-UseGCOverheadLimit -J-Xmx10G -Dpython.path=otp-1.3.0-shaded.jar python_script.py

4.2 The second option is to use a script like python_script_loopHM.py, which will create a different travel time matrix departing every ten minutes, say between 10am and 6pm, and save each matix in a separete .csv file

c:\jython2.7.0\bin\jython.exe -J-XX:-UseGCOverheadLimit -J-Xmx10G -Dpython.path=otp-1.3.0-shaded.jar python_script_loopHM.py

4.3 The third option uses the python script named python_script_loopHM_parallel.py, and it allows one to estimate various travel time matrices for different departure times (similarly to the second option) but using parallel computing. This makes things much faster because each computer processor will compute the travel-time matrix of a different departure time in parallel.

c:\jython2.7.0\bin\jython.exe -J-XX:-UseGCOverheadLimit -J-Xmx10G -Dpython.path=otp-1.3.0-shaded.jar python_script_loopHM_parallel.py

This code is inspired by @laurentg's code but it tries to achieve a different output, providing a travel time matrix. @laurentg has also made important contributions to this repository, to which I am grateful. The two python scripts that use multiple threads to run in parallel were developed in collaboration with Nate Wessel and Jader Martins. Nate and Jader did most of the heavy lifting, really.

More information about how to automate OTP here.

Citation

If you have used this script in your work and you would like to cite it, you can use the following reference: DOI

Pereira, R. H. M.; Grégoire, L.; Wessel, N.; Martins, J. (2019). Tutorial with reproducible example to estimate a travel time matrix
using OpenTripPlanner and Python. Retrieved from https://github.com/rafapereirabr/otp-travel-time-matrix. 
doi:10.5281/zenodo.3242134