Skip to content

Using the London Underground to explain pathfinding algorithms visually

Notifications You must be signed in to change notification settings

zeevox/animated-london-tube

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Animating the London Underground tube map!

The tube map is an excellent way of explaining pathfinding algorithms. In fact, it is often used in company interviews as a way of testing the candidate's knowledge of graph data structures and shortest path algorithms.

This project aims to visualise algorithms such as BFS, DFS, Dijkstra and A* using the tube map.

Video

How do travel planners work? on YouTube by Timothy Langer

Press the thumbnail above to view the final video on YouTube, or click here.

Thorough write-up

For a detailed explanation of what this project was all about and how I did it, please see my blog post.

Brief overview

I converted the official tube map provided by TfL into an SVG file and removed clutter such as DLR, Trams and Thameslink that do not belong on a map of the London Underground. Next, I individually selected each station in the SVG in Inkscape and gave it a unique ID. In this case, I based the ID off the three-letter station codes that TfL uses.

In addition, I downloaded the average inter-station travel times from a TfL FOI request provided in XLSX format. This was converted into a CSV for simpler parsing.

tube.py is a wrapper for importing the aforementioned SVG and inter-station travel times and provides methods for individually showing / hiding stations on the map as well as changing their opacity.

In main.py are the actual pathfinding algorithms. During their execution, they show/hide visited stations and write to an SVG file for every frame.

The SVG files can then be rasterised and formed into an MP4 using ffmpeg to create a visualisation of the pathfinding algorithms at work.