Traveling Salesman: the most misunderstood problem
nomachetejuggling.com
nomachetejuggling.com
Suppose we have an algorithm D(TSP,C) which returns 1 if the TSP has a path of cost <= C.
Then the basic idea for an algorithm for the optimization version is :
C = sum( costs of all paths in graph )
while D(TSP,C) == 1:
C = C / 2
Probably the greatest thing about having a polynomial time algorithm for an NP complete problem would be that it would allow finding the global optimum for any finite optimization problem in polynomial time.Going from there to "what is a minimum-cost circuit?" is a bit more work, but still polynomial:
G' = G
X = TSP-minimum-circuit-cost(G)
for E in edges(G):
if (exists-circuit-with-cost(G' minus E, X))
G' = G' minus E
return (G')What you show is that the problem of finding the lowest cost is in FP^NP (the class of function problems solvable in polynomial time with the help of an NP oracle). However, by taking your idea a bit further one can show that TSP is in FP^NP. In fact, it is known that TSP is FP^NP-complete, i.e. it is one of the hardest problems in that class (and thus likely not in FNP, the NP for function problems).
Let's assume doing an actual binary search. What you are getting, in every step of binary search using your oracle, is an upper bound U (D(TSP, U) ==1), for which we know that there is a solution smaller or equal that U, and a lower bound L (D(TSP, L) == 0) for which we know there isn't. This is where your confusion between finite and integer-valued comes into play: If the problem were integer valued, you would have the optimal solution S as soon as L_i=U_i (implying U_i is S), which would be guaranteed after a polynomial number of steps. With real valued weights, all you get is a sequence of intervals (L_1, U_1], (L_2, U_2], ... where the size of the intervals is halved in every step. What you actually want is the exact value of the solution. For that, you would need to show that there is no hamiltonian path between L_i and U_i, which isn't something your oracle can determine.
Note that this probably doesn't show that a polynomial oracle for the TSP decision problem will not yield a polynomial solution to the optimization problem in general, it just deals with your proposition. Edit: Not -> Note
You only need to binary search that set, not the real numbers' axis. The set's size is exponential to N, but binary searching is logarithmic, so it becomes polynomial in N.
A) Sort edges (descending).
B) Have a total order between N-sized subsets by treating each edge as a binary digit (1 if it is in, or 0 if it is not). I believe this guarantees that the total order between the binary numbers that correspond to edge selections is the same total order as the one between the sums of those selections.
C) Start with some first guess (e.g: 111...111000000...)
D) Binary search on the number, by adjusting each next guess to be the nearest number with N digits enabled.
I am not entirely sure, I just made this up, but I think it might work?
For a practical idea of how you'd do this, I think you'd just modify your binary search based on the possible circuit values. Basically, figure out what number excludes half of the remaining solutions, rather than just half of the range, and use that in your binary search.
Now, if I had such an oracle, I would let it loose on all graphs equal to the target graph with one edge removed. I think (but cannot prove (yet?)) that that is a way to prove, for each edge, whether it is by necessity part of the shortest tour. I also supect that, for most graphs, the set of remaining "might be in the shortest tour" will be so small that an exhaustive search will be easy.
EDIT: There might be multiple paths with the same minimal cost but binary search will still find this value.
There are O(V!) possible paths. Assuming binary search actually halves the search space each iteration, it will run in O(log(V!)) = O(log(n(n-1)...*1)) = O(log(n) + log(n-1) + ... + log(1)), which is clearly polynomial.
So to actually solve the optimization version you would need two iterations/recursions around the call to D. The inner iteration finds a solution with the desired property, ie. cost <= C and the outer one does the binary search over C. Overall it still reduces to a number of calls to D that is polynomial in the number of bits used to represent the problem, including those used to represent the weights.
The problem with the original blog post is that while the author states correctly that the TSP optimization problem is NP hard rather than NP complete because it doesn't have the form of an NP problem, he doesn't mention that it is also NP easy and therefore NP-equivalent (see last line in this Wikipedia article):
The bad part is that if you don't know better, you'll think "Wait, how the hell would you verify a correct answer to this without searching for an even shorter path?" And you'll be right, but you'll feel like you're missing something. Giving examples of CS that make people feel like they fundamentally don't understand CS is probably a Bad Thing.
Both P and NP are classes of decision problems. That means they only contain problems that ask for a yes/no answer. So because TSP asks for a route, it is not just a decision problem, and can't be in NP. However, as the author mentions, NP does in fact contain the TSP-DECIDE problem in the way he defines it.
Moreover, the problem TSP of finding a lowest cost route can be solved by a polynomial time Turing Machine that can use a TSP-DECIDE oracle (i.e. call a constant time function that solves TSP-DECIDE). It is in fact complete for that class FP^NP ("= function problems solvable in polynomial time with an oracle for NP problems"), which means it is one of the hardest problems there. The class FP^NP contains all of FNP (NP for functional problems) and is believed to contain more problems -- so there is a good chance that TSP is not in FNP.
I normally see SAT given as the NP-complete example.
Yes, it's wrong to use "NP-complete", but plenty of people who thoroughly understand the problem do so. Welcome to Computer Science, sloppy is par for the course.
Let's define a new problem, TSP-cost-optimize, which returns the cost of the best Hamiltonian. It's NP-Complete, because it reduces to TSP-decide: Just do a binary search on the space of possible scores; even if that space is exponential, we're fine, since binary search runs in the log of the size of the space.
TSP-cost-optimize's certificate can be the steps of the binary search; that will be polynomial in size, since it's a polynomial number of TSP-decide certificates, and you can verify it in polynomial time.
Given TSP-cost-optimize, I can in fact provide a polynomial-time-verifiable certificate for the result of TSP-optimize: The result of TSP-cost-optimize on the same graph! So under your definition of NP, TSP-optimize is in fact in NP. (This also makes sense if you use the non-deterministic Turing machine definition of NP.)
What's not clear to me is whether given the result of TSP-cost-optimize, you can actually find a shortest path in polynomial time. But I expect you probably can.
I think this should terminate (after trying all edges once each) with an example of the shortest path (that consists of all remaining edges).
If you're going to provide a TL;DR: it's probably better to stick it up top. Otherwise, the people who DR because it's TL will likely never find it.