shortest way with more then 2 Points, but fix Order
at first, please excuse my bad knowledge in english.
I've got the following Problem: I must find the shortest way between more then 2 Points in a fix order (e.g. A -> D -> F). I am familiar with the algorithm of Dijkstra. But that one does only compute the shortest ways between two Points. And I've also heard of the TSP, but that does not seem to fit, too. Because there is no fix order. I have searched the web for my Problem already, but maybe this is not an very popular one, or I've used the wrong key words.
Still, there must exists a solution, because there are many route planner, which successfuly provide this function.
So please, can anyone help me with my Problem by namin开发者_开发技巧g an aglorithm, or give me some advice.
thank you very much, for your help! yours sincerely, Angelo
//edit Oh, it is very embarrasing. It seems that I have thought to long, so I failed to describe the real issue. Its like that: There are some Tickets, that can only be used from begin.
T1: A -> B (costs 50) T2: B -> C (costs 50) T3: A -> B -> C (costs 80) The given route is A -> B -> C
Now you see, if we treat the given route as two separated Problems we will become a total cost of 100, but obviously the Ticket T3 is the better solution.
If some of the points are fixed but others are not (meaning the user wants to go from A->D->F
, but the graph means they might have to do A->B->C->D->E->F
) this a standard problem. Either you care about the order ADF or you don't (it might be AFD). In the first case, it is simple two paths (A->D
D->F
) which you compute independently. In the second case, it is more like TSP.
You can find the shortest path between A and D, then the shortest path between D and F etc. Applying Dijkstra algorithm multiple times for each pair of nodes.
精彩评论