exercise 12: implementing the lin-kernighan heuristic for the tsp

21
Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP Markus Reuther Zuse Institute Berlin January 19, 2012 Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 1 / 10

Upload: vuongtram

Post on 30-Jan-2017

227 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Exercise 12: Implementing the Lin-Kernighan heuristicfor the TSP

Markus Reuther

Zuse Institute Berlin

January 19, 2012

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 1 / 10

Page 2: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Outline

1 The Traveling Salesman Problem

2 The Lin-Kernighan heuristic

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 2 / 10

Page 3: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

The Traveling Salesman Problem

Given

Complete undirected graph G = (V ,E )

Metric edge costs ce ≥ 0 for all e ∈ E .

Problem

Find a hamiltionian cycle with minimal cost.

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 3 / 10

Page 4: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Lin-Kernighan (LK)Most famous and best local search approach for the sym. TSP.

Developed by Shen Lin and Brian Kernighan in 1973.

Best exact solver for the TSP is Concorde

(Applegate, Bixby, Chvatal, Cook).

Best LK-Code today: Keld Helsgaun.

Concorde + Code of Helsgaun, 2006: pla85900 solved (world record).(Applegate, Bixby, Chvatal, Cook, Espinoza, Goycoolea, Helsgaun)

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 4 / 10

Page 5: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

k-opts

k-opt neighborhood for tour x : Nk(x) consists of all tours, which can beconstructed from x by deleting and adding k edges.

Observations

Two hamiltionian cycles only differ in k edges (2 ≤ k ≤ n),i.e.: xopt ∈ Nk(x) for every x .

Problem 1: k-optimality in Nk can only be tested in O(nk).

Problem 2: k is unknown.

Approach: Choose an efficient searchable neighborhood such that k canbe choosen dynamically.

⇒ Sequential k-opt moves.

Definition: Sequential k-opt move

A k-opt move is called sequential if it can be described by a pathalternating between deleted and added edges.

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 5 / 10

Page 6: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

k-opts

k-opt neighborhood for tour x : Nk(x) consists of all tours, which can beconstructed from x by deleting and adding k edges.

Observations

Two hamiltionian cycles only differ in k edges (2 ≤ k ≤ n),i.e.: xopt ∈ Nk(x) for every x .

Problem 1: k-optimality in Nk can only be tested in O(nk).

Problem 2: k is unknown.

Approach: Choose an efficient searchable neighborhood such that k canbe choosen dynamically.

⇒ Sequential k-opt moves.

Definition: Sequential k-opt move

A k-opt move is called sequential if it can be described by a pathalternating between deleted and added edges.

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 5 / 10

Page 7: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

k-opts

k-opt neighborhood for tour x : Nk(x) consists of all tours, which can beconstructed from x by deleting and adding k edges.

Observations

Two hamiltionian cycles only differ in k edges (2 ≤ k ≤ n),i.e.: xopt ∈ Nk(x) for every x .

Problem 1: k-optimality in Nk can only be tested in O(nk).

Problem 2: k is unknown.

Approach: Choose an efficient searchable neighborhood such that k canbe choosen dynamically.

⇒ Sequential k-opt moves.

Definition: Sequential k-opt move

A k-opt move is called sequential if it can be described by a pathalternating between deleted and added edges.

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 5 / 10

Page 8: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

k-opts

k-opt neighborhood for tour x : Nk(x) consists of all tours, which can beconstructed from x by deleting and adding k edges.

Observations

Two hamiltionian cycles only differ in k edges (2 ≤ k ≤ n),i.e.: xopt ∈ Nk(x) for every x .

Problem 1: k-optimality in Nk can only be tested in O(nk).

Problem 2: k is unknown.

Approach: Choose an efficient searchable neighborhood such that k canbe choosen dynamically.

⇒ Sequential k-opt moves.

Definition: Sequential k-opt move

A k-opt move is called sequential if it can be described by a pathalternating between deleted and added edges.

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 5 / 10

Page 9: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Example

Sequential 6-opt

Double-Bridge-Move (4-opt)

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 6 / 10

Page 10: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Lin-Kernighan

Flip operations

a

b

a

b

Operation:flip(next(a),prev(b))

Gain gt of flip t:

gt = c(a, next(a)) + c(prev(b), b)− c(next(a), b)− c(a, prev(b))

Lin-Kernighan

Choose a fix starting node a and construct the alternating path by asequence of flip operations of the form flip(next(a), prev(b)).

The goal within this construction is to obtain

k∑i=1

gti > 0.

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 7 / 10

Page 11: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Lin-Kernighan

Flip operations

a

b

a

b

Operation:flip(next(a),prev(b))

Gain gt of flip t:

gt = c(a, next(a)) + c(prev(b), b)− c(next(a), b)− c(a, prev(b))

Lin-Kernighan

Choose a fix starting node a and construct the alternating path by asequence of flip operations of the form flip(next(a), prev(b)).

The goal within this construction is to obtain

k∑i=1

gti > 0.

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 7 / 10

Page 12: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Example

v1

v2

v3v4

v5v6

v7

v8

v9

v10

v12

v11

v1v2 − v8v7 − v4v3 − v10v9 − v12v11 − v6v5−

flip(v2, v4)

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 8 / 10

Page 13: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Example

v1

v2

v3v4

v1v4 − v7v8 − v2v3 − v10v9 − v12v11 − v6v5−

flip(v4, v6)

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 8 / 10

Page 14: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Example

v1

v2

v3v4

v5v6

v1v6 − v11v12 − v9v10 − v3v2 − v8v7 − v4v5−

flip(v6, v8)

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 8 / 10

Page 15: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Example

v1

v2

v3v4

v5v6

v7

v8

v1v8 − v2v3 − v10v9 − v12v11 − v6v7 − v4v5−

flip(v8, v10)

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 8 / 10

Page 16: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Example

v1

v2

v3v4

v5v6

v7

v8

v9

v10

v1v10 − v3v2 − v8v9 − v12v11 − v6v7 − v4v5−

flip(v10, v12)

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 8 / 10

Page 17: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Example

v1

v2

v3v4

v5v6

v7

v8

v9

v10

v11

v12

v1v12 − v9v8 − v2v3 − v10v11 − v6v7 − v4v5−

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 8 / 10

Page 18: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Example

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 8 / 10

Page 19: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Implementation details

Backtracking

NeighborhoodgraphI k-Nearest graphI α-Nearest graphI Delaunay triangulation

Mak-Morton-Moves

alternateStep()

Swaps

Bentley-Marking-Scheme

Kicking-StrategicI Double-Bridge-MovesI . . .

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 9 / 10

Page 20: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Neighborhood graphs for the choice of the edge{a, next(a)}

Figure: Neighborhood graph: 15 nearest neighbors

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 10 / 10

Page 21: Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP

Neighborhood graphs for the choice of the edge{a, next(a)}

Figure: Neighborhood graph: Delaunay triangulation

Markus Reuther (Zuse Institute Berlin) Exercise 12: Implementing the Lin-Kernighan heuristic for the TSP January 19, 2012 10 / 10