Tuesday 1 July 2014

QuickGraph: Modelling the London Underground in C#


In this example we model the London Underground, well more specifically the Victoria, Bakerloo and Circle lines.

We ask the question: what is the shortest path between Marylebone and Victoria?

This requires a change at Oxford Circus from the Bakerloo to Victoria line.  Thanks to QuickGraph we can easily model the London underground as a graph.


The way this works is that we have our TrainLine and Station classes each populated with the relevant names.  Each TrainLine has an ordered list of it’s Stations.  We then loop through each of the TrainLines and their Stations to create a graph, adding “edges” between each of the stations.  This map is then used by the library to calculate the shortest path. Source:  https://github.com/stevenh77/QuickGraphExample/

No comments:

Post a Comment