I am working with a subway network. I have to find some paths between A and B that respect some rules, for example, the fastest, shortest, etc... I know how to solve those, but one of the rules is to find a path with less changes between lines, is there any algorithm used for that?
Asked
Active
Viewed 101 times
0
-
I don't see how that differs from the others. Couldn't you just, say, add some arbitrary delay in travel time to a change of trains and then use the `fastest` algorithm to find the path with less changes? – 500 - Internal Server Error Jan 07 '15 at 19:49
1 Answers
3
Treat a subway line as a node in graph, and connect two nodes by an edge if there is an intersection of two subway lines. Now, you can use Dijkstra's algorithm to find the shortest path.

iForests
- 6,757
- 10
- 42
- 75
-
Shortest path is found by Dijkstra but not sure how to find train changes while calculating closest nodes to each node. – Mohit Dec 16 '21 at 22:50