68
The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson [email protected] http:// davidsjohnson.net Seeley Mudd 523, Tuesdays and Fridays

The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson [email protected]

Embed Size (px)

Citation preview

Page 1: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

The Traveling Salesman Problem in Theory & Practice

Lecture 8: Lin-Kernighan and Beyond

11 March 2014

David S. Johnson

[email protected]://davidsjohnson.net

Seeley Mudd 523, Tuesdays and Fridays

Page 2: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Outline

1. k-Opt, k > 3

2. Lin-Kernighan

3. and Beyond….

4. A quick tour of heuristics for the Asymmetric TSP

Page 3: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

4-Opt• Seems to be relatively straightforward to generalize from 3-

opt.

– Just need to now consider possibilities for t7 and t8.

– Can further exploit the Partial Sum Theorem.

– Can consider all possibilities for t5, but need to make sure that t7 breaks up the short cycle (or create a new one).

Page 4: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

t1 t2t3

t4

t4

An alternative View: Maintain the path

Page 5: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

t1 t4t3 t2

An alternative View: Maintain the path

Page 6: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

t1 t2t3t4

An alternative View: Maintain the path, at least eventually…

t5 t6

Page 7: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

t1 t2t4

An alternative View: Maintain the path, at least eventually…

t3 t5 t6t5 t3 t6t2

Page 8: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Double Bridge Move

Cannot be produced by any sequential move.

Best one can be found in O(N2) time.

Page 9: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Best Double Bridge Move in Time O(N2)[Glover, “Finding a best traveling salesman 4-opt move in the same time as a best 2-opt move,” J. Heuristics 2 (1996), 169-179]

Simpler algorithm due to Johnson & McGeoch, 2002

Page 10: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Normal Form for Double Bridge Move

N12 N-1

p

j

i+1 i

j+1

p+1

q

qp+1

C[h,k] = Cost of move that deletes {h,h+1} and {k,k+1} and adds {h,k+1} and {h+1,k}

Smallest index of the first endpoint of a deleted edge

Page 11: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

The Functions to be Computed

• f(p,j) = min {C[p,q] : j < q ≤ N}, 2 ≤ p < j ≤ N.

• g(i,j) = C[i,j] + min {f[p,j] : i < p < j}, 1 ≤ i < j-1 ≤ N-1.

N12 N-1

p

j

i+1i

j+1

p+1

q

q+1

