PPT6 - Dynamic Programming Multistage Graph & Travelling Salesman Problem
PPT6 - Dynamic Programming Multistage Graph & Travelling Salesman Problem
Week 6
Session 10
Dynamic Programming: Multistage Graph
and Travelling Salesman Problem
The General Objectives
Multistage Graph
Understand the concept of Multistage Graph solution using
Dynamic Programming
2
Outline
Multistage Graph
Multistage Graph Problem
Forward Technique
Backward Technique
3
COMP6127 - Algorithm Design and Analysis
MULTISTAGE GRAPH
Dynamic Programming:
Multistage Graph
5
Dynamic Programming:
Multistage Graph Problem
6
Dynamic Programming:
Multistage Graph Problem
Forward Method
Calculate distance to front (to sink)
Backward Method
Calculate distance to back (from source)
7
Dynamic Programming:
Forward Method
8
Dynamic Programming:
Forward Method
cost(4,I) = c(I,L) = 7
cost(4,J) = c(J,L) = 8
cost(4,K) = c(K,L) = 11
cost(3,F) = min { c(F,I) + cost(4,I) | c(F,J) + cost(4,J) }
cost(3,F) = min { 12 + 7 | 9 + 8 } = 17
cost(3,G) = min { c(G,I) + cost(4,I) | c(G,J) + cost(4,J) }
cost(3,G) = min { 5 + 7 | 7 + 8 } = 12
cost(3,H) = min { c(H,J) + cost(4,J) | c(H,K) + cost(4,K) }
cost(3,H) = min { 10 + 8 | 8 + 11 } = 18
cost(2,B) = min { c(B,F) + cost(3,F) | c(B,G) + cost(3,G) | c(B,H) + cost(3,H) }
cost(2,B) = min { 4 + 17 | 8 + 12 | 11 + 18 } = 20
cost(2,C) = min { c(C,F) + cost(3,F) | c(C,G) + cost(3,G) }
cost(2,C) = min { 10 + 17 | 3 + 12 } = 15
cost(2,D) = min { c(D,H) + cost(3,H) }
cost(2,D) = min { 9 + 18 } = 27
cost(2,E) = min { c(E,G) + cost(3,G) | c(E,H) + cost(3,H) }
cost(2,E) = min { 6 + 12 | 12 + 18 } = 18
cost(1,A) = min { c(A,B) + cost(2,B) | c(A,C) + cost(2,C) | c(A,D) + cost(2,D) | c(A,E) + cost(2,E) }
cost(1,A) = min { 7 + 20 | 6 + 15 | 5 + 27 | 9 + 18 } = 21
9
Dynamic Programming:
Backward Method
10
Dynamic Programming:
Backward Method
bcost(2,B) = c(A,B) = 7
bcost(2,C) = c(A,C) = 6
bcost(2,D) = c(A,D) = 5
bcost(2,E) = c(A,E) = 9.
bcost(3,F) = min { c(B,F) + bcost(2,B) | c(C,F) + bcost(2,C) }
bcost(3,F) = min { 4 + 7 | 10 + 6 } = 11
bcost(3,G) = min { c(B,G) + bcost(2,B) | c(C,G) + bcost(2,C) | c(E,G) + bcost(2,E) }
bcost(3,G) = min { 8 + 7 | 3 + 6 | 6 + 9 } = 9
bcost(3,H) = min { c(B,H) + bcost(2,B) | c(D,H) + bcost(2,D) | c(E,H) + bcost(2,E) }
bcost(3,H) = min { 11 + 7 | 9 + 5 | 12 + 9 } = 14
bcost(4,I) = min { c(F,I) + bcost(3,F) | c(G,I) + bcost(3,G) }
bcost(4,I) = min { 12 + 11 | 5 + 9 } = 14
bcost(4,J) = min { c(F,J) + bcost(3,F) | c(G,J) + bcost(3,G) | c(H,J) + bcost(3,H) }
bcost(4,J) = min { 9 + 11 | 7 + 9 | 10 + 14 } = 16
bcost(4,K) = min { c(H,K) + bcost(3,H) }
bcost(4,K) = min { 8 + 14 } = 22
bcost(5,L) = min { c(I,L) + bcost(4,I) | c(J,L) + bcost(4,J) | c(K,L) + bcost(4,K) }
bcost(5,L) = min { 7 + 14 | 8 + 16 | 11 + 22 } = 21
11
Dynamic Programming:
Shortest Path in Multistage Graph
12
Exercise
1. Find shortest path from node A to node L using Dynamic
Programming (forward method and backward method) !
13
COMP6127 - Algorithm Design and Analysis
15
Dynamic Programming:
Implementation of TSP
16
Dynamic Programming:
TSP - Case
17
Dynamic Programming:
Representation of TSP
18
Dynamic Programming:
Formula of TSP with DP
p(i,L) = min[c(j,i) + p(j,L–{j})]
Then, the shortest path for the graph is p(A,{B,C,D}) that means distance
of path from intial node A after going through node B, C, D by any
sequences (found the shortest path).
19
Dynamic Programming:
Calculation of TSP
p(B,Ø)=c(A,B)=12
p(C,Ø)=c(A,C)=11
p(D,Ø)=c(A,D)=16
p(B,{C})=c(C,B)+p(C,Ø)=25
p(B,{D})=c(D,B)+p(D,Ø)=27
p(C,{B})=c(B,C)+p(B,Ø)=29
p(C,{D})=c(D,C)+p(D,Ø)=33
p(D,{B})=c(B,D)+p(B,Ø)=22
p(D,{C})=c(C,D)+p(C,Ø)=29
p(B,{C,D})= min[c(C,B)+p(C,{D})|c(D,B)+p(D,{C})]
= min[14+33|11+29] = 40
p(C,{B,D})= min[c(B,C)+p(B,{D})|c(D,C)+p(D,{B})]
= min[15+27|17+22] = 39
p(D,{B,C})= min[c(B,D)+p(B,{C})|c(C,D)+p(C,{B})]
= min[10+25|18+27] = 35
p(A,{B,C,D})= min[c(B,A)+p(B,{C,D}) | c(C,A)+p(C,{B,D}) | c(D,A)+p(D,{B,C})]
= min[15+40|8+39|9+35]
= 44
•Distance of the shortest path = 44
20
Dynamic Programming:
Calculation of TSP
p(B,Ø)=c(A,B)=12
p(C,Ø)=c(A,C)=11
p(D,Ø)=c(A,D)=16
p(B,{C})=c(C,B)+p(C,Ø)=25
p(B,{D})=c(D,B)+p(D,Ø)=27
p(C,{B})=c(B,C)+p(B,Ø)=29
p(C,{D})=c(D,C)+p(D,Ø)=33
p(D,{B})=c(B,D)+p(B,Ø)=22
p(D,{C})=c(C,D)+p(C,Ø)=29
p(B,{C,D})= min[c(C,B)+p(C,{D}) | c(D,B)+p(D,{C})]
= min[14+33 | 11+29] = 40
p(C,{B,D})= min[c(B,C)+p(B,{D}) | c(D,C)+p(D,{B})]
= min[15+27 | 17+22] = 39
p(D,{B,C})= min[c(B,D)+p(B,{C}) | c(C,D)+p(C,{B})]
= min[10+25 | 18+27] = 35
p(A,{B,C,D})= min[c(B,A)+p(B,{C,D}) | c(C,A)+p(C,{B,D}) | c(D,A)+p(D,{B,C})]
= min[15+40 | 8+39 | 9+35]
= 44
•Distance of the shortest path = 44
21
Exercise
1. Given a Cost Matrix of TSP as:
17 8 12
10 15 11 14
8 16 9 10
12 19 10 13
15 7 19
22
Thank You