Alessandro
Alessandro

Reputation: 886

Best algorithm to get the path with less changes

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

Answers (1)

iForests
iForests

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

Related Questions