5 traveling salesman problem - schoolit - · pdf file5 traveling salesman problem problem...

67
5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a Hamiltonian cycle of minimum length in a given complete weighted graph G=(V,E) with weights c ij =distance from node i to node j.

Upload: vuongcong

Post on 06-Feb-2018

240 views

Category:

Documents


7 download

TRANSCRIPT

Page 1: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

5 TRAVELING SALESMAN PROBLEM

PROBLEM DEFINITION AND EXAMPLES

TRAVELING SALESMAN PROBLEM, TSP:Find a Hamiltonian cycle of minimum length in a given complete weightedgraph G=(V,E) with weights cij=distance from node i to node j.

Page 2: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Tour = a Hamiltonian cycle, a cycle that includes every vertex exactly once

In graph G = (V,E):

• n=|V|, number of vertices

• The graph may a directed multigraph (two arcs in opposite directionsbetween every pair of nodes) or an undirected graph in which the distancesmay be symmetric: cij = cji, or not: cij cji for some i j.

• If the graph is not complete, set cij = cji = for missing edges i–j orcij = for missing arcs i j (or cij = length of the shortest path from i to j).

• Set cii = , i=1,...,n, or exclude the connection i–i in some other way.

Page 3: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

If the solution gives a total length , a Hamiltonian cycle does not exist inthe given incomplete graph.

The feasible solutions, the Hamiltonian cycles correspond to cyclicpermutations of the vertex set.

Page 4: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Different TSP cases:

1) symmetric TSP: cij = cji for all i,j

2) asymmetric TSP: cij cji for some i j

3) triangle inequality TSP: cik cij + cjk for all i,j,k

4) Euclidean TSP: the distances between vertices are their Euclideandistances.

TSP is NP-complete in all these cases.

If the triangle inequality holds, the shortest closed walk (circuit) through allnodes is a Hamiltonian cycle.

Page 5: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Suppose a minimum length Hamiltonian path starting from a fixed node 1,is to be determined.

This problem can be modeled as the cycle problem by setting ci1 = 0 forall nodes 2,...,n.

Page 6: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

TSP is an important problem, because

• it is often a subproblem of various routing problems

• similar principles of solution can be used in other network and graphproblems.

Page 7: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

EXAMPLES

Example 5.1A multi-function machine can be used to perform n different operations.A changeover or setup cost will occur between operations. Parameters:

cij = changeover or setup cost when operation j is performedimmediately after operation i

If the operation i is- first in the sequence, a setup cost is c0i.- last in the sequence, the machine must be reset to its initial state, inducinga cost ci0.

Page 8: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Example 5.2A number of holes must be drilled to given positions on a metal sheet. Thedrill is at an initial position to which it must be returned after the drilling.The sheets are manufactured as mass production, so it is important todetermine the minimum time drilling sequence.

Page 9: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Example 5.3A wallpaper has a periodic pattern of length 1. Different sheets must be cutin a sequence that minimizes the waste.

ai = starting point of sheet i, 0 ai 1bi = ending point of sheet i, 0 bi 1pi = length of the sheet i

=> bi = ai + pi (mod 1).

If sheet j is cut immediately after sheet i, the waste is

cij = aj – bi if bi aj1 + aj – bi if bi> aj

⇔cij = aj – bi (mod 1)

Page 10: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Starting point of the roll: a0=b0, e.g. a0=0.

The length from the last ending point to a0 is waste.

Define a dummy sheet 0 with a0 = b0 and use the above formula for alli,j=0,1,...,n.

The problem is a (n+1)-node TSP with distances cij.

Remark: This is a polynomially solvable special case of TSP, withcomplexity O(n log n).

Page 11: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

EXACT METHODS FOR THE TSP

BRANCH AND BOUND METHODS

Branch & Bound methods are normally based on some relaxation of theILP model of TSP. The decision variables of the model are

xij = →

notif0jiarcalonggoescycle theif1

In the following optimization models, the variables xii are either excludedfrom the model or prevented by setting cii = .

