View
225
Download
0
Category
Preview:
Citation preview
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 1/14
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 2/14
Session 15
Dynamic Programming:Multistage Graph Problem
Course : T0034 !lgorithm Design " !nalysis
#ear : $013
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 3/14
Bina Nusantara
MULTISTAGE GRAPH
% Multistage Graph is a graph &ith special characteristics:1' Directe( Graph
$' )ach e(ge has &eight
3' *as only 1 source +calle( as s, an( 1 sin- +calle( as t,
4' Path .rom source to sin- consists some stages /1 to /-
5' !ll stages connect no(e in /i to no(e /i01 &here 1 i -
2' There are - stages &here - $
' )ach path .rom s to t is conse6uence o. choice -7$'
% Multistage Graph is a mo(eling that can be use( to sol8esome real problems' )9ample: choosing proect to get ma9imum pro.it; inclu(ing
selecting steps to per.orm each tas-'
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 4/14
Bina Nusantara
MULTISTAGE GRAPH PROBLEM
% Multistage Graph Problem :
Sortest path .in(ing problem .rom source to sin- in Multistage Graph'
The problem is one o. goo( implementation o. Dynamic Programming'
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 5/14
Bina Nusantara
DP IN MULTISTAGE GRAPH PROBLEM
% Sol8ing o. Multistage Graph problem usingDynamic Programming in shortest path .rom ano(e to another is a shortest path o. pre8ious
stage a((e( by (istance o. one o. an e(geconnects to a stage'
% <or&ar( Metho( Calculate (istance to .ront +to sin-,
% =ac-&ar( Metho(
Calculate (istance to bac- +.rom source,
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 6/14
Bina Nusantara
FORWARD METHOD
% !nalysis by calculating path .rom a node to sink
% <ormula: cost(i,j) = min{c(j,k) + cost(i+1,k)}
% Calculation starts .rom no(es in stage -7$% cost+i, is (istance o. path .rom node in stage i
to sin-+t,
% c+l, is (istance o. path .rom node to node l
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 7/14Bina Nusantara
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 { 1 + 8 | 8 + 11 } = 18
cost(2,!) = min { c(!,F) + cost(3,F) | c(!,G) + cost(3,G) | c(!,H) + cost(3,H) }
cost(2,!) = min { 4 + 17 | 8 + 12 | 11 + 18 } = 2cost(2,") = min { c(",F) + cost(3,F) | c(",G) + cost(3,G) }
cost(2,") = min { 1 + 17 | 3 + 12 } = 15
cost(2,#) = min { c(#,H) + cost(3,H) }
cost(2,#) = min { 9 + 18 } = 27
cost(2,$) = min { c($,G) + cost(3,G) | c($,H) + cost(3,H) }
cost(2,$) = min { % + 12 | 12 + 18 } = 18
cost(1,&) = min { c(&,!) + cost(2,!) | c(&,") + cost(2,") | c(&,#) + cost(2,#) | c(&,$) + cost(2,$) }
cost(1,&) = min { 7 + 2 | % + 15 | 5 + 27 | 9 + 18 } = 21
'ot*st t is &-"-G-I-L .it /istnc* 21
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 8/14Bina Nusantara
BACKWARD METHOD
% !nalysis by calculating path .rom source to a
node
% <ormula: bcost(i,j) = min{bcost(i–1,l) + c(l,j)}
% Calculation starts .rom no(es in stage 3
% bcost+i, is (istance o. path backward .rom source
+s, to node in stage i
% c+l, is (istance o. path .rom node to node l
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 9/14Bina Nusantara
METODE BACKWARD
0cost(2,!) = c(&,!) = 7
0cost(2,") = c(&,") = %
0cost(2,#) = c(&,#) = 5
0cost(2,$) = c(&,$) = 9
0cost(3,F) = min { c(!,F) + 0cost(2,!) | c(",F) + 0cost(2,") }
0cost(3,F) = min { 4 + 7 | 1 + % } = 11
0cost(3,G) = min { c(!,G) + 0cost(2,!) | c(",G) + 0cost(2,") | c($,G) + 0cost(2,$) }
0cost(3,G) = min { 8 + 7 | 3 + % | % + 9 } = 9
0cost(3,H) = min { c(!,H) + 0cost(2,!) | c(#,H) + 0cost(2,#) | c($,H) + 0cost(2,$) }
0cost(3,H) = min { 11 + 7 | 9 + 5 | 12 + 9 } = 14
0cost(4,I) = min { c(F,I) + 0cost(3,F) | c(G,I) + 0cost(3,G) }
0cost(4,I) = min { 12 + 11 | 5 + 9 } = 14
0cost(4,J) = min { c(F,J) + 0cost(3,F) | c(G,J) + 0cost(3,G) | c(H,J) + 0cost(3,H) }
0cost(4,J) = min { 9 + 11 | 7 + 9 | 1 + 14 } = 1%
0cost(4,K) = min { c(H,K) + cost(3,H) }
0cost(4,K) = min { 8 + 14 } = 22
0cost(5,L) = min { c(I,L) + 0cost(4,I) | c(J,L) + 0cost(4,J) | c(K,L) + 0cost(4,K) }
0cost(5,L) = min { 7 + 14 | 8 + 1% | 11 + 22 } = 21
'ot*st t is &-"-G-I-L .it /istnc* 21
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 10/14Bina Nusantara
SHORTEST PATH IN MULTISTAGE GRAPH
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 11/14Bina Nusantara
EXERCISE
% <in( shortest path .rom no(e ! to no(e > usingDynamic Programming +.or&ar( metho( an(bac-&ar( metho(, ?
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 12/14Bina Nusantara
REVIEW
% M@>TAST!G) GB!P*
% M@>TAST!G) GB!P* PB=>)M
% DA!MAC PBGB!MMAG A M@>TAST!G)GB!P*
% <BE!BD M)T*D !D =!CFE!BD M)T*D
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 13/14Bina Nusantara
Books References
% Be.erences:
Computer !lgorithms C
% )llis *oro&itH Sarta Sahni Sanguthe8ar Baase-aran'
% Computer Science Press' +1IIJ,
Antro(uction to !lgorithms
% Thomas * Cormen Charles ) >eiserson Bonal( >'
% 3n( )(ition' The MAT Press' e& #or-' +$00I,
!lgoritma Atu Mu(ah% Bobert Setia(i'
% PT Prima An.osarana Me(ia Felompo- Grame(ia'
% Ka-arta' +$00J,
7/25/2019 PAA Dynamic Programming
http://slidepdf.com/reader/full/paa-dynamic-programming 14/14Bina Nusantara
END
Recommended