Reputation: 886
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?
Upvotes: 0
Views: 116
Reputation: 6949
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.
Upvotes: 3