You are given a weighted connected graph (20 nodes) with all edges having positive weight. We have a robot that starts at point A and it must pass at points B, D and E for example. The idea is to find the shortest path that connects all these 4 points. The robot also has a limited battery, but it can be recharged in some points.
After researching on the internet I have two algorithms in mind: Dijkstra's and TSP. Dijkstra's will find the shortest path between a node and every other node and TSP will find the shortest path that connects all points. Is there any variant of the TSP that only finds the shortest path between a set of nodes? After all, in the TSP all nodes are labeled "must-pass". I'm still not taking in account the battery constraint.
Thanks in advance!
You can reduce your graph to a TSP and then invoke a TSP algorithm on it:
u,v
for ALL pairs of verticesu
andv
.u
andv
as the distance found by Floyd-Warshall.The above is optimal, because assume there is a shorter path.
Di->...->D{i+1}
has at least the weight ofFloydWarshall(Di,D{i+1})
(correctness of Floyd-Warshall), and thus the edges(D0,D1),(D1,D2),...,(Dk,D{k+1)
exist in the modified graph with a weight smaller/equal the weight in the given path.Thus, from correctness of your TSP-Solver, by using
D0->D1->...->Dk->D{k+1}
, you get a path that is at least as good as the candidate optimal path.You might also want to look into the generalized traveling salesman problem (GTSP): The nodes are partitioned into subsets, and the problem is to find the minimum-length route that visits exactly one node in each subset. The model is allowed to choose whichever node it wants from each subset. If there are nodes that must be visited, you can put them in a subset all by themselves.