0% found this document useful (0 votes)
53 views15 pages

20220701173555D6434 - 20200720221524D5797 - 20180725175948D5542 - COMP6049 Pert 14

This document discusses dynamic programming approaches for solving multistage graph problems. It begins by defining a multistage graph as a directed graph with stages connecting nodes and a single source and sink node. The multistage graph problem is to find the shortest path from the source to the sink. Two dynamic programming techniques are described: the forward method calculates costs moving forward from earlier to later stages, while the backward method calculates backward costs from later to earlier stages. Examples are provided to demonstrate calculating the shortest path between stages using both methods on a sample multistage graph.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views15 pages

20220701173555D6434 - 20200720221524D5797 - 20180725175948D5542 - COMP6049 Pert 14

This document discusses dynamic programming approaches for solving multistage graph problems. It begins by defining a multistage graph as a directed graph with stages connecting nodes and a single source and sink node. The multistage graph problem is to find the shortest path from the source to the sink. Two dynamic programming techniques are described: the forward method calculates costs moving forward from earlier to later stages, while the backward method calculates backward costs from later to earlier stages. Examples are provided to demonstrate calculating the shortest path between stages using both methods on a sample multistage graph.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

COMP6049 – Algorithm Design

and Analysis
Topic 14 – Dynamic Programming: Multistage Graph
Outline Materials

• Multistage Graph problem


• Forward technique
• Backward technique

Bina Nusantara University ISYS6197 2


MULTISTAGE GRAPH

• Multistage Graph is a graph with special


characteristics:
1. Directed Graph
2. Each edge has weight
3. Has only 1 source (called as s) and 1 sink (called as t)
4. Path from source to sink consists some stages V1 to Vk
5. All stages connect node in Vi to node Vi+1 where 1 ≤ i ≤ k
6. There are k stages, where k ≥ 2
7. 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) = 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,
cost(1,A) = min { 7 + 20 | 6 + 15 | 5 + 27 | 9 + 18 } = 21

Shortest path is A-C-G-I-L with distance 21

Bina Nusantara
BACKWARD METHOD

• Analysis by calculating path from source to a node


• Formula: bcost(i,j) = min{bcost(i–1,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) = 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) + cost(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

Shortest path is A-C-G-I-L with distance 21

Bina Nusantara
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
Q&A
References

• S. Sridhar. 2014. Design and Analysis of Algorithms, 1/e.


Oxford University Press. India. Chapter 13
• Ellis Horowitz,Sanguthevar Rajasekaran,Sartaj Sahni. 1998.
Computer algorithms/C++. 1STBL. New York. Chapter 5.2
• Multistage Graphs
http://www.cs.oswego.edu/~odendahl/coursework/csc465
/notes/09-c-multistage.html
THANK YOU

You might also like