Metrenq: Find your way in the Delhi Metro

I built this webapp a couple of weeks ago. It was a fun weekend project. I arrived at the idea when I was travelling in the Metro and was unable to find an app that would give me proper directions, like which train U needed to board, headed to which station, or if I had other route options etc. Or I would have to fire up data-hungry Google Maps when I had less data available and was on a slow connection.

Moreover, I was really fascinated by the idea of representing the complex Delhi Metro map, its stations and interchanges, in Javascript and utilising that data to find possible routes between two stations.

The app is available at http://thezillion.github.io/metrenq

The app does not have great aesthetics by the way.

How to

Just enter the boarding and deboarding stations and it will list the number of routes, ranking routes by number of stations, and also displaying number of interchanges for every route.

How I built it

The app is written completely in Javascript. The data is stored in JS objects and does not utilise any database. Though this increases the load time, the in-app processes are fast because it doesn’t need to run AJAX to load Python script data. The data is available at the frontend

I used jQuery and the awesome Select2 library.

Data objects

All data is stored in three JS objects: stations, lines, and ipoints.

Only the stations object and a part of the lines object are loaded from the server. The other three data objects are populated using the process_data function.

The stations object contains basic station data: the station name, lines it loes on, and station number. This number is the way of representing the station throughout the program.

The lines object contains line data: stations on each line in the correct order and also tells which line it intersects with, and at which station.

The ipoints object is a fast access object meant to list all the ipoints for every line.

Some terms

Ipoint: Short for intersectiom point, an ipoint is the station where two lines cross each other.

One-interchange relationship (OIR): Two stations are in an OIR if we can go from one to the other by interchanging only once.

Algorithm

The task is to find all possible routes between two points (stations) on the map. The stations may be:

  1. on the same line
  2. in an OIR
  3. connected through more than one interchange

The first two cases are simple. The third case is a bit complex. I’ll explain the algorithm using three examples signifying each of the three cases.

In the second case, I simply find a common interchange point for the two stations based on the lines of the two stations.

In the third case, I find the ipoints on the current station’s line(s) and recursively try to find an OIR between the ipoint and destination station. If an OIR is not found, I again find the ipoints for this station and repeat the process.

Plans

I’m still working on the app. I plan on making the displayed information more detailed, plus improving the aesthetics.

Hope you like it! http://thezillion.github.io/metrenq/

Delhi Metro Map

This is what the Delhi Metro map looks like. It’s still growing and getting denser.

Delhi Metro Map

Advertisements