Theorem: The length of the best 2-bridge move ismin {g(i,j): 1 ≤ i < j-1 ≤ N-2.

Question: How is this O(N2)?

There are θ(N2) values of f(p,j) and g(i,j) to compute, and the average ones appears to take time θ(N) to compute.

Page 12: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

The Functions to be Computed

• f(p,j) = min {C[p,q] : j < q ≤ N}, 2 ≤ p < j ≤ N.

• g(i,j) = C[i,j] + min {f[p,j] : i < p < j}, 1 ≤ i < j-1 ≤ N-1.

N12 N-1

p

j

i+1i

j+1

p+1

q

q+1

Observation: The only difference between f(p,j) and f(p,j-1) is the inclusion of C[p,j] in the minimization.

The only difference between g(i,j) and g(i-1,j) is the inclusion of f(i,j) in the minimization.

So the values of each can be computed in constant time per value.

Page 13: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

4-Opt Conclusions• Can be implemented to run in O(N2) per iteration.

• This is likely to be significantly slower than our 3-opt implementation.

• k-opt for k > 4 will be even worse:

– Intermediate solutions can involve a path plus multiple cycles.

– More possibilities for non-sequential moves that must be considered as special cases (triple-bridge moves, etc.),

• Improvement in tours over what 3-opt can produce may not be worth the effort (Shen Lin, private communication).

• Alternative approach: a highly-pruned N-opt approach:

The Lin-Kernighan Algorithm

Page 14: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

The Lin-Kernighan Algorithm[Shen Lin & Brian Kernighan, Bell Labs, 1971]

• Built on top of 3-opt, augmented to allow choices of t5 that create a short cycle, so long as there are legal choices of t6, t7, and t8 that pull things together again.

• After each choice of t6 (or t8 in in the above special case), we invoke a deep-dive “LK-search,” assuming the gain criterion from the Partial Sum Theorem is met.

The source of what follows is [Lin & Kernighan, “An effective heuristic algorithm for the traveling salesman problem,” Operations Research 21 (1973), 498-516] and the original Lin-Kernighan FORTRAN code.

Page 15: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

t1 t2it2i+1

t2i+2

t2i+2

LK Search

Candidates for t2i+1 are the cities on the neighbor list for t2i such that the length of the resulting “one-tree” is less than the length of the shortest tour seen so far.[Note that this is the same criterion as provided by the Partial Sum Theorem.]

We abandon the choice if the edge to be deleted, {t2i+1,t2i+2}, was added to the tour earlier in this search (is not an original tour edge). This limits the depth of the search to N.

Page 16: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

LK Search

t1 t2i+2t2i+1 t2i

Candidates for t2i+1 are the cities on the neighbor list for t2i such that the length of the resulting “one-tree” is less than the length of the shortest tour seen so far.[Note that this is the same criterion as provided by the Partial Sum Theorem.]

We abandon the choice if edge to be deleted, {t2i+1,t2i+2}, was added to the tour earlier (is not an original tour edge). This limits the depth of the search to N.

If adding the edge {t1,t2i+2} to this path yields a new champion tour, save that tour.

As the starting path for the next level of the search, take the shortest path generated by any of the the valid choices for t2i+1.The flips illustrated here are actually performed, and then undone as needed, eventually returning us to our starting point (or the improved tour, if found).

Page 17: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Differences between Algorithm Tested and Lin-Kernighan, as described

• We use pre-computed neighbor lists (k = 20). LK did not similarly restrict t3, t5,

t7, although their code restricted LK search to the 5 nearest neighbors.

• We use don’t-look-bits and queue order. LK cycled through t1 candidates in input order.

• We use randomized Greedy starting tours, whereas LK used random starting tours.

• Lin-Kernighan not only forbids the deletion of a previously-added tour edge. It also forbids addition of a previously deleted edge. We allow this latter possibility.

• Lin-Kernighan also added a search for an improving double-bridge move (one that does not deleted added edges), used only whenever no further standard improving moves could be found. They used an exhaustive search, but even our O(N2) algorithm is unlikely to scale well, so we omit this step.

• Lin-Kernighan used Array tour representation, while we switch to 2-level trees for N > 1,000.

• Lin-Kernighan coded in FORTRAN and ran on memory-constrained machines. The largest instance they could test had 318 cities and was considered “big” in 1971. We used C and modern machines, and go considerably bigger.

Page 18: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Show Movie

Page 19: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Worst-Case Running Time per Iteration(Time to find the next improving move or determine there is

none.)

• O(N) choices for t1.

• Up to 2 choices for t2.

• O(k) choices for t3, each potentially involving a between + a flip.

• Up to 2 choices for t4.

• O(k) choices for t5, each potentially involving a between + a flip.

• Up to 2 choices for t6.

• O(k) choices for t7, each potentially involving a between + a flip.

• Up to 2 choices for t8.

• O(N) levels of LK-search.

• O(k) choices for t2i+1, each potentially involving a flip.

Total = O(N2k4logN) using splay trees.

In practice much smaller because of don’t-look-bits.

In p

ractice

much

smalle

r, since

tour e

dg

es u

sually

go to

near

neig

hb

ors

Further restricted by the locking of edges

Typically much smaller.

Page 20: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

How Many Iterations?• In practice, typically θ(N) on random Euclidean instances for all of 2-opt, 3-

opt, and Lin-Kernighan.

• In theory, what?

• Theorem [Englert, Röglin, & Vöcking, “Worst case and probabilistic analysis of the 2-opt

algorithm for the TSP,” Algorithmica 68 (2014), 190-264]: For any Lp metric, 1 ≤ p ≤ ∞,

and any N ≥ 1, there exists a set of 16N points in the unit square for which 2-opt can take as many as 2N+4 -22 steps.

• One can get similar exponential lower bounds for k-opt, k > 2, if one considers instances not obeying the triangle inequality. [Chandra, Karloff, & Tovey,

“New results on the old k-opt algorithm for the TSP,” SIAM J. Comput., 28 (1999), 1998–2029].

• Note: This is doubly worst-case – not only must one be unfortunate enough to get the bad instance, one must also be unfortunate enough to pick the bad sequence of moves. What about average case, at least on the instances?

• For random Euclidean instances, one of these levels of worst-case can be removed.

Page 21: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Iterations for Random Euclidean Instances

Theorem [Kern, 1989]: With high probability, maximum length of a sequence of improving 2-opt moves is O(N16).

Theorem [Chandra, Karloff, & Tovey, 1999]: The expected length of a maximum sequence of 2-opt moves is O(N10logN) and O(N6logN) for the Manhattan (L1) metric.

Theorem [Englert, Röglin, & Vöcking, 2014]: The expected length of a maximum sequence of 2-opt moves is O(N4+1/3logN) and O(N3.5logN) for the Manhattan metric.

(This latter result extends parametrically to higher dimensions and a variety of other point distributions.)

Page 22: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Removing the Move Sequence from the Picture: PLS-completeness

[Johnson, Papadimitriou, & Yannakakis, “How easy is local search?” J. Comp. Syst. Sci. 37 (1988), 79-100]

Definition: A local search problem L in PLS (polynomial-time local search) consists of

a) A type TL ε {min, max}.

