Skip to content

Train Graph Building

jloh02 edited this page Jul 23, 2021 · 4 revisions

Since LTA does not directly provide train data, the only data regarding trains publicly given is via the Datamall Geospatial API. Using GeoTools and its SHP parser, the TrainStations and TrainExits features can be processed.

Linear Train Vertex Creation

In Singapore, all train stations are given an ID (e.g. CC15). The first 2 letters indicate the line, while the following number indicate the stop sequence. Numbers are sometimes omitted due to cancelled stations. Assuming each MRT line is a straight line with no branches or loops, edges can be created similar to that of bus stops, except for the fact that edges are bidirectional.

Exceptions to this assumption are ignored in this process using the 2 regexes in application.yml

exclude-line-branch: '(^CE\d$)|(^CG\d$)'
exclude-line-loop: '(^BP\d{1,2}$)|(^STC$)|(^PTC$)|(^SE\d{1,2}$)|(^SW\d{1,2}$)|(^PE\d{1,2}$)|(^PW\d{1,2}$)' 

Handling Branches

Some MRT services (ie EW and CC) have branching services, some of which require changing trains while others do not.

Configuration

In application.yml, a sample branch would look like this:

branch-node: CC4
src: CE1
des: CE2
join: true   
transfer-time: 0
post-branch-service:
  ascending: 'Circle Line (HarbourFront)'
  descending: 'Circle Line (Dhoby Ghaut/Marina Bay)'
branch-service:
  ascending: 'Circle Line (HarbourFront)'
  descending: 'Circle Line (Marina Bay)'

Since Linear Train Vertex Creation traverses train stations in ascending numerical order, branch-node determines after which stage that branching has to occur. The branch's start and end point are denoted by src and des. The boolean join determines if the branch joins with the main line at branch-node or splits with it. As of date of writing this document, only joins occur on Singapore's train system. transfer-time is the time taken to change from the main line to the branch. On the Circle line, there is no change of train required. Hence, transfer-time: 0. After branching, the service name of the main line and branches have to change. Therefore, the post-branch-service and branch-service configurations determine this.

Pseudocode

The branching logic during linear vertex creation is as such:

Linear traversal:
	Once see <branching node>
	Determine whether <join or split (bool)>

Looping and processing:
	For every node after <branching node> (check if currBranch is null), use post branch service names
	For every node on the branch, use branch service names

Loops

Train loops (in LRTs) are handled in 2 different ways. There are 2 kinds of loops: (1) A simple circle (2) A circle loop with a line at a single interchange station. (1) describe the PTC and STC LRTs while (2) refers to the BP LRT.

Handling both cases are similar to linear creation, except for the fact that there exists an extra edge to join the loop's last node to the first node.

Interchanges

Train interchanges (stations which serve 2 lines) can connect both lines by creating a vertex between each "node" (internally different nodes but same "node" in reality) with a "Walk (Interchange)" service and transfer-time determined in application.yml

Frequency and Operational Hours

Since LTA does not easily provide an API to obtain train frequencies and operational hours, this project assumes these values taken from Land Transport Guru