Siddharth Sharma 2025492 Group 16
A Python-based command-line tool that simulates the Delhi Metro network. It calculates the shortest routes between stations, handles line transfers, estimates travel times based on peak/off-peak frequencies, and calculates fares.
Lines included: Blue, Magenta, Yellow, Blue-Vaishali(taken as an independent line originating from Yamuna bank). However if added properly into the metro_data.txt file, the program is scalable for even more lines.
here is a link of whiteboard I used before starting to code, it very much explains the entire project: https://excalidraw.com/#json=9-lZMmWAazooaugkUlGcP,EiFV1YCp2G2V7b6hsNrFGA
- Scheduling: Calculates exact departure and arrival times from each direction.
- Routing: Finds the most efficient route by time between two stations.
- Peak vs. Off-Peak Logic:
- Peak Hours: Frequency is every 4 minutes.
- Morning: 08:00 - 11:00
- Evening: 17:00 - 20:00
- Off-Peak: Frequency is every 8 minutes
- Peak Hours: Frequency is every 4 minutes.
- Fare Calculator: Calculates based on number of stations travelled, data is according to DMRC website.
- Download the files
- metro_simulator.py : contains the python program to run.
- metro_data.txt : contains the data of metro in the following order as comma separated values Line,Station,NextStation,TravelTime,Interchange
- Save them in a same folder and and the terminal run
python3 metro_simulator.py
- The program gives 2 choices which can be chosen by entering 1/2 respectively.
- The time to travel between two stations is hypothetical as DMRC doesn't not provide the actual data and it depends on many factors.
- Blue line splits at Yamuna Bank towards Vaishali and Noida Electronic City, I have assumed that every metro starting from Dwarka Sec 21 goes to Noida and that Yamuna Bank is an interchange.
- Fixed Interchange time of 3 minutes.
- Special discounts like weekends and through metro cards are not included.
- Assumes between operation between 06:00 to 23:00, also that if first metro starts from Dwarka Sec 21 then first metro at Dwarka will be at 06:03 and similarly for last metro.
- While calculating next metros I have assumed that all metros before it came at a fixed interval of frequencies (4/8)
-
Data loading Data is passed onto three variables as follows: 1.
METRO_LINES: a dictionary containing lines as keys and a list of their stations as values 2.TRAVEL_TIMES: a dictionary containing (current_station, next_station) as keys and time to travel between them as its value 3.INTERCHANGES: a dictionary containing interchange station as keys and set of lines they are on as values. -
Path finding algorithm
- transfers must be less than 2 to constrain recursion depth
- maintain a set of visited stations as the recursion might fall into a circular loop.
- checks if both the stations are on same path, if yes then finds a path linearly and adds it to a list of all paths.
- if stations are not on same path, then finds common interchanges and recursively find path from source to interchange and then interchange to destination and add every possible path into a list.
- then returns the route that takes least time.
-
Scheduling next metro and subsequent metros
- Offset calculation: the program calculates the offset from lines terminals stations to the users station. example: If it takes 20 minutes to reach Rajiv Chowk from Samaypur Badli, the first train arrives at
06:00 + 20 mins = 06:20. $T_{next} = T_{start} + k \times Frequency$ - where k is obtained by finding
k = math.ceil((check_time - first_arival_start) / get_frequency(check_time)) - Subsequent metros are calculated as follows
-
Metro 1 (
$T_1$ ): Calculated as above. -
Metro 2 (
$T_2$ ):$T_1 + Frequency(at \ T_1)$ -
Metro 3 (
$T_3$ ):$T_2 + Frequency(at \ T_2)$
-
Metro 1 (
- Offset calculation: the program calculates the offset from lines terminals stations to the users station. example: If it takes 20 minutes to reach Rajiv Chowk from Samaypur Badli, the first train arrives at
Kindly also see the whiteboard linked before as it contains the flow of code in implementing these algorithms.
- "Station not found": Station names are Case Sensitive, Mayur Vihar and mayur vihar are different.
- Stations between Yamuna Bank and Vaishali lies on a line named "Blue-Vaishali".
- Make sure that metro_data.txt is in the same folder as the python file
- Ensure that the metro_data.txt file is not broken, and that it has links between the stations.
Siddharth Sharma 2025492 Group 16