1

I've been reading about different algorightms for solving the traveling salesman problem but can`t seem to find a example where you do not wish to visit all the nods in the graph. In example, lets say I have a graph made up of the nods n1,n2,n3,n4,n5,n6. In the classic traveling salesman problem I would want to visit all the nods in the shortest time possible. But what if I wish to leave from n1 and visit n3 n5 and n6 only. I can pass through the other nods if I have to but the only ones I absolutely have to visit are n1 n3 n5 n6 and back to n1. This means that what I'm looking for is the shortest path from n1 to n1 that passes through these 3 points. Any hint on which algorithm to look at would be welcome.

Thank you

Samuel Benitah

1 Answers1

1

Let V be the set of vertices the you are required to visit. Let d(u,v) be the length of the shortest path from u to v. For every pair of vertices u and v in V, add an edge from u to v with length d(u,v). Let this graph be G, i.e., G is the original graph augmented by these edges. Let G_V be the G restricted to V. Your problem is equivalent to solving the TSP on G_V. To see this, note that if P is a segment in an optimal path in G satisfying your constraints such that only its endpoints(say u and v) lie in V, then the length of P should be d(u,v). If not, you can replace that segment by a shortest path from u to v and improve the optimal solution.

Pradhan
  • 16,391
  • 3
  • 44
  • 59
  • First of all thank you for the answer. I have a few questions regarding it. Let's say I have a graph V with 4 nodes n1 n2 n3 n4. I wish to leave from n1 and visit n2 to come back to n1. The 2 paths possible are n1-n3-n2 or n1-n4-n2. If I were to construct the graph G based only on optimal paths it would only contain the shortest path n1-n3-n2. As such G would only contain 1 path and and would use the path to visit n2 and to come back to n1. This wouldn't work for me because he would visit n3 twice. The answer I would need would be to visit n1-n3-n2 to visit n2 and n2-n4-n1 to come back. – Samuel Benitah Dec 14 '14 at 20:06