b) A polynomial-time recognizable set DL of instances.

c) For each instance x D𝜖 L, a set FL(x) of solutions that is recognizable in time

polynomial in |x|.

d) For each solution s F𝜖 L(x),

1) a non-negative integer cost cL(s,x), and a

2) a subset N(s,x) ⊆ FL(x), called the neighborhood of x.

e) Three polynomial-time algorithms:

1) AL, which, given x D𝜖 L, produces a standard (starting) solution AL(x) 𝜖 FL(x).

2) BL, which, given x D𝜖 L and s F𝜖 L(x), computes cL(s,x).

3) CL, which, given x D𝜖 L and s F𝜖 L(x), either returns a solution s’ N(s,x)𝜖 with a

better cost (e,g., cL(s’,x) < cL(s,x) if TL = min), or reports truthfully that no such

solution exists, and hence s is locally optimal.

Page 23: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Key Computational Question About a Problem L in PLS:

Is there an algorithm that, given an instance x D𝜖 L, finds a locally optimal

solution s F𝜖 L(x) in time polynomial in |x|?

• True if all sequences of improving moves are polynomially bounded, as they would be, for instance, if all costs are polynomially bounded in |x|. Examples include

– Vertex Cover

– Max Clique

– TSP when all edge lengths are less than some constant

(as in the case of our random Euclidean instance generator, where all coordinates are in [0, 107] and distances are rounded to the nearest integer)

• Also may be true if there is a better heuristic for choosing the next move than the one given by CL(s,x).

• Or if there is some way of finding a locally optimal solution without using a local search algorithm at all.

– As when L is corresponds to the Simplex neighborhood for Linear Programming.

Page 24: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

PLS-ReductionsA reduction from PLS problem L to PLS problem K consists of two polynomial-time computable functions:

1) f, which maps instances of x D𝜖 L to instances f(x) D𝜖 K and

2) g, which maps pairs (x D𝜖 L, s F𝜖 K(f(x))) to solutions g(x,s) F𝜖 L(x),

such that for all x D𝜖 L, if s is a locally optimal solution for instance f(x) of K, then g(x,s) is locally optimal for L.

This notion is transitive, and has all the properties needed to define the concept of PLS-completeness, and yield the following:

Theorem: If we can find locally optimal solutions in polynomial time for any PLS-complete problem, then we can do so for all problems in PLS.