Page 12: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

ILP model:

min ∑∑= =

n

1i

n

1jijijxc (5.1)

subject to

∑=

=n

1jij 1x for every i=1,...,n (every vertex i has one successor) (5.2)

∑=

=n

1iij 1x for every j=1,...,n (every vertex j has one predecessor) (5.3)

xij = 0 or 1 i,j=1,...,n (5.4)

In addition, subtour elimination constraints(= constraints preventing separate cycles)

Page 13: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Subtour elimination constraints

• Tucker formulation:

ui – uj + nxij n – 1 for every i,j = 2,...,n, i j (5.5)ui ∈ R i=2,...,n

Constraints (5.5) prevent any subtours not containing vertex 1:

– Consider a subtour with vertices i1,...,ik not containing vertex 1.– Write down the constraints (5.5) for the subtour edges i–j having

variable values xij=1.– Sum up these constraints => nk (n-1)k,

which is false.

Page 14: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

• Dantzig-Fulkerson-Johnson formulation:

1xSi Sj

ij ≥∑∑∈ ∈

(5.6)

for subsets S⊂{1,...,n}, 2 |S| n–2

(S = V – S, complement of S)

Constraints (5.6) force a connection (an edge to be used) between everypair of separate subsets.

Page 15: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

An alternative formulation:

1|R|xji

Rj,iij −≤∑

≠∈

(5.7)

for all nonempty subsets R⊂{2,...,n}, |R| 2.

Constraints (5.7) prevents cycles of |R| vertices that do not include node 1(because a cycle of |R| nodes has |R| edges).

The DFJ formulations are impractical for large scale problems, because thenumber of subtour elimination constraints is of order 2n.

Page 16: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

In Branch & Bound methods the lower bound for the length of the cycle isdetermined by an appropriate relaxation, e.g. by discarding the subtourelimination constraints. This results in an assignment problem, and it iscalled an assignment relaxation.

Page 17: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

BRANCH AND BOUND WITH ASSIGNMENT RELAXATION

0. Initialization: Construct an initial feasible tour by some heuristic or use tour... 1 and setfmin:= c12 + c23 + ... + cn1.

1. Solve the assignment relaxation. If the solution is a Hamiltonian cycle, stop:it is the optimum solution.

2. Choose a subtour with the smallest number of nodes, in order i(1), ..., i(k), k<n. In this solution xi(1),i(2) = xi(2),i(3) = ... = xi(k-1),i(k) = xi(k),i(1) = 1.

3. Branching: Define k subproblems by deleting each edge of the subtour in turn,by setting

xi(1),i(2) = 0 (1st subproblem)or xi(2),i(3) = 0 (2nd subproblem)Mor xi(k),i(1) = 0 (kth subproblem)

Page 18: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

4. Choose a subproblem to be solved. Solve the associated assignment problem bysetting cij = for the deleted edge. Denote the solution by x, f.

5. (i) If f<fmin, but subtours exist, go to 2. (ii) Bounding: if f<fmin and the solution has no subtours, update the solution

xmin:=x, fmin:=f . Go to 6. (iii) If f fmin, go to 6.

6. If unsolved subproblems exist, go to 4. Else, stop: the optimum solution is xmin, fmin.

Page 19: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Example 5.4 TSP distance matrix C

i\j 1 2 3 4 512345

0 2 0 6 1 1 0 4 4 2 5 3 0 1 5 4 7 2 0 1 2 6 3 6 0

Initialization: Tour 1 1, fmin = 10.

For the Hungarian method, we first set cii = to force xii=0.

Page 20: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Assignment solution with the Hungarian method:x12 = x21 = x34 = x45 = x53 = 1.

Subtours 1 1 and 3 3, f = 8 < fmin

Branching on subtour 1 1: define subproblems

(1) x12 = 0 set c12 =

(2) x21 = 0 set c21 =

Solution of subproblem (1):

tour 1 1, f = 9 < fmin.

Set fmin := 9 and save the solution xmin.

