I am looking for a bit of help with some work I have.
The task is to create a London Underground journey planner.
Edit:-
At the moment I have an adjacency list of nodes with edge data in a HashTable.
I want to find a way to use Breadth-First searching to get a shortest path between any two vertices.
The vertices are connected logically as the tube map looks. Each station’s edge is represent by using: (this_station, next_station, tube_line) <- this is the info I have about each station.
Traversing this is quite tricky. Any help seriously appreciated!
This is a classic graph theory problem. You can represent your stops as nodes, and your connections between stops as edges.
To directly answer your question, I believe the best way to represent segments of lines into a single line would be to make a graph which represents all lines. You can tag your edges with a data flag (or set of flags) to represent which line(s) the nodes belong to. Ultimately, regardless of lines, stations and segments, this is a graph. If you are interested in representing these concepts, the way I would recommend storing them would be as attributes of nodes (or edges).
If you are interested in removing these edges, you can iteratively remove edges which are purely intermediate. So, if A->B->C, and B has no other connections, you could remove B and add it’s B->C weight to the A->C weight.
Using a graph representation will allow you to apply existing shortest-path algorithms to your problem.
Good luck!
-Brian J. Stinar-