0

I am trying to solve the TSP (Travelling Salesman Problem), but not in a traditional way. I am following these steps.

1) First I change the TSP to a true / false problem.

The definition of this problem is now: "Is there a route by all the cities with a total distance less or equals than k?" Let's assume I have an algorithm TSP_tf(k) to solve it.

2) Then I search the minimum k.

This is, I search "which is the distance of the shortest possible route".

An efficient algorithm to solve it would be with a dichotomic search. I begin with k=1, and I call TSP_tf(k). If it returns false, I multiply k by 2, and keep calling TSP_tf until true is returned. When this happens, search the minimum k that returns true in the interval (k/2 - k], also with a dichotomic search.

I will get then the minimum distance min_k.

3) Return the shortest route of the TSP knowing its distance is min_k.

And here is where my question comes. How would be an efficient algorithm to solve this? By efficient I mean a good approach :) It is obvious that TSP will remain being NP.

Santiago Gil
  • 1,292
  • 7
  • 21
  • 52
  • I think this is a bit too broad for us to handle. Maybe [cs.se] would be willing to take this up, but even they may want something more concrete to start with. I'm not sure what your goal actually is, since all three steps are (I think) NP. – Teepeemm Sep 27 '16 at 19:36
  • Feeding `min_k` to the ILP model would allow you to prune a lot, but explaining that approach in detail takes a whole book. – harold Sep 27 '16 at 19:41
  • 1
    I'm voting to close this question as off-topic because it's about computer science, not applied to programming. [It has been reposted to Computer Science](http://cs.stackexchange.com/q/64037). (In the future, [please don't do this](http://meta.stackexchange.com/q/64068), [flag](http://stackoverflow.com/help/privileges/flag-posts) your question to request migration instead.) – Gilles 'SO- stop being evil' Sep 29 '16 at 13:17

2 Answers2

1

Your TSP_tf is what is normally known as the decision problem version. That problem is NP-complete, see https://en.wikipedia.org/wiki/Travelling_salesman_problem#Computational_complexity for verification. Therefore you shouldn't hope that it will be very tractable.

That said, the same Wikipedia article has plenty of information on surprisingly effective ways to solve the TSP problem in practice.

btilly
  • 43,296
  • 3
  • 59
  • 88
  • Yes I knew that terminology, but in my language, not in English. Thank you for the link, sounds interesting, but for the moment I want to solve the problem this way, just for curiosity. – Santiago Gil Sep 28 '16 at 13:32
0

I managed to solve it finally.

Suppose we have a graph g which represents the cities and their conections of the TSP. A node represents a city and a weighted edge represents that there is a connection between both cities with the corresponding distance of its weigth.

In order to get the shortest route given its distance, let's delete one to one the edges, and see if they are part of the shortest route. How can we know it? If we delete an edge e from the graph and we call TSP_tf with the known shortest distance min_k, two things can happen:

  • TSP_tf(min_k) == false. This is, deleting e makes not possible to obtain a route with min_k distance. e is part of the shortest route.

  • TSP_tf(min_k) == true. Without the connection e, it's still possible to obtain a route with the same minimum min_k distance. e doesn't take part of the shortest route.

If we apply it progressively to all the edges of the graph, we can obtain the exact shortest route (or better said, one of the shortest routes, because there may be more than one solution).

// min_k is the distance of the shortest path of the TSP represented by the graph g.
Graph TSP(Graph g, int min_k)
    Graph shortestPath = g;
    For (Edge e in g)
        // Delete the edge e.
        shortestPath -= e;
        // e is part of the shortest path.
        If (TSP_tf(shortestPath, min_k) == false)
            shortestPath += e;
        EndIf
    EndFor
    Return shortestPath;
EndTSP

As we know, the maximum number of nodes of a graph is 1/2 * |V| * |V-1|, being |V| the number of nodes. A TSP_tf call is done for each node, so the number of calls to TSP_tf has a peak O(|V|^2), being an efficient algorithm.

Santiago Gil
  • 1,292
  • 7
  • 21
  • 52