Traveling Salesman Problem
Traveling Salesman Problem
Traveling Salesman Problem (TSP) deals with finding a minimum cost (or distance
or time) tour for a salesman visiting n cities where
each city is visited exactly once
and the salesman returns to the starting city
Tour: A tour is a complete route through the n cities where no city is visited more
than once
Subtour: A subtour is a round trip that does not pass through all cities
Network representation
of the TSP
1
Traveling Salesman Problem (TSP) (Contd…)
Integer programming formulation of TSP
Suppose TSP consists of n cities i = j = 1,2,…, n.
cij = distance (time or cost) from city i to city j, for i j
cij = M (a large positive number), for i j
1 if the salesman goes from city i to city j
xij
n n 0 otherwise
Min Z cij xij
i 1 j 1
n
s.t. x
i 1
ij 1 for j 1,2, , n (the salesman must arrive at each city once)
x
j 1
ij 1 for i 1,2,, n (the salesman must leave each city once)
uj 0 for j 1, 2, ,n 2
Traveling Salesman Problem (TSP) (Contd…)
Cycle Total Distance (in miles)
1. 1-2-3-4-5-1 79
3
2. 1-2-3-5-4-1 108
29
3. 1-2-4-3-5-1 80 11
4. 1-2-4-5-3-1 105 30
20
2
5. 1-2-5-3-4-1 78
6. 1-2-5-4-3-1 74 8 4
7. 1-3-4-2-5-1 67 => Shortest Tour
13
8. 1-3-2-4-5-1 97 22
9. 1-3-5-2-4-1 96 20
10. 1-3-2-5-4-1 95 16
12. 1-4-3-2-5-1 70 6 5
• Of course, This trial approach can only be used for small problems.
4
Branch and Bound approach for TSP
5
Branch and Bound approach for TSP
Solution Procedure
Step 0: Ignore the subtour elimination constraint from TSP. The resulting problem is an
assignment problem.
Step 1: Solve the associated assignment problem using Hungarian Algorithm.
Step 2: If the optimal solution to the assignment problem provides a tour (i.e. no subtour), then it
is the optimal solution to the TSP and STOP. OTHERWISE (the optimal solution to the
assignment problem yields subtours), go to Step 3 (restrictions are imposed to remove the
subtours).
Step 3: Select a subtour with the smallest number of cities (because it creates the smallest number
of subproblems). Let k be the number of cities in the selected subtour (i1 - i2 -…- ik - i1).
Step 4: Branch into k subproblems (branches). Then for the subproblems P1, P2,…,Pk , set
c i1i2 M
c i2i3 M
c ik i1 M, respectively
Step 5: Solve one of the subproblem. If the solution of the resulting assignment problem provides
a tour it provides an upper bound (minimum tour length). Otherwise, Go to Step 3.
Step 6: Continue the process until all the unexplored subproblems have been fathomed (better
upper bound or subproblem cannot produce a better solution).
Step 7: The optimum tour is the one associated with the best upper bound.
6
Branch and Bound approach for TSP
City 1 0 10 3 6 9
City 2 5 0 5 4 2
City 3 4 9 0 7 8
City 4 7 1 3 0 4
City 5 3 2 6 5 0
7
Ignoring the subtour elimination constraint from TSP: Solve the
resulting Assignment Problem using Hungarian Algorithm
Subproblem P0
Z* = Bound= M
8
Row Reduction
City 1 City 2 City 3 City 4 City 5
City 1 M 7 0 3 6
City 2 3 M 3 2 0
City 3 0 5 M 3 4
City 4 6 0 2 M 3
City 5 1 0 4 3 M
Column Reduction
City 1 City 2 City 3 City 4 City 5
City 1 M 7 0 1 6
City 2 3 M 3 0 0
City 3 0 5 M 1 4
City 4 6 0 2 M 3
City 5 1 0 4 1 M
9
Optimal Solution: x13 x25 x31 x42 x54 1, all other xij = 0, ZA = 15.
This solution has two subtours: 1 – 3 – 1 and 2 – 5 – 4–2. So, this is not optimal
solution to the TSP. 10
Z* = Bound = M P0: ZA = 15
(1-3-1) (2-5-4-2)
x13 = 0 x31 = 0
P1:
P1: ZA = 17
(2-5-2)(1-4-3-1)
x25 = 0 x52= 0
P2:
Branch on Subproblem P1:
Subproblem P2: Subproblem P1 with constraint x25 =0, i.e. Set c25 = M)
Subproblem P2 City 1 City 2 City 3 City 4 City 5
City 1 M 10 M 6 9
City 2 5 M 5 4 M
City 3 4 9 M 7 8
City 4 7 1 3 M 4
City 5 3 2 6 5 M
13
Optimal Solution: x14 x23 x31 x45 x52 1, all other xij = 0, ZA = 21
This solution gives a tour: 1 – 4 – 5 – 2 – 3 – 1. So, this is a feasible solution to the
TSP. Fathomed (feasible solution and update the bound)
Z* = Bound= 21
14
Z* = Bound= 21 P0: ZA = 15
(1-3-1) (2-5-4-2)
x13 = 0 x31 = 0
P1: ZA = 17
(2-5-2)(1-4-3-1)
x25 = 0 x52= 0
P2: ZA = 21 P3:
(1-4-5-2-3-1)
Fathomed
Subproblem P3: Subproblem P1 with constraint x52 =0, i.e. Set c52 = M)
City 1 City 2 City 3 City 4 City 5
City 1 M 10 M 6 9
Subproblem P3
City 2 5 M 5 4 2
City 3 4 9 M 7 8
City 4 7 1 3 M 4
City 5 3 M 6 5 M
15
Optimal Solution: x14 x25 x31 x42 x53 1, all other xij = 0, ZA = 19
This solution gives a tour: 1 – 4 – 2 – 5 –3 – 1. So, this is a feasible solution to the TSP.
Fathomed (Update bound since this is better solution) Z* = Bound= 19 16
P0: ZA = 15
Z* = Bound= 19
(1-3-1) (2-5-4-2)
x13 = 0 x31 = 0
P1: ZA = 17 P4:
(2-5-2)(1-4-3-1)
x25 = 0 x52= 0
P2: ZA = 21 P3: ZA = 19
(1-4-5-2-3-1) (1-4-2-5-3-1)
Fathomed Fathomed
Subproblem P4:
17
Optimal Solution: x13 x25 x34 x42 x51 1, all other xij = 0, Z = 16.
This solution gives a tour: 1 – 3 – 4 – 2 –5 – 1. So, this is a feasible solution to the TSP.
Fathomed (Update bound since this is better solution)
Z* = Bound= 16
18
Optimal
Z* = 16 solution to
P0: ZA = 15
(1-3-1) (2-5-4-2) the TSP
x13 = 0 x31 = 0
P1: ZA = 17 P4: ZA = 16
(2-5-2)(1-4-3-1) (1-3-4-2-5-1)
Fathomed
x25 = 0 x52= 0
P2: ZA = 21 P3: ZA = 19
(1-4-5-2-3-1) (1-4-2-5-3-1)
Fathomed Fathomed