News for hackers. Stuff that matters.
Re:The TSP Isn't NP Complete by ColinWright on Monday December 30, 2013 @12:19PM (#6985545)

  > ... there seems to be a fair amount of confusion
  > about it on the web.
There's a lot of confusion on the web about this. And while it's true that this is largely a small technical point, this is an area where small technical details can matter.

  > It's true that TSP is not NP complete because it is
  > not in NP, because it is an optimization problem, not
  > a decision problem.
So we make it a decision problem by saying: "Is there a tour with cost less than K?"

  > ... if you have an algorithm that can solve any NP complete
  > problem in polynomial time (ie. P == NP) then you can use that
  > algorithm to solve TSP (actually any finite optimization problem)
  > in polynomial time.
And, roughly speaking, you do that by binary searching on the cost of a solution. Set a lower limit of 0 and a random upper bound. Keep doubling that till you get a solution, then binary search.
Re:The TSP Isn't NP Complete by backlava on Monday December 30, 2013 @02:24PM (#6986285)
Can you elaborate on this binary search? How do you get a proposed path to feed to your decision problem?
Re:The TSP Isn't NP Complete by ColinWright on Monday December 30, 2013 @02:55PM (#6986502)
Roughly - and possibly with some errors ...

It's not a path that we're feeding to the decision problem. The decision problem is when we have a graph with costs on the edges, and when someone says "Is there a solution of cost less than K?" We're assuming we have a way to answer that, and using that to get a solution to the optimization problem.

We need to use that to find the best possible path. We start by finding the cost of the best possible path. Set k=1 and ask if there's a solution. If not, double K and ask again. Repeat until the answer is "Yes".

Now you know there is a solution with cost in the range [0,K]. Set L=0 and U=K. Now do a binary search. Set K = L + (U-L)/2 and ask if there is a solution of cost K. If not, set L=K, if so then set U=K. Lather, rinse, repeat, until U-L is sufficiently small (1 if using integer weights - more care required otherwise).

Now we know the optimum price. Remove an edge and see if there's still a solution. If there is, there's an optimal path without it. If not, the edge is in the optimal path. Repeat for all edges - some efficiencies can be made.

Re:The TSP Isn't NP Complete by ufo on Monday December 30, 2013 @07:24PM (#6988102)
Removing one edge at a time won't work if there is a second, redundant, optimal path (every edge can be removed without altering the cost). I don't remember how you get around this but it shouldnt be too complicated...
Re:The TSP Isn't NP Complete by ColinWright on Tuesday December 31, 2013 @03:42AM (#6989656)
Sorry, thought that was clear. If you remove an edge and find the cost doesn't change, don't put the edge back - carry on with the smaller graph.
Re:The TSP Isn't NP Complete by habitue on Monday December 30, 2013 @03:03PM (#6986557)
This doesn't get you the path itself, it only gets you the length of the path.

Think of it like this:

the decision version question is: Is there a path of length k that hits all of the cities?

The algorithm just has to answer yes/no, it doesn't have to give you the path itself. So you can use binary search to repeatedly ask whether there is a path with length less than k, and home in on the optimal length. You still don't know what the path is.

We assume it would be difficult for the algorithm to make this determination without having actually discovered the path, but the problem doesn't require that it output any such path.

Edit: This is wrong, ColinWright details how to get the actual path from just knowing the length