In addition, the running time of the “standard algorithm” for a PLS-complete problem is “typically” exponential, and the problem of determining the output of that algorithm is “typically” NP-hard.

(This is a property of many particular proofs of PLS-completeness, rather than a known consequence of the definitions).

Page 25: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

PLS-Completeness and the TSP

• [Krentel, “Structure in locally optimal solutions,” FOCS 1989, IEEE Computer Society, pp. 216-221]: k-opt is PLS-complete for some k between 1,000 and 10,000.

• [Papadimtriou, “The complexity of the Lin-Kernighan heuristic for the traveling salesman problem,” SIAM J. Comput. 7 (1992), 450-465]. Lin-Kernighan is PLS-complete.

This is for the variant in which, for LK-search, instead of not allowing an added edge to be subsequently deleted, we instead do not allow an edge that has been deleted to be subsequently added back.

Note that under this variant, the LK-search can take as many as θ(N2) steps, as compared to the O(N) bound for the other method.

And recall that both criteria are used in the original Lin-Kernighan paper.

Page 26: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Computational Results, Random Euclidean Instances

N = 103 104 105 106

2-Opt [20] % Excess over HK 4.9 5.0 4.9 4.9

150 Mhz Secs 0.32 3.8 56.7 928

3-Opt [20] % Excess 3.1 3.0 3.0 3.0

150 Mhz Secs 0.38 4.6 66.1 1054

LK [20] % Excess 2.0 2.0 2.0 2.0

150 Mhz Secs 0.77 9.8 151 2650

Time on 3.06 Ghz Intel Core i3 processor at N = 106:

25.4 sec (2-opt), 29.5 sec (3-opt), 61.5 (LK)

Of this, 23.5 sec was for Preprocessing

(input reading + neighbor list construction + initial tour generation)

Page 27: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com
Page 28: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com
Page 29: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com
Page 30: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Beating Lin-Kernighan, Part 1:

Simulated Annealing

[Kirkpatrick, Gelatt, & Vecchi, “Optimization by simulated annealing,” Science 220 (13 May 1983), 671-680]

[Černy, “A thermodynamical approach to the travelling salesman problem: An efficient simulation algorithm,” J. Optimization Theory and Appl. 45 (1985), 41-51]

[Kirkpatrick, “Optimization by simulated annealing: Quantitative studies,” J. Stat. Physics 34 (1984), 976-986]

Based on an analogy: Physical System Optimization ProblemState Feasible SolutionEnergy CostGround State Optimal SolutionRapid Quenching Local OptimizationCareful Annealing Simulated Annealing

Page 31: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com
Page 32: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Theoretical Results

General Theorem [Proved by many]:• If you run long enough, and cool slowly enough• (say letting the temperature be C/log(n), where C

is a constant and n is the number of moves tested so far),

• then, with high probability, you will converge to an optimal solution.

General Drawback: For this to work, “long enough” will exceed the time to perform exhaustive search…

Page 33: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Implementations Details

• Initial temperature so high that most moves are accepted.

• Exponentials are evaluated by lookup from a pre-computed table.

• “Frozen” = No more moves being accepted.

• “At Equilibrium” = Having tried a given fixed number of moves at the current temperature.

• “Lower the temperature” = Multiply it by a fixed constant, say 0.95.

A generic simulated annealing implementation reflecting these principles was developed by DSJ, together with interns Cecilia Aragon, Lyle McGeoch, and Cathy Schevon. We consulted with Scott Kirkpatrick and so that our implementation would reflect his own. It is described in

[Johnson, Aragon, McGeoch, & Schevon, “Optimization by simulated annealing: an experimental evaluation; Part I, Graph Partitioning,” Oper. Res 37 (1989), 865-892] and

[Johnson, Aragon, McGeoch, & Schevon, “Optimization by simulated annealing: an experimental evaluation; Part II, Graph coloring and number partitioning,” Oper. Res 39 (1991), 378-406].

The implementation was adapted to the TSP with Lyle McGeoch. Results are described in