Page 21: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Solution of subproblem (2):

subtours 1 1 and 3 3, f = 9 = fmin

This lower bound is no better than the incumbent solution. All subproblemsare fathomed.

Optimum solution: 1 1, length fmin = 9.

Page 22: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

B&B with Assignment relaxation:Simple but inefficient because of its bounding technique.The tree of subproblems may become impracticable.

A stricter lower bound:the Lagrangean function for a modified problem and a minimal spanningtree relaxation.

G. Laporte: The Traveling Salesman Problem:An overview of exact and approximate algorithms.European Journal of Operations Research 59 (1992), pp. 231-247.

Page 23: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

DYNAMIC PROGRAMMING

Dynamic programming:• A divide-and-conquer-strategy.• The problem is handled is smaller parts in a sequential way so that smallsubproblems are solved first and their solutions are stored for futurereference.•Larger subproblems are solved by a recursion formula from thesmaller ones.• The next stage is calculated from the previous stage in a bottom-upfashion.• Finally, back-tracking through the table to obtain the complete solution.

Page 24: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Example 5.4

i\j 1 2 3 4 512345

0 2 0 6 1 1 0 4 4 2 5 3 0 1 5 4 7 2 0 1 2 6 3 6 0

Notation:Vertex set V={1,...,n}S = subset of V

g(i,S) = length of a shortest path from vertex i to vertex 1 passing throughevery vertex of S exactly once

Page 25: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Example: If

S = {3}, g(2,S) = c23+c31 = 4+5 = 9

S={3,4}, g(2,S) = min { c23+c34+c41, c24+c43+c31}= min {4+1+4, 4+2+5} = min {9, 11} = 9

Recursion formula:

g(i,S) =Sj

min∈

{cij + g(j, S–{j})}

The minimum value is

fmin =n,...,2j

min=

{c1j + g(j, V–{1,j})}

Page 26: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

DYNAMIC PROGRAMMING ALGORITHM FOR THE TSP

Input: Number of vertices n, n×n matrix C = (cij)

1. For i = 2 to n, set g(i,O/ ) = ci1

2. For k = 1 to n-2 For all subset S ⊆V–{1} containing k vertices For all i ∉ S, i 1

g(i,S) :=Sj

min∈

{cij + g(j, S–{j})}

p(i,S) := value of j that gave the minimum (successor if vertex i in set S)

3. Length of optimum TSP-tour: f := g(1,V–{1}) =

n,...,2jmin=

{c1j + g(j, V–{1,j})}

p(1,V–{1}) := value of j that gave the minimum (successor of vertex 1).

Page 27: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

The array p has n rows for all the vertices and columns for all subsets ofV–{1},

p(i,S) = the first vertex after i on a shortest path from i to 1 that passes through all the vertices of S exactly once

The optimal tour from the array p:

The first vertex after 1: p(1, V–{1}) = kThe second: p(k, V–{1,k})etc.

Complexity = number of operations: T(n) = O(n22n)

Memory used in storing the arrays: M(n) = O(n2n).

Page 28: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

HEURISTICS FOR THE TSP

Notation: fa = length of the tour given by the algorithm fmin = length of the optimal tour

Most of the following heuristics are designed to solve symmetric instancesof TSP, although they can be modified for asymmetric cases.

Let us assume, that the distances• are nonnegative and symmetric• satisfy the triangle inequality.

Without these assumptions, the bound given for the objective functionvalue may not be valid.

Direction of a route is irrelevant Not specified in the following methods.

Page 29: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Many of these methods, e.g. the construction heuristics, start with anarbitrary vertex.

To increase reliability, the procedure can be repeated from several (or all)vertices in turn. The computation time multiplies correspondingly.

Example 5.5 n=5 vertices, distance matrix:

cij 1 2 3 4 51 - 8 4 9 92 8 - 6 7 103 4 6 - 5 64 9 7 5 - 45 9 10 6 4 -

Page 30: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

CONSTRUCTION METHODS

