

Traveling Salesman: the most misunderstood problem - alter8
http://www.nomachetejuggling.com/2012/09/14/traveling-salesman-the-most-misunderstood-problem/

======
tgflynn
The TSP optimization problem is polynomial time reducible to the TSP decision
problem by binary search.

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.

~~~
chmike
A priori it would be a computer science revolution if this would have been
missed by everyone until now. So forgive me to be particularly cautious with
your proposal. What I think is missing in your analysis is that we are lacking
a polynomial method to build an hamiltonian path with cost <= C. If we had,
then we would apply your algoritm to optimize in polynomial time.

~~~
alextp
The above construction is a not a breakthrough and it is how I was taught in
my approximate algorithms class. Also the way the optimization problem is
usually defined is not as "give a circuit with minimal cost" but "what is the
cost of the minimal-cost circuit?", which is easier to reason about in an
approximate way.

~~~
mikeash
Same here. Intuitively, a decider that can answer "Is there an answer less
than X?" will give you one bit of the lowest cost each time you query it. Do
it repeatedly until you have all of the bits, and you're done.

~~~
konstruktor
No nonempty interval of real numbers can be represented in a finite number of
bits.

~~~
tgflynn
That's exactly what floating point numbers are: representations of real number
intervals as finite length bit strings. The number of bits simply determines
the granularity of the representation (ie. the width of the intervals).

~~~
konstruktor
Floating point numbers are approximations of real numbers, which isn't
sufficient in this context. Solving a lossy representation of the problem
isn't a reduction in the complexity theoretic sense.

~~~
tgflynn
In the case of this problem the set of possible paths is finite so it can, in
principle, be sorted in order of increasing cost. The smallest cost delta
between any 2 paths in the sorted list is the lowest cost edge in the graph
(this probably assumes that all edge costs are positive) so you only need to
continue the binary search until intervals of this size are reached. At that
point the exact solution has been found.

EDIT: There might be multiple paths with the same minimal cost but binary
search will still find this value.

------
mistercow
This is a major point of confusion for people who are new to the concepts, and
I'm glad someone has taken the time to explain it in depth. And it's not just
TSP that it happens with. Almost every popular example of an NP-complete
problem I've seen is actually an NP-hard optimization problem corresponding to
an NP-complete decision problem.

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.

------
jb17
I think the author actually adds to the confusion about TSP by being
unnecessarily vague.

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.

------
gilgoomesh
Perhaps I simply know different people but I'm accustomed to Travelling
Salesman, without explaining which version is intended, being given as the
canonical NP-Hard (implicitly the optimal solution problem).

I normally see SAT given as the NP-complete example.

~~~
jcd748
Yes, I've always seen SAT as the canonical example given. Though, when I did
some reading into phase transitions in NP-complete problems, 3-SAT was usually
the example given (and used).

------
drobilla
Well, this is true, but it's also hyperbole. It's not really everybody
misunderstanding the problem so much as simply not caring. People are sloppy
with the terms "NP-hard" and "NP-complete" and use them interchangeably
because it's usually not important. Usually they mean "NP-hard", and that is
the significant thing.

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.

~~~
IsTom
And usually they just need to say that it's intractable, unless they're
speaking about some kind of solver or approximation classes.

------
jlebar
Ironically enough, I think this guy misunderstands TSP. I wrote this comment
on his blog:

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.

~~~
peterderivaz
I guess you could find the shortest path by iteratively deleting an edge and
checking whether the best cost has got worse. If it does get worse, then put
that edge back in and try deleting another edge. If it does not get worse,
then permanently delete that edge.

I think this should terminate (after trying all edges once each) with an
example of the shortest path (that consists of all remaining edges).

------
jawns
Just a small quibble:

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.

------
sherjilozair
Since optimization and decision problems are equivalent, what someone means by
saying that an optimization problem is in np-complete is that its equivalent
decision problem is in np-complete.

------
dsr12
TL;DR: For now TSP-OPTIMIZE is in NP-Hard but not (necessarily) in NP, so its
not in NP-Complete. TSP-DECIDE is both in NP-Hard as well as NP, and is
therefore NP-Complete.

------
zxcvbn
Thank you. I finally get what NP-complete is.

------
drivebyacct2
I'm so thankful. After 4.5 years of CS, the only class that taught me anything
was my advanced algorithm class and I _learned_ enough to retain an immense
amount of the information a year later. This is fun stuff and I hated it two
years ago.