[Johnson & McGeoch, “The traveling salesman problem: A case study in local optimization,” in Local Search in Combinatorial Optimization, Aarts & Lenstra (editors), John-Wiley and Sons, Ltd., 1997, pp. 215-310].

Page 34: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

TSP-Specific DetailsBasic move: 2-opt (as done by Kirkpatrick).Initial tour: Random tour.Starting temperature: set so 97% of moves are accepted.Temperature length = N(N-1), approximately twice the neighborhood size.Temperature reduction factor = 0.95.

Averages over 10 runs.

Times are on a 150 Mhz processor

“Excess” is percent over HK bound

Page 35: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Algorithm Engineering for Simulated Annealing

Neighborhood Pruning (first suggested by [Bonomi & Lutton, 1984]).

• In our version, we only consider moves corresponding to an arbitrary city as t1, one of its tour neighbors as t2, and t3 chosen from the 20 cities on t2’s neighbor list, a total of 20N possibilities..

• This is further restricted as follows. Let c = t1 and let c’ be the tour neighbor of c that is farther away. We only consider candidates c’’ for t3 such that either d(c,c”) ≤ d(c,c’) or the probability of accepting an uphill move of size d(c,c”) – d(c,c’) is greater than 0.01.

• At each temperature, we consider 20αN candidate moves (α ≥ 1 a parameter), so that each potential move has a reasonably probability of being chosen as a candidate.

Low-temperature starts (suggested by Kirkpatrick).

• Start with a Nearest Neighbor tour and a temperature yielding an initial acceptance rate of about 50%. For random Euclidean instances we follow the suggestion of Bonomi and Lutton to use L/√N, where L is the length of our “unit” square.

Page 36: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

For more structured, instances, however, SA2 can beat LK on a time equalized basis.In particular, for dsj1000 from TSPLIB (a clustered Euclidean instance which causes LK by a factor of 5 or more), SA2 has 1.27% excess and time equalized LK gets 1.35%.

Page 37: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

dsj1000

Page 38: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

More Algorithm Engineering: Using 3-opt Moves

Proposed by Kirkpatrick in 1984, but his implementation did not exploit what we now know about fast 3-opt, and so his move set only contained moves where the segment moved was of length 10 or less (a generalization of Or-opt).

• In our version, we consider both 2- and 3-opt moves, choosing 2-opts for the first 10αN candidates at each temperature, and 3-opts for the last 10αN.

• A random 3-opt move is chosen as follows. Choose t1 randomly

from the N possibilities, t2 randomly from the two possibilities, t3

randomly from the (pruned) list of up to 20 possibilities, t4

randomly from the two possibilities, t5 randomly from the 20

possibilities (with up to four retries if the initial choices are

topologically infeasible), and then, if t6 is not topologically

determined, choose it randomly from the two possibilities. This yields a total of at most 3200N possibilities.

Page 39: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com
Page 40: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Other Metaheuristics

• Neural Nets [Hopfield & Tank, 1985]– Hopeless

• DNA computing [Adleman, 1994]– Parallel exhaustive search in a bathtub – does not scale

• Tabu Search [Glover, 1986]– Based on an idea implicit in LK-search - not competitive for

TSP

• Genetic Algorithms [Holland, 1975]– Initial ideas were not competitive, but…

Page 41: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Genetic Algorithm Schema1. Generate an initial population P consisting of a random set of

k solutions.

2. While not yet converged, create a new generation of P as follows.

1) Select k’ distinct one- or two-item subsets of P (the mating strategy)

2) For each one-element subset, perform a random mutation to obtain a new solution.

3) For each two-element subset, perform a randomized crossover operation to obtain a new solution that reflects both parents.

4) Let P’ be the set of solutions generated by (2) and (3).

5) Using a selection strategy, choose k survivors from P∪P’ and replace P by these survivors.

3. Return the best solution in P.Standard “convergence” strategy: Stop if you have run for j generations without improving the best solution.

Standard “selection” strategy: Choose the k best solutions.

Page 42: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

a b u h i q w o p v n m s z x l k e r y d f g j c

Sample Crossover Operation