In construction methods, the tour is built up by adding new vertices to apartial tour or path.

A. NEAREST NEIGHBOR METHOD

1. Choose an arbitrary starting node for the tour. This is the initial pathof one node.

2. Find an unconnected node that is closest to the last node of the path.Join this node to the last node.

3. Repeat step 2 until all nodes are joined to the path. Then, join thelast node to the first one.

Page 31: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Evaluation of the solution: fa / fmin 21nlog

21 +

Worst case complexity: T(n) = O(n2)

( x = smallest integer that is x, function ceiling)

Experimental testing on the TSPLIB problems gives an averagefa / fmin 1.26.

Page 32: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Example 5.5(A)

Starting with node 1, the solution is 1-3-4-5-2-1, f = 31

Different solutions result from different starting points.

Page 33: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

B. METHOD OF CLARKE AND WRIGHT= THE SAVINGS ALGORITHM

1. Choose an arbitrary node k (as a center node) for the tour. Thestarting closed walk visits each other node one by one and returns tonode k after each of them.

2. For all pairs of nodes i,j = 1,...,n, such that i k, j k, i j, calculate thesavings for replacing cycles k-i-k and k-j-k by a combined cyclek-i-j-k:

sij = cki + ckj – cij.3. Sort the savings in decreasing order.4. In the order of the savings, modify the current walk by replacing two

edges incident to the center, i-k and k-j with edge i-j.The replacement is not made if i and j already belong to the samesubtour. Repeat until a Hamiltonian cycle is formed.

Page 34: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Evaluation of the solution: fa / fmin = O(log n)Worst case complexity: T(n) = O(n2 log n)

Example 5.5(B)Savings matrix, with center k=3:

sij 1 2 4 51 - 2 0 12 2 - 4 24 0 4 - 75 1 2 7 -

Symmetry: sij = sji (only upper half of the matrix needed)Decreasing order: s45, s24, s12, s25, s15, s14

Page 35: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

1) 2)

3) 4)

Solution: 1-3-5-4-2-1, f = 29

Page 36: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

C. INSERTION METHODS

In insertion methods, the tour is constructed by inserting new nodes tosubtours, i.e. partial tours.

Notation:

T = subtour, partial tour

f = cik + ckj – cij = increase in tour length, when node k inserted between nodes i and j

Distance from node k to subtour T:

d(k,T) =Tj

min∈

ckj

Page 37: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

C1. METHOD OF NEAREST INSERTION

1. Choose an arbitrary node i as a starting node.2. Find a node j closest to i. Form a subtour T = i-j-i.3. Find a node k not in the subtour that is closest to any of the subtour

nodes (that is, for which the minimum distance to the subtour nodesis smallest):

d(k,T) =Ti

min∉

d(i,T)

4. Find an edge i-j of the subtour to insert k, such that the increase oflength f = cik + ckj – cij is minimized. Modify the subtour byinserting k between i and j.

5. Go to 3 until a Hamiltonian cycle is formed.

Evaluation of the solution: fa / fmin 2Worst case complexity: T(n) = O(n2)

Page 38: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Example 5.5(C1)Starting node: i=1.

Closest node: j=3: T= 1-3-1.

Closest node to the subtour:k=4: T = 1-3-4-1

k=5: T = 1-3-4-5-1 (best of three possible insertions)

k=2: Four possibilities. Insertion to1-3: f = c12 + c23 - c13 = 8+6-4 = 103-4: f = c32 + c24 - c34 = 6+7-5 = 8 smallest4-5: f = c42 + c25 – c4 = 7+10-4 = 135-1: f = c52 + c21 – c51 = 1+8-9 = 9

T = 1-3-2-4-5-1, f = 30

Page 39: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

T = 1-3-4-1 T = 1-3-4-5-1

Solution: T = 1-3-2-4-5-1, f =30

Page 40: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

C2. METHOD OF CHEAPEST INSERTION

