TLDR version: Most important issue is, that in a TSP problem, instead of finding the shortest Hamiltonian cycle, what are good ways to find the best path (I suppose the one that visits the most nodes) which is at most X length, with a fixed starting point.
Full version:
I’m interested in some ideas for a problem that involves TSP.
First, an example real-world TSP problem is when you have N geographical locations to visit and you need driving directions for an optimal route (or near-optimal) to visit all, either a roundtrip or A to Z. There is a nice JS implementation for this at http://www.gebweb.net/optimap/ and a JS TSP solver available at http://code.google.com/p/google-maps-tsp-solver/.
Now consider that you have N = 100 – 1000+ locations. At that point you cannot calculate the route with any reasonable amount of time/resources, but even if it were possible that is not that useful for most real world scenarios. Let’s say you pick a fixed starting point and based on that, from those 1000+ locations you want to generate an optimal subroute which fits into a (relatively small) max constraint (for example, a route that can be covered in 1 day or 1 week).
How can this be solved in near real time?
My thoughts sofar:
-
Build the duration matrix from
starting point (this step is
feasible even at a few thousand
points) and pick a small subset of
points which are closest to the
starting point. Ideally this subset
should be large enough, that
visiting it fully is definitely >
max constraint, but small enough to process quickly, at least with
heuristic algorithms. -
Find an optimal route considering
the locations chosen in step 1. But
instead of a route that visits all
points from this set, I need the
best route which satisfies max
constraint thus it should not
visit all points (it can visit
all but that would be the edge
case). I’m especially not sure on
how it would be best to tackle this
one in an efficient way?
Any links, or ideas appreciated, especially for point 2.
Disclaimer: Of course the core of the problem is language-agnostic, I’m using JS/Google Maps as an example of real world application.
OK, here’s my sketch of a solution, in pseudo code. You need to know about Priority Queues
This effectively does a breadth first search of the solution space, in a reasonably memory efficient manner. Moreover, if it is too slow, then when looping over all children you can speed up the algorithm by only taking N nearest neighbors, where N is configurable. You may miss the optimum solution, but it should be reasonable in most cases.