Executive summary: build a robust SBB journey planner for the Zürich area, and make a short video presentation of it - to be done in groups of 4 or 5, before midnight of May 30.
Our project is spread-out around multiple notebooks and helper files. In this section, we will describe the process of simply using the planner, or re-generating the data from scratch.
The video presentation of our project is available here.
To simply use the planner, you'll need the notebook planning.ipynb
. It uses the final processed networkx graph. To obtain that graph, make sure to pull the data available on git lfs using git lfs pull
.
Then, you can launch the voila app by replacing /lab
in the URL by /voila/render/notebooks/planning.ipynb
. Or you can simply run the notebook and use the planner from jupyter lab itself.
If you need run the project from scratch, you'll have the run the following notebooks in the specified order:
- Infrastructure procressing (
infra_processing.ipynb
): this notebook is in charge of parsing the timetable data into a list of edges and vertices that represent the transportation graph in a 15km radius around Zürich HB. It saves the processed data in hdfs under/user/theAggregators/
. - Delay processing (
delay_processing.ipynb
): this notebook computes the average delay for each stop at each hour of the day. For stops with missing data, it computes the delay with respect to the mean delay for that type of transport. It also saves the processed data in/user/theAggregators/
. - Planning procesing (
planning_processing.ipynb
): this notebook builds the networkx graph from the processed edges and vertices and keeps its largest connected components containing Zürich HB. It saves the graph locally using pickle. That file is uploaded to git lfs later on. - Planning interface (
planning.ipynb
): this notebook contains the user interface for the planning and presents it in a Voilà dashboard. Refer to the instructions above to use the planning interface. - Validation of our model (validation.md): we compare our results to ones from SBB.
Initially, we split the work among the team members as follows:
- Eloïse and Karim worked on building the infrastructure and the graph on which the search is based
- Guillaume and Tatiana worked on modeling the delays and incorporating them to the edges of the graph.
Then, since the k-shortest-path algorithm is very central to the rest of the project we worked on it in rotating pairs. In the meantime, Tatiana started working on the initial basic interface. When the algorithm was ready, Guillaume and Eloïse incorporated it to the interface. Then Eloïse and Karim worked on beautifying it and making it more user friendly.
Imagine you are a regular user of the public transport system, and you are checking the operator's schedule to meet your friends for a class reunion. The choices are:
-
You could leave in 10mins, and arrive with enough time to spare for gossips before the reunion starts.
-
You could leave now on a different route and arrive just in time for the reunion.
Undoubtedly, if this is the only information available, most of us will opt for option 1.
If we now tell you that option 1 carries a fifty percent chance of missing a connection and be late for the reunion. Whereas, option 2 is almost guaranteed to take you there on time. Would you still consider option 1?
Probably not. However, most public transport applications will insist on the first option. This is because they are programmed to plan routes that offer the shortest travel times, without considering the risk factors.
In this final project you will build your own robust public transport route planner to improve on that. You will reuse the SBB dataset (See next section: Dataset Description).
Given a desired arrival time, your route planner will compute the fastest route between departure and arrival stops within a provided confidence tolerance expressed as interquartiles. For instance, "what route from A to B is the fastest at least Q% of the time if I want to arrive at B before instant T". Note that confidence is a measure of a route being feasible within the travel time computed by the algorithm.
The output of the algorithm is a list of routes between A and B and their confidence levels. The routes must be sorted from latest (fastest) to earliest (longest) departure time at A, they must all arrive at B before T with a confidence level greater than or equal to Q. Ideally, it should be possible to visualize the routes on a map with straight lines connecting all the stops traversed by the route.
In order to answer this question you will need to:
- Model the public transport infrastructure for your route planning algorithm using the data provided to you.
- Build a predictive model using the historical arrival/departure time data, and optionally other sources of data.
- Implement a robust route planning algorithm using this predictive model.
- Test and validate your results.
- Implement a simple Jupyter-based visualization to demonstrate your method, using Jupyter dashboard such as Voilà or ipywidgets.
Solving this problem accurately can be difficult. You are allowed a few simplifying assumptions:
- We only consider journeys at reasonable hours of the day, and on a typical business day, and assuming the schedule of May 13-17, 2019.
- We allow short (total max 500m "As the Crows Flies") walking distances for transfers between two stops, and assume a walking speed of 50m/1min on a straight line, regardless of obstacles, human-built or natural, such as building, highways, rivers, or lakes.
- We only consider journeys that start and end on known station coordinates (train station, bus stops, etc.), never from a random location. However, walking from the departure stop to a nearby stop is allowed.
- We only consider departure and arrival stops in a 15km radius of Zürich's train station,
Zürich HB (8503000)
, (lat, lon) =(47.378177, 8.540192)
. - We only consider stops in the 15km radius that are reachable from Zürich HB. If needed stops may be reached via transfers through other stops outside the 15km area.
- There is no penalty for assuming that delays or travel times on the public transport network are uncorrelated with one another.
- Once a route is computed, a traveller is expected to follow the planned routes to the end, or until it fails (i.e. miss a connection). You do not need to address the case where travellers are able to defer their decisions and adapt their journey "en route", as more information becomes available. This would require us to consider all alternative routes (contingency plans) in the computation of the uncertainty levels, which is more difficult to implement.
- The planner will not need to mitigate the traveller's inconvenience if a plan fails. Two routes with identical travel times under the uncertainty tolerance are equivalent, even if the outcome of failing one route is much worse for the traveller than failing the other route, such as being stranded overnight on one route and not the other.
- All other things being equal, we will prefer routes with the minimum walking distance, and then minimum number of transfers.
- You do not need to optimize the computation time of your method, as long as the run-time is reasonable.
- You may assume that the timetables remain unchanged throughout the 2018 - 2020 period.
Upon request, and with clear instructions from you, we can help prepare the data in a form that is easier for you to process (within the limits of our ability, and time availability). In which case the data will be accessible to all.
For this project we will use the data published on the Open Data Platform Mobility Switzerland.
We will use the SBB data limited around the Zurich area, focusing only on stops within 15km of the Zurich main train station.
Students should already be familiar with the istdaten. A daily feed is available from the open data platform mobility, and google drive archives.
The 2018 to 2020 data is available as a Hive table in ORC format on our HDFS system, under /data/sbb/orc/istdaten
.
See assignments and exercises of earlier weeks for more information about this data, and methods to access it.
We provide the relevant column descriptions below. The full description of the data is available in the opentransportdata.swiss data istdaten cookbooks. If needed you can translate the column names and descriptions from German to English with an automated translator, such as DeepL.
BETRIEBSTAG
: date of the tripFAHRT_BEZEICHNER
: identifies the tripBETREIBER_ABK
,BETREIBER_NAME
: operator (name will contain the full name, e.g. Schweizerische Bundesbahnen for SBB)PRODUCT_ID
: type of transport, e.g. train, busLINIEN_ID
: for trains, this is the train numberLINIEN_TEXT
,VERKEHRSMITTEL_TEXT
: for trains, the service type (IC, IR, RE, etc.)ZUSATZFAHRT_TF
: boolean, true if this is an additional trip (not part of the regular schedule)FAELLT_AUS_TF
: boolean, true if this trip failed (cancelled or not completed)HALTESTELLEN_NAME
: name of the stopANKUNFTSZEIT
: arrival time at the stop according to scheduleAN_PROGNOSE
: actual arrival time (whenAN_PROGNOSE_STATUS
isGESCHAETZT
)AN_PROGNOSE_STATUS
: look only at lines when this isGESCHAETZT
. This indicates thatAN_PROGNOSE
is the measured time of arrival.ABFAHRTSZEIT
: departure time at the stop according to scheduleAB_PROGNOSE
: actual departure time (whenAN_PROGNOSE_STATUS
isGESCHAETZT
)AB_PROGNOSE_STATUS
: look only at lines when this isGESCHAETZT
. This indicates thatAB_PROGNOSE
is the measured time of arrival.DURCHFAHRT_TF
: boolean, true if the transport does not stop there
Each line of the file represents a stop and contains arrival and departure times. When the stop is the start or end of a journey, the corresponding columns will be empty (ANKUNFTSZEIT
/ABFAHRTSZEIT
).
In some cases, the actual times were not measured so the AN_PROGNOSE_STATUS
/AB_PROGNOSE_STATUS
will be empty or set to PROGNOSE
and AN_PROGNOSE
/AB_PROGNOSE
will be empty.
We have copied the timetable to HDFS.
We are in the process of converting the files in an easy to query table form, and will keep you updated when the tables are available.
You will find there the timetables for the years 2018, 2019 and 2020. The timetables are updated weekly. It is ok to assume that the weekly changes are small, and a timetable for a given week is thus the same for the full year - you can for instance use the schedule of May 13-17, 2019, which was a typical week for the year.
Only GTFS format has been copied on HDFS, the full description of which is available in the opentransportdata.swiss data timetable cookbooks. The more courageous who want to give a try at the Hafas Raw Data Format (HRDF) format must contact us.
We provide a summary description of the files below. The most relevant files are marked by (+):
-
stops.txt(+):
STOP_ID
: unique identifier (PK) of the stopSTOP_NAME
: long name of the stopSTOP_LAT
: stop latitude (WGS84)STOP_LON
: stop longitudeLOCATION_TYPE
:PARENT_STATION
: if the stop is one of many collocated at a same location, such as platforms at a train station
-
stop_times.txt(+):
TRIP_ID
: identifier (FK) of the trip, unique for the day - e.g. 1.TA.1-100-j19-1.1.HARRIVAL_TIME
: scheduled (local) time of arrival at the stop (same as DEPARTURE_TIME if this is the start of the journey)DEPARTURE_TIME
: scheduled (local) time of departure at the stopSTOP_ID
: stop (station) identifier (FK), from stops.txtSTOP_SEQUENCE
: sequence number of the stop on this trip id, starting at 1.PICKUP_TYPE
:DROP_OFF_TYPE
:
-
trips.txt:
ROUTE_ID
: identifier (FK) for the route. A route is a sequence of stops. It is time independent.SERVICE_ID
: identifier (FK) of a group of trips in the calendar, and for managing exceptions (e.g. holidays, etc).TRIP_ID
: is one instance (PK) of a vehicle journey on a given route - the same route can have many trips at regular intervals; a trip may skip some of the route stops.TRIP_HEADSIGN
: displayed to passengers, most of the time this is the (short) name of the last stop.TRIP_SHORT_NAME
: internal identifier for the trip_headsign (note TRIP_HEADSIGN and TRIP_SHORT_NAME are only unique for an agency)DIRECTION_ID
: if the route is bidirectional, this field indicates the direction of the trip on the route.
-
calendar.txt:
SERVICE_ID
: identifier (PK) of a group of trips sharing a same calendar and calendar exception pattern.MONDAY
..SUNDAY
: 0 or 1 for each day of the week, indicating occurence of the service on that day.START_DATE
: start date when weekly service id pattern is validEND_DATE
: end date after which weekly service id pattern is no longer valid
-
routes.txt:
ROUTE_ID
: identifier for the route (PK)AGENCY_ID
: identifier of the operator (FK)ROUTE_SHORT_NAME
: the short name of the route, usually a line numberROUTE_LONG_NAME
: (empty)ROUTE_DESC
: Bus, Zub, Tram, etc.ROUTE_TYPE
:
Note: PK=Primary Key (unique), FK=Foreign Key (refers to a Primary Key in another table)
The other files are:
- calendar-dates.txt contains exceptions to the weekly patterns expressed in calendar.txt.
- agency.txt has the details of the operators
- transfers.txt contains the transfer times between stops or platforms.
Figure 1. better illustrates the above concepts relating stops, routes, trips and stop times on a real example (route 11-3-A-j19-1, direction 0)
Figure 1. Relation between stops, routes, trips and stop times. The vertical axis represents the stops along the route in the direction of travel. The horizontal axis represents the time of day on a non-linear scale. Solid lines connecting the stops correspond to trips. A trip is one instances of a vehicle journey on the route. Trips on same route do not need to mark all the stops on the route, resulting in trips having different stop lists for the same route.
For your convenience we also provide a consolidated liste of stop locations in ORC format under /data/sbb/orc/geostops
. The schema of this table is the same as for the stops.txt
format described earlier.
Finally, you can find also additional stops data in BFKOORD_GEO. This list is older and not as complete as the stops data from the GTFS timetables. Nevertheless, it has the altitude information of the stops, which is not available from the timetable files, in case you need that.
It has the schema:
STATIONID
: identifier of the station/stopLONGITUDE
: longitude (WGS84)LATITUDE
: latitude (WGS84)HEIGHT
: altitude (meters) of the stopREMARK
: long name of the stop
Althought, not required for this final, you are of course free to use any other sources of data of your choice that might find helpful.
You may for instance download regions of openstreetmap OSM, which includes a public transport layer. If the planet OSM is too large for you, you can find frequently updated exports of the Swiss OSM region.
Others had some success using weather data to predict traffic delays. If you want to give a try, web services such as wunderground, can be a good source of historical weather data.
We offer a list of useful references for those of you who want to push it further or learn more about it:
- Adi Botea, Stefano Braghin, "Contingent versus Deterministic Plans in Multi-Modal Journey Planning". ICAPS 2015: 268-272.
- Adi Botea, Evdokia Nikolova, Michele Berlingerio, "Multi-Modal Journey Planning in the Presence of Uncertainty". ICAPS 2013.
- S Gao, I Chabini, "Optimal routing policy problems in stochastic time-dependent networks", Transportation Research Part B: Methodological, 2006.