1. Choose an arbitrary node i as a starting node.2. Find a node j closest to i. Form a subtour T = i-j-i.3. Find an edge i-j of the subtour and a node k not in the subtour,

such that the increase of length f = cik + ckj – cij is minimized.Modify the subtour by inserting k between i and j.

4. Go to 3 until a Hamiltonian cycle is formed.

Evaluation of the solution: fa / fmin 2Worst case complexity: T(n) = O(n2 log n)

Page 41: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Example 5.5(C2)• Starting node i=1. Closest node j=3: T= 1-3-1.• Edge 1-3 (or 3-1), insert node2: f = c12 + c23 - c13 = 8+6-4 = 10 smallest4: f = c14 + c43 - c13 = 9+5-3 = 115: f = c15 + c53 - c13 = 9+6-3 = 12k=2: T = 1-2-3-1• Three edges, two unattached nodes: six possibilitiesEdge 1-2, insert node 4: f = c14 + c42 - c12 = 9+7-8 = 8Edge 1-2, insert node 5: f = c15 + c52 - c12 = 9+10-8 = 11Edge 2-3, insert node 4: f = c24 + c43 - c23 = 7+5-6 = 6 smallestEdge 2-3, insert node 5: f = c25 + c53 - c23 = 10+6-6 = 10Edge 3-1, insert node 4: f = c34 + c41 - c31 = 5+9-4 = 10Edge 3-1, insert node 5: f = c35 + c51 - c31 = 6+9-4 = 11k=4: T = 1-2-4-3-1• Last node 5: Compare all possible insertions optimal insertion to 4-3.k=5: T = 1-2-4-5-3-1, f = 29

Page 42: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

T = 1-2-3-1 T = 1-2-3-4-1

Solution T = 1-2-4-5-3-1, f = 29

Page 43: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

C3. METHOD OF FARTHEST INSERTION

1. Choose an arbitrary node i as a starting node.2. Find the farthest node from i, i.e. the node j for which distance cij is

longest. Form a subtour T = i-j-i.3. Find a node k not in the subtour that is farthest from the subtour, i.e.

d(k,T) =Ti

max∉

d(i,T)

4. Find an edge i-j of the subtour to which the insertion of k gives thesmallest increase of length, i.e. for which f = cik + ckj – cij issmallest (as in the nearest insertion method).Modify the subtour by inserting k between i and j.

5. Go to 3 until a Hamiltonian cycle is formed.

Reminder: distance from node i to subtour T was defined asd(i,T) =

Tjmin

∈ cij

Page 44: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Evaluation of the solution: fa / fmin 1nlog +Worst case complexity: T(n) = O(n2)

According to experimental results, the Farthest Insertion Method usuallygives a better average function value than nearest and cheapest insertion,although it is unknown whether the f-ratio has a constant upper bound.

Page 45: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Example 5.5(C3)• Starting node i=1.Farthest node j=4: T= 1-4-1.

• Distance to T from node2: d(2,T) = c24 = 7 largest3: d(3,T) = c31 = 45: d(5,T) = c54 = 4k=2: T = 1-2-4-1

• Distance to T from node3: d(3,T) = c31 = 45: d(5,T) = c54 = 4 (equal)k=3: T = 1-2-4-3-1, because f smallest when 3 inserted to 4-1.

• Last node 5: optimal insertion to 4-3.k=5: T = 1-2-4-5-3-1, f=29

Page 46: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

T = 1-3-4-1 T = 1-2-4-1

T = 1-2-4-3-1 Solution: T = 1-2-4-5-3-1, f = 29

Page 47: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

OTHER INSERTION METHODS:Quick insertion or Nearest additionArbitrary insertionConvex hull insertionGreatest angle insertion

For all mentioned insertion methods,

fa / fmin 1nlog +

Experimentally, no instances found with fa / fmin > 4.

Page 48: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

D. MINIMUM SPANNING TREE METHOD

In this algorithm an Eulerian cycle (actually circuit) is formed in a multi-graph where the edges of a minimum spanning tree are doubled during thealgorithm.

