0

One of the classical Travelling Salesman Problem (TSP) definitions is:

Given a weighted complete undirected graph where triangle inequality holds return an Hamiltonian path of minimal total weight.

In my case I do not want an Hamiltonian path, I need a path between two well known vertexes. So the formulation would be:

Given a weighted complete undirected graph where triangle inequality holds and two special vertexes called source and destination return a minimal weighted path that visits all nodes exactly once and starts from the source and ends to the destination.

I recall that an Hamiltonian path is a path in an undirected graph that visits each vertex exactly once.

For the original problem a good approximation (at worse 3/2 of the best solution) is the Christodes' algorithm, it is possible to modify for my case? Or you know another way?

Paolo.Bolzoni
  • 2,416
  • 1
  • 18
  • 29
  • Do you have the constraint that each vertex must be visited exactly once? – bloops Mar 08 '13 at 17:35
  • For what it's worth, the variant of the Hamiltonian Path problem where the start/end vertices are specified is sometimes known as "Restricted Hamiltonian Path". – mhum Mar 08 '13 at 18:23
  • In that case, add a vertex s' with a 0-weight edge (s',s) and a vertex t' with a 0-weight edge (t,t'). The new graph still satisfies triangle inequality. In the new graph, every Hamiltonian path must start at s' and end at t' (or vice versa) from which you can extract an s-t path in the old graph. Thus, now you can use standard approaches to the problem. – bloops Mar 11 '13 at 16:47
  • So I get a new graph adding nodes s' and t' added and edges (s', s) and (t,t') of weight 0. The Hamiltonian path will pass through s' and t' as it visits all nodes, but how can I extract a s-t path? I cannot simply drop the part between s' and t' as it might contains other nodes. E.g., a -> s'-> s -> b -> t -> t' -> a again. – Paolo.Bolzoni Apr 20 '13 at 11:21

3 Answers3

0

Add an edge (= road) from your destination node to your source node with cost 0 and you've got a TSP (for which the triangle inequality doesn't hold though).

The book "In pursuit of the Traveling Salesman" briefly mentions this technique.

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • The graph is complete, there already an edge between the source and destination. I am not sure that altering the weight makes sense. Does it? – Paolo.Bolzoni Mar 08 '13 at 18:09
  • I think I got an idea out this. Add a vertex with only two edges of zero weight to source and destination. Finally calculate the Hamiltonian path on the new graph. The 0 weight ensure the source and destination are consecutive. Just remove the extra node and relative edges and you got a solution. – Paolo.Bolzoni Mar 08 '13 at 18:18
0

Why don't you use dijkstra's algorithm with extra book keeping on each node for the path information. i.e., the list of vertices passed in the shortest path to that particular vertex from the source.

And stop when you reach your end vertex. Then your path will be

Path to the starting vertex of the current edge + current edge.

where current edge is the last edge which lead you to your destination.

vishnu viswanath
  • 3,794
  • 2
  • 36
  • 47
0

You can alter a TSP algorithm to make sure you use the edge between start and finish. Then simply remove the edge from the TSP result and you get your path.

In other words, if you add the edge from start to finish to your path, you get a TSP solution, but not necessary the optimal one.

In greedy algorithm, you have a sorted list of all edges L and an empty list I. You keep adding the shortest edge that does not form a cycle until you pass all vertexes. Simply remove the edge from start to finish from L and add it to I before you add the rest of the edges.

In nearest neighbor, you start from one vertex, then add the shortest edge that starts at that vertex and leads to any vertex that has not been visited. Mark your finish as visited, then start from your start vertex and add the edge between the last vertex in the resulted path and the finish and you got your path from start to finish.

There are other TSP algorithms that can be altered to provide this path.