• Pick a segment S from tour A.

• Delete all the cities in S from tour B (keeping the remaining cities in the same order).

• Insert segment S into what is left of tour B.

If you are skeptical that operations like this can lead to a competitive algorithm, you are right.

A new idea is needed: The “Hybrid Genetic Algorithm”

[Brady, “Optimization strategies gleaned biological evolution,” Nature 317 (1985), 804-806].

q w e r t y u o p a s d f g h j k l z x c v b n mq w e r t y u o p a d f g h j c v b nq w e r t y u o p a d f g h j c v b nq w e r t y u o p a d f g h j c v b n m s z x l k

a b u h i q w o p v n m s z x l k e r y d f g j c

Page 43: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Hybrid Genetic Algorithm Schema

1. Generate an initial population P consisting of a random set of k solutions.

2. Apply a given local optimization algorithm A to each solution s in P, letting the resulting local optimal solution s’ replace s in P.

3. While not yet converged, create a new generation of P as follows.

1) Select k’ distinct one- or two-item subsets of P (the mating strategy)

2) For each one-element subset, perform a random mutation to obtain a new solution.

3) For each two-element subset, perform a randomized crossover operation to obtain a new solution that reflects both parents.

4) Let P’ be the set of solutions generated by (2) and (3), after first applying algorithm A to each.

5) Using a selection strategy, choose k survivors from P∪P’ and replace P by these survivors.

4. Return the best solution in P.

New

Page 44: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Advantages and Disadvantages

+ We can use Lin-Kernighan as the local optimization algorithm. Presumably we will get better tours than for basic Lin-Kernighan.

- For a reasonably population size, we will need to perform lots of LK’s. Is this the most cost-effective way of investing all that extra time?

- We still have the problem of the ad-hoc crossover to contend with.

In 1989, Martin, Otto, & Felten suggested a way to remove both drawbacks. (Their paper was published as [“Large-step Markov chains for the TSP incorporating local search heuristics,” Complex Systems 5 (1991), 299-326].)

Page 45: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Martin, Otto, & Felten’s Approach

• Set population size to 1.

• Only do mutations (no matings).

• For the mutation, perform a random double-bridge 4-opt move.

Note that, although this was originally viewed in the context of genetic algorithms, there is little left that is genetic about it. The common name for this approach (using Lin-Kernighan) is now

– “Iterated Lin-Kernighan” or

– “Chained Lin-Kernighan.”

Page 46: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Advantages of Iterated Lin-Kernighan

• Minimal extra programming needed to turn a local search heuristic into an iterated local search heuristic.

• Preprocessing is amortized (although this is true of multiple-independent-run LK as well).

• After the first run of LK, subsequent ones are all much faster, since they start with all but 8 don’t-look-bits still on.

• The damage done to the tour by just changing 4 edges still turns out to open up significant room for LK to find new improvements.

• Surprisingly good performance.

Page 47: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Random Euclidean Instances

.96

1704

3.06 Ghz Intel Core i3 processor

Page 48: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Random Euclidean Instances

Page 49: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Selected TSPLIB Instances

Except for instance fl3795, ILK(N) is always within 0.05% – 0.25% of optimal.

Page 50: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

TSPLIB Instance fl3795

ILK(N), 20 nearest neighbors: 4.33% excess (1080 seconds, 3.06 Ghz

processor)

ILK(N), 20 quad neighbors: 1.09% excess ( 205 seconds, 3.06 Ghz

processor)* *Average of three runs, one of which found the optimal and a second found optimal + 1.

Page 51: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Random Distance Matrices

Page 52: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Beating Iterated Lin-KernighanChained Lin-Kernighan [Applegate, Cook, & Rohe, “Chained Lin-Kernighan for large traveling salesman problems,” INFORMS J. Comput. 15 (2003), 82-92]

• Broader and deeper search before LK-searches, More selective in choices of double-bridge moves (mixture of greedier choices, random walks, etc.)