1. Construct the minimum spanning tree for the weighted graph G.2. Choose a leaf node i0 (i.e. node of degree 1). Set i:=io.3. If an untraversed edge i-j incident to i exists, go from i to j

(edge i-j is added to the path). Set i:=j and repeat step 3.If all edges from i are traversed, return to the first predecessor of i,be it node k. If k=io (the starting node), an Eulerian cycle is formed:go to 4.Else, set i:=k and repeat step 3.

4. Form a Hamiltonian cycle using shortcuts: traverse the Euleriancycle by skipping every node already visited.

Page 49: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Evaluation of the solution: fa / fmin 2Worst case complexity: T(n) = O(n2)

Example 5.5(D)

Minimum spanning tree: Eulerian cycle:

Page 50: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Construction of the Eulerian cycle:Choose io = 1.1-3, i=33-2, i=2Return to k=3 using 2-3, i=33-4, i=44-5, i=5Return to k=4 using 5-4, i=4Return to k=3 using 4-3, i=3Return to k=1 using 3-1, i=1=io.Eulerian cycle: 1-3-2-3-4-5-4-3-1.

Page 51: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Eulerian cycle: 1-3-2-3-4-5-4-3-1.

Hamiltonian cycle with shortcuts: 1-3-2-4-5-1, f = 30

Page 52: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

E. METHOD OF CHRISTOFIDES

1. Construct the minimum spanning tree T for the weighted graph G.2. Identify the nodes with odd degree.

Construct a minimum weight perfect matching for these nodes.Append the edges of the matching to the minimum spanning tree.Every node has an even degree.Generate an Eulerian cycle in this graph.

3. Form a Hamiltonian cycle using shortcuts as in the previous method.

Page 53: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Evaluation of the solution: fa / fmin 1.5

Best worst case bound among nonexact methods!

Experimental testing on the TSPLIB problems gives an averagefa / fmin 1.14.

Worst case complexity: T(n) = O(n3)

A minimum weight perfect matching in a complete graph of n vertices canbe found in time O(n3). Some edges may double when appending thematching edges to the tree.

Page 54: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Example 5.5(E)

Start with the minimum spanning tree given in the previous example:

Nodes with odd degree: 1,2,3,5Perfect matchings in the set {1,2,3,5}:1-2, 3-5, weight 14 smallest1-3, 2-5, weight 14 smallest1-5, 2-3, weight 15

Page 55: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Add edges 1-2, 3-5 of the minimum weight matching to the spanning tree:

Eulerian cycle: 1-2-3-4-5-3-1Hamiltonian cycle using shortcuts: solution 1-2-3-4-5-1, f = 32

Page 56: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

F. MERGING METHODS

METHOD OF NEAREST MERGERStart with n one-node subtours.Find two cycles with minimum distance and merge them into one cycle inan optimal way. Continue until you get one cycle.

Evaluation of the solution: fa / fmin 2Worst case complexity: T(n) = O(n2)

ASSIGNMENT-BASED MERGING starts with a solution of theassignment relaxation. If separate subtours exist, two largest subtours aremerged like in the previous method. This method is suitable mainly forasymmetric TSP.

Page 57: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

IMPROVEMENT METHODS

Improvement methods start with a complete tour and try to improve itgradually. Many improvement methods use local search or neighborhoodsearch.

DefineS = set of feasible solutionsN(x) = neighborhood of x, a set of neighboring solutions of x

The definition of a neighborhood depends on the problem and it has often astrong effect on the quality of the solution.

Page 58: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

LOCAL SEARCH = NEIGHBORHOOD SEARCH, a generic algorithm

1. Generate a feasible solution x.

2. Generate an unexamined neighbor y of x: S)x(Ny ∩∈

3. If f(y) < f(x), set x:=y.

4. Stop, if all neighbors of x are examined without improvement:x is a locally optimal solution.

Else, go to 2.

Page 59: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Definition 5.1

a) Operation k-change means deleting k edges from a tour and replacingthem with k edges such that the result is a Hamiltonian cycle.

