Assume I want to minimize the distance traveled between a series of cities:
starting tour: S-1-2-3-4-5-E
optimal tour: S-5-1-2-3-4-E
The tour must start at S
, must end at E
, but can visit the cities in between in any order. In my use case, the number of cities in between S
and E
will be between 1 and 35.
The heuristic I'm currently using is a repeated two-opt (shown in pseudo-javascript):
minStopSequence = ['S', 1, 2, 3, 4, 5, 'E'];
changed = true;
while (changed === true) {
changed = false;
for (i = 1; i < minStopSequence.length - 2; i++) {
for (j = i + 1; j < minStopSequence.length - 1; j++) {
newStopSequence = reverseTheMiddleSection(minStopSequence, i, j);
newSegmentDur = getDuration(newStopSequence);
if (newSegmentDur < minSegmentDur) {
minSegmentDur = newSegmentDur;
minStopSequence = newStopSequence;
changed = true;
}
}
}
}
This often fails at finding the optimal solution (for example, it won't find the optimal tour in the example above). I tried augmenting this with a shift (for each index, for each length, move that segment to the end), but doing so causes 2 problems:
- I repeat some tour possibilities (inefficient)
- I still don't hit optimality, even with tours as small at 5 cities long
I've seen the lin-kernighan-helsgaun algorithm achieves optimality for sizes < 50, and an 'exact' variation works with asynchronous graphs (http://www.researchgate.net/profile/Daniel_Karapetyan/publication/227414913_Lin-Kernighan_heuristic_adaptations_for_the_generalized_traveling_salesman_problem/links/02e7e527676733456d000000.pdf p.11), but am unsure how to adapt it to my use case.
If it is possible to use this heuristic, could you help me figure out how to implement it? If not, what would be the most suitable heuristic that returns optimal results for the smallest problems (say n < 15) and near-optimal for the larger ones?