Course
Year
: T0034 Algorithm Design & Analysis
: 2013
Session 15
Dynamic Programming:
Multistage Graph Problem
MULTISTAGE GRAPH
Multistage Graph is a graph with special characteristics:
1.
2.
3.
4.
5.
6.
7.
Directed Graph
Each edge has weight
Has only 1 source (called as s) and 1 sink (called as t)
Path from source to sink consists some stages V1 to Vk
All stages connect node in Vi to node Vi+1 where 1 i k
There are k stages, where k 2
Each path from s to t is consequence of choice k-2.
Multistage Graph is a modeling that can be used to solve
some real problems.
Example: choosing project to get maximum profit; including
selecting steps to perform each task.
Bina Nusantara
MULTISTAGE GRAPH PROBLEM
Multistage Graph Problem :
Sortest path finding problem from source to sink in Multistage Graph.
The problem is one of good implementation of Dynamic Programming.
Bina Nusantara
DP IN MULTISTAGE GRAPH PROBLEM
Solving of Multistage Graph problem using
Dynamic Programming in shortest path from a
node to another is a shortest path of previous
stage added by distance of one of an edge
connects to a stage.
Forward Method
Calculate distance to front (to sink)
Backward Method
Calculate distance to back (from source)
Bina Nusantara
FORWARD METHOD
Analysis by calculating path from a node to sink
Formula: cost(i,j) = min{c(j,k) + cost(i+1,k)}
Calculation starts from nodes in stage k-2
cost(i,j) is distance of path from node j in stage i
to sink(t)
c(j,l) is distance of path from node j to node l
Bina Nusantara
FORWARD METHOD
cost(4,I)
cost(4,J)
cost(4,K)
cost(3,F)
cost(3,F)
cost(3,G)
cost(3,G)
cost(3,H)
cost(3,H)
cost(2,B)
cost(2,B)
cost(2,C)
cost(2,C)
cost(2,D)
cost(2,D)
cost(2,E)
cost(2,E)
cost(1,A)
cost(1,A)
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
c(I,L) = 7
c(J,L) = 8
c(K,L) = 11
min { c(F,I) + cost(4,I) | c(F,J) +
min { 12 + 7 | 9 + 8 } = 17
min { c(G,I) + cost(4,I) | c(G,J) +
min { 5 + 7 | 7 + 8 } = 12
min { c(H,J) + cost(4,J) | c(H,K) +
min { 10 + 8 | 8 + 11 } = 18
min { c(B,F) + cost(3,F) | c(B,G) +
min { 4 + 17 | 8 + 12 | 11 + 18
min { c(C,F) + cost(3,F) | c(C,G) +
min { 10 + 17 | 3 + 12 } = 15
min { c(D,H) + cost(3,H) }
min { 9 + 18 }
=
27
min { c(E,G) + cost(3,G) | c(E,H) +
min { 6 + 12 | 12 + 18 } = 18
min { c(A,B) + cost(2,B) | c(A,C) +
min { 7 + 20 | 6 + 15 | 5 + 27
Shortest path is A-C-G-I-L with distance 21
Bina Nusantara
cost(4,J) }
cost(4,J) }
cost(4,K) }
cost(3,G) | c(B,H) + cost(3,H) }
}
=
20
cost(3,G) }
cost(3,H) }
cost(2,C) | c(A,D) + cost(2,D) | c(A,E) + cost(2,E) }
| 9 + 18 } = 21
BACKWARD METHOD
Analysis by calculating path from source to a
node
Formula: bcost(i,j) = min{bcost(i1,l) + c(l,j)}
Calculation starts from nodes in stage 3
bcost(i,j) is distance of path backward from source
(s) to node j in stage i
c(j,l) is distance of path from node j to node l
Bina Nusantara
METODE BACKWARD
bcost(2,B)
bcost(2,C)
bcost(2,D)
bcost(2,E)
bcost(3,F)
bcost(3,F)
bcost(3,G)
bcost(3,G)
bcost(3,H)
bcost(3,H)
bcost(4,I)
bcost(4,I)
bcost(4,J)
bcost(4,J)
bcost(4,K)
bcost(4,K)
bcost(5,L)
bcost(5,L)
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
c(A,B) = 7
c(A,C) = 6
c(A,D) = 5
c(A,E) = 9.
min { c(B,F) + bcost(2,B) | c(C,F) + bcost(2,C)
min { 4 + 7 | 10 + 6 } = 11
min { c(B,G) + bcost(2,B) | c(C,G) + bcost(2,C)
min { 8 + 7 | 3 + 6 | 6 + 9 } = 9
min { c(B,H) + bcost(2,B) | c(D,H) + bcost(2,D)
min { 11 + 7 | 9 + 5 | 12 + 9 } = 14
min { c(F,I) + bcost(3,F) | c(G,I) + bcost(3,G)
min { 12 + 11 | 5 + 9 } = 14
min { c(F,J) + bcost(3,F) | c(G,J) + bcost(3,G)
min { 9 + 11 | 7 + 9 | 10 + 14 } = 16
min { c(H,K) + cost(3,H) }
min { 8 + 14 } = 22
min { c(I,L) + bcost(4,I) | c(J,L) + bcost(4,J)
min { 7 + 14 | 8 + 16 | 11 + 22 } = 21
Shortest path is A-C-G-I-L with distance 21
Bina Nusantara
}
| c(E,G) + bcost(2,E) }
| c(E,H) + bcost(2,E) }
}
| c(H,J) + bcost(3,H) }
| c(K,L) + bcost(4,K) }
SHORTEST PATH IN MULTISTAGE GRAPH
Bina Nusantara
EXERCISE
Find shortest path from node A to node L using
Dynamic Programming (forward method and
backward method) !
Bina Nusantara
REVIEW
MULTISTAGE GRAPH
MULTISTAGE GRAPH PROBLEM
DINAMIC PROGRAMMING IN MULTISTAGE
GRAPH
FORWARD METHOD AND BACKWARD METHOD
Bina Nusantara
Books References
References:
Computer Algorithms / C++
Ellis Horowitz, Sartaj Sahni, Sanguthevar Rajasekaran.
Computer Science Press. (1998)
Introduction to Algorithms
Thomas H Cormen, Charles E Leiserson, Ronald L.
3nd Edition. The MIT Press. New York. (2009)
Algoritma Itu Mudah
Robert Setiadi.
PT Prima Infosarana Media, Kelompok Gramedia.
Jakarta. (2008)
Bina Nusantara
END
Bina Nusantara