b) A k-neighborhood of a TSP-solution (Hamiltonian cycle) x is the set ofHamiltonian cycles that result from x with a k-change.

c) TSP tour (Hamiltonian cycle) is k-optimal, if it cannot be improved withany k-change.

We can say that any k-optimal solution is a locally optimal solution of theTSP with respect to the k-neighborhood.

Page 60: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Example of a 2-change: The edges marked with broken line to be changed:

1 – 2 – 3 – 4 – 5 – 1 1 – 3 – 2 – 4 – 5 – 1

In the directed Hamiltonian cycle, some of the old edges change directionafter the k-change.

Page 61: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

ALGORITHM k-OPT:

1. Construct a Hamiltonian cycle x.2. Execute a k-change, resulting in cycle y.3. If f(y) < f(x), set x:=y.4. Go to 2 until a local optimum is obtained.

This is a typical local search for TSP.In step 1, a construction method or random choice can be applied.

Page 62: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Example 5.5(k-OPT) Algorithm 2-Opt

Starting cycle: T = 1-2-3-4-5-1, f = 32

Possibilities for a 2-change:Edges to be changed Result1-2, 3-4 1-3-2-4-5-1 f=30 < 321-2, 4-5 1-4-3-2-5-1 f=392-3, 4-5 1-2-4-3-5-1 f=352-3, 5-1 1-2-5-4-3-1 f=313-4, 5-1 1-2-3-5-4-1 f=33

Page 63: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

The first change improves the solution, the others need not be calculated.

T = 1-3-2-4-5-1

Edges to be changed Result1-3, 2-4 1-2-3-4-5-1 f = 321-3, 4-5 1-4-2-3-5-1 f = 373-2, 4-5 1-3-4-2-5-1 f = 353-2, 5-1 1-3-5-4-2-1 f = 29 < 30 improvement!(2-4, 5-1 1-3-2-5-4-1 f = 33, not needed)

Page 64: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Change of 3-2 and 5-1 result in T = 1-3-5-4-2-1f = 29

Checking all possible 2-changes no improvement.

Solution T = 1-3-5-4-2-1 (or T=1-2-4-5-3-1 because of symmetry) f = 29,which is optimum.

Page 65: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

Typically small values of parameter k are used: k=2 or k=3.Then the change is relatively easy to perform and the neighborhood issmall.

Prosedure 3-Opt takes about n times as long as the 2-Opt prosedure.

The algorithm can be repeated from different randomly generated startingsolutions to improve the solution.

When k is increased, the number of iterations increases but the solutionimproves.

It has been shown experimentally that values of k>3 don't give furtheradvantage to the quality of the solution. Best results are gained with met-hods where the value of k is dynamically changed.

Page 66: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

COMPOSITE k-OPT HEURISTIC1. Construct a Hamiltonian cycle x.2. Apply 2-Opt algorithm to x, resulting solution y.3. Apply 3-Opt algorithm to y.

Modifications:• Repeat the composite procedure with varying construction methods.Random generation is recommended because it tends to cover the solutionspace more evenly.• Repeat the construction step 1 from several starting vertex. Apply steps2 – 3 to the best initial solution.

Page 67: 5 TRAVELING SALESMAN PROBLEM - Schoolit -  · PDF file5 TRAVELING SALESMAN PROBLEM PROBLEM DEFINITION AND EXAMPLES TRAVELING SALESMAN PROBLEM, TSP: Find a

LIN-KERNIGHAN HEURISTIC• based on k-Opt algorithm• k = 2 or 3, changed adaptively

Very powerful method.Different versions of the Lin-Kernighan-methods exist, and they give good,"near-optimal" results on empirical tests. The method is more complicatedto code than the simple k-Opt.

Source:http://www.research.att.com/~dsj/papers/TSPchapter.pdf

Several other heuristics are available for the TSP. Some special methodsare introduced in the last chapter:- Genetic Algorithms- Simulated Annealing- Tabu Search