This application aims to determine the best route between two stations in Singapore's MRT.
The project is based on Typescript and uses Node.js v10 in order to execute.
- Node v10.x & NPM v6.x
The following commands will install both Node v10.x and NPM are on Ubuntu 16.04.
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
You can verify the installation using the following commands:
node --version
# Prints Node version like (v10.15.3)
npm --version
# Prints NPM version like (6.4.1)
Install dependencies:
# From the project root directory
npm install
Automated tests for the project can be run using:
# From the project root directory
npm test
Running the solution involves two steps:
- Build (Transpile TypeScript into JavaScript)
- Running the build output (javascript)
You can build the project using the following command:
# From the project root directory
npm run build
You can run the transpiled code using the following command:
# From the project root directory
npm start
The easiest way to use the solution is npm start
. Source station, Destination station and start-time (optional) are the arguments
accepted by the solution. You can provide the start-time in YYYY-MM-DDThh:mm
format. In case no arguments are provided, you will be
prompted for the same.
# Be prompted for arguments
npm start
# Provide arguments while starting the solution
# Without providing start-time
npm start -- route "Holland Village" "Bugis"
# With start-time
npm start -- route "Holland Village" "Bugis" --start-time "2019-01-01T08:00"
The following assumptions were made during the development:
- Time taken per stop, time taken per line change and the opening dates only come into effect when the start time is provided.
- If the start time is not provided, the time taken per stop and the time taken to change lines, both are assumed to be 1 minute. The opening date for the stop is ignored.
- Trains cannot travel through stations which are not open.
Example: If the following is a train line:
Station A -> Station B -> Station C
. If Station B is not open yet, there is no route between Station A and Station C.
The following terminology is used in the code:
- Line: The route that metro trains will take. (Eg: Circle Line, NorthSouth Line, etc.)
- Line Code: The first two letters of all the stops in the line. (Eg: The line
NS1 -> NS2 -> ...
hasNS
as the line code) - Line Stop/Stop: All the stops made by a particular line. This is the place where users embark and disembark. (Eg: The line
NS1 -> NS2 -> ...
has[NS1, NS2, ...]
as the line stops) - Station: A station is home to one or more Line Stops. Any stations which has more than 1 stop, is an intersection station.
- Intersection Line: Intersection Line is a virtual line used to connect two stops of the same station. This concept is used to make
line-change possible in the searching algorithm used.
(Eg:
Little India
is home to two stops:NE7
&DT12
. While searching for an optimal route, an intersection line is used to connectNE7
&DT12
).
Here are the known issues with the solution:
In case a train line is closing or opening in some time (due to night hours), but the start-time provided is just before the closing time, the solution only takes into account the train lines which were open at the start-time provided. Any lines closure/opening that happens after the start-time is not taken into account while determining the route.
Example:
Suppose a user is trying to go from Caldecott to Newton at 2019-01-01T21:59
. The optimum route, without considering the line closure
which takes place at 22:00
, would be CC17 -> CC19 -> DT9 -> DT10 -> DT11
. However, since the DT line closes at 22:00
, the user will
not be able to switch to the DT line.