Hybrid Genetic Algorithm [Nguyen, Yoshihara, Yamamori, and Yasunaga, “Implementation of an effective hybrid GA for large-scale traveling salesman problems,” IEEE Trans. Syst., Man, Cybernetics B37 (2007), 92-99]

• Genetic algorithm with crossovers + mutations + Lin-Kernighan, and large running times for bigger instances.

Helsgaun’s algorithm [Helsgaun, “An effective implementation of the Lin-Kernighan traveling salesman heuristic,” European J. Oper. Res. 126 (2000), 106-130. Source code available at http://www.dat.ruk.dk/~keld/]

• Different restart mechanism, broader initial search, …

Tour merging [Cook & Seymour, “Tour merging via branch-decomposition,” INFORMS J. Comput. 15 (2003), 233-248]

Page 53: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com
Page 54: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com
Page 55: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Random Distance Matrices

N = 1000 3162 10,000 N = 1000 3162 10,000

% Excess of HK bound Seconds on a 500 Mhz DEC Alpha

Note: Helsgaun’s algorithm is the only heuristic we’ve seen that is not fazed by these instances.

Page 56: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Heuristics for the Asymmetric TSP(a quick tour)

Tour Construction:

• Asymmetric Nearest Neighbor

• Asymmetric Greedy

• Match & Patch (Compute minimum-cost cycle cover, repeatedly patch together the two largest cyles)

• Contract or Patch

• Repeated Assignment

• Zhang’s Algorithm (Truncated Branch & Bound)

Local Optimization:

• Asymmetric 3-Opt

• Iterated 3-Opt

• Kanellakis-Papadimitriou (Mimics Lin-Kernighan, and also uses “best double-bridge move” as a component)

• Helsgaun (Convert to symmetric instance and apply Helsgaun’s algorithm.

Page 57: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Matching-and-Patch

Page 58: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Contract-or-Patch

Once all 2-cycles are removed, proceed as in Match & Patch.

Page 59: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Repeated AssignmentDelete all but one city from each cycle, find new matching, and repeat.

Theorem [Frieze, Galbiati, & Maffioli (1982]: Assuming Δ-Inequality,

RA(I) ≤ log(N)OPT(I).

The union of all the matching edges is a connected graph in which every vertex has equal in- and out-degrees. So there is an Euler tour. If we assume the Δ-Inequality, the Euler tour can be traversed using shortcuts at no extra cost. Each matching is no longer than an optimal tour, again by the triangle inequality. Since each matching involves no more than half the previous number of vertices, we have:

Page 60: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Heuristics for the Asymmetric TSP(a quick tour)

Tour Construction:

• Asymmetric Nearest Neighbor

• Asymmetric Greedy

• Match & Patch (Compute minimum-cost cycle cover, repeatedly patch together the two largest cyles)

• Contract or Patch

• Repeated Assignment

• Zhang’s Algorithm (Truncated Branch & Bound)

Local Optimization:

• Asymmetric 3-Opt (Only 3-opt moves that cause no reversals)

• Iterated Asymmetric 3-Opt

• Kanellakis-Papadimitriou (Mimics Lin-Kernighan, and also uses “best double-bridge move” as a component)

• Helsgaun (Convert to symmetric instance and apply Helsgaun’s algorithm.

Page 61: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Results for Instance Generators of[Cirasella, Johnson, McGeoch, & Zhang, “The asymmetric traveling salesman problem: Algorithms, instance generators, and tests,” ALENEX 2001, Lecture Notes in Computer

Science 2153, Springer, pp. 32-59]

Page 62: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

The Coin Collection Problem

Page 63: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

The Stacker-Crane Problem

Page 64: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

The No-Wait Shop Scheduling Problem

Page 65: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

The Disk Scheduling Problem

Page 66: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

The Shortest Common Superstring Problem

Page 67: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

The Drilling on a Tilted Table Problem

Page 68: The Traveling Salesman Problem in Theory & Practice Lecture 8: Lin-Kernighan and Beyond 11 March 2014 David S. Johnson dstiflerj@gmail.com

Next Time

Optimization Algorithms