Design and Analysis of Algorithms Lecture Dynamic programming Alexander Kolesnikov 17.10.205 DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU,

Slides:



Advertisements
Similar presentations
Unit-iv.
Advertisements

~1~ Infocom’04 Mar. 10th On Finding Disjoint Paths in Single and Dual Link Cost Networks Chunming Qiao* LANDER, CSE Department SUNY at Buffalo *Collaborators:
1.1 Data Structure and Algorithm Lecture 6 Greedy Algorithm Topics Reference: Introduction to Algorithm by Cormen Chapter 17: Greedy Algorithm.
Optimization of thermal processes2007/2008 Optimization of thermal processes Maciej Marek Czestochowa University of Technology Institute of Thermal Machinery.
CS420 Lecture 9 Dynamic Programming. Optimization Problems In optimization problems a set of choices are to be made to arrive at an optimum, and sub problems.
Deterministic Dynamic Programming.  Dynamic programming is a widely-used mathematical technique for solving problems that can be divided into stages.
1 Appendix B: Solving TSP by Dynamic Programming Course: Algorithm Design and Analysis.
 2004 SDU Lecture11- All-pairs shortest paths. Dynamic programming Comparing to divide-and-conquer 1.Both partition the problem into sub-problems 2.Divide-and-conquer.
Algorithm Strategies Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Computability and Complexity 23-1 Computability and Complexity Andrei Bulatov Search and Optimization.
Chapter 7 Dynamic Programming 7.
§ 8 Dynamic Programming Fibonacci sequence
Dynamic Programming Technique. D.P.2 The term Dynamic Programming comes from Control Theory, not computer science. Programming refers to the use of tables.
The Stagecoach Problem
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2006 Lecture 2 Monday, 9/13/06 Design Patterns for Optimization Problems.
MIT and James Orlin © Dynamic Programming 2 –Review –More examples.
Cache Placement in Sensor Networks Under Update Cost Constraint Bin Tang, Samir Das and Himanshu Gupta Department of Computer Science Stony Brook University.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2002 Lecture 1 (Part 3) Tuesday, 1/29/02 Design Patterns for Optimization.
Chapter 10 Dynamic Programming. 2 Agenda for This Week Dynamic Programming –Definition –Recursive Nature of Computations in DP –Forward and Backward Recursion.
Backtracking.
1 Numerical geometry of non-rigid shapes Shortest path problems Shortest path problems Lecture 2 © Alexander & Michael Bronstein tosca.cs.technion.ac.il/book.
IT 60101: Lecture #201 Foundation of Computing Systems Lecture 20 Classic Optimization Problems.
DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND Image Compression Lecture 9 Optimal Scalar Quantization Alexander Kolesnikov.
CSCE350 Algorithms and Data Structure Lecture 17 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
7 -1 Chapter 7 Dynamic Programming Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if.
Fundamentals of Algorithms MCS - 2 Lecture # 7
Dr. Naveed Ahmad Assistant Professor Department of Computer Science University of Peshawar.
Dynamic Programming Key characteristic of a Dynamic Program: Breaking up a large, unwieldy problem into a series of smaller, more tractable problems. Shortest.
7 -1 Chapter 7 Dynamic Programming Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if.
8 -1 Dynamic Programming Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if i  2 Solved.
Contents of Chapter 5 Chapter 5 Dynamic Programming
1 1 Slide © 2000 South-Western College Publishing/ITP Slides Prepared by JOHN LOUCKS.
Algorithm Paradigms High Level Approach To solving a Class of Problems.
DPA1 Dynamic Programming Applications INSEAD Ph.D. Programme May-June 2003.
Honors Track: Competitive Programming & Problem Solving Optimization Problems Kevin Verbeek.
Efficient algorithms for polygonal approximation
Algorithm Design Methods (II) Fall 2003 CSE, POSTECH.
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
December 14, 2015 Design and Analysis of Computer Algorithm Pradondet Nilagupta Department of Computer Engineering.
Dynamic Programming Discrete time frame Multi-stage decision problem Solves backwards.
Approximation Algorithms Department of Mathematics and Computer Science Drexel University.
Tuesday, April 30 Dynamic Programming – Recursion – Principle of Optimality Handouts: Lecture Notes.
CS 3343: Analysis of Algorithms Lecture 18: More Examples on Dynamic Programming.
Computer Sciences Department1.  Property 1: each node can have up to two successor nodes (children)  The predecessor node of a node is called its.
Ramakrishna Lecture#2 CAD for VLSI Ramakrishna
1 1 © 2003 Thomson  /South-Western Slide Slides Prepared by JOHN S. LOUCKS St. Edward’s University.
1Computer Sciences Department. 2 Advanced Design and Analysis Techniques TUTORIAL 7.
8 -1 Dynamic Programming Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if i  2 Solved.
Dynamic Programming Sequence of decisions. Problem state.
Design & Analysis of Algorithm Dynamic Programming
Water Resources Planning and Management Daene McKinney
Chapter 11 Dynamic Programming.
Lecture on Design and Analysis of Computer Algorithm
EML Engineering Design Systems II (Senior Design Project)
Lecture 5 Dynamic Programming
CS 3343: Analysis of Algorithms
Lecture 5 Dynamic Programming
Graphs & Graph Algorithms 2
Unit-5 Dynamic Programming
Dynamic Programming General Idea
Unit 4: Dynamic Programming
Unit-4: Dynamic Programming
Lecture 6 Topics Greedy Algorithm
Dynamic Programming.
Greedy Algorithms TOPICS Greedy Strategy Activity Selection
Dynamic Programming General Idea
Dynamic Programming.
Dynamic Programming 動態規劃
Advanced Analysis of Algorithms
Department of Computer Science & Engineering
Presentation transcript:

Design and Analysis of Algorithms Lecture Dynamic programming Alexander Kolesnikov DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF JOENSUU JOENSUU, FINLAND

List of sample problems Shortest path in trellis graph; Shortest path in trellis graph; Optimal allocation of constrained resource; Optimal allocation of constrained resource; Optimal sequence partition (k-link shortest path). Optimal sequence partition (k-link shortest path). to be continued...

Shortest path in trellis graph

Stagecoach problem A traveler wishes to minimize the length of a journey A J from town A to J.

Greedy algorithm The length of the route A-B-F-I-J: =13. Can we find shorter route?

Exhaustive search: try all Route A-D-F-I-J: =11 The total number of routes to be tested: 3  3  2  1=18 Can we avoid exhaustive search?

Shortest path construction: 1st stage (B) ?

Shortest path construction: 1st stage S(A,B)=2 S(A,C)=4 S(A,D)=3

Shortest path construction: 2nd stage (E) 1. (A..B)-E: 2+7=9 2. (A..C)-E: 4+3=7 3. (A..D)-E: 3+4= (A..C)-E: 7 ?

Shortest path construction: 2nd stage (E) 1. (A..B)-E: 2+7=9 2. (A..C)-E: 4+3=7 *) 3. (A..D)-E: 3+4= (A..C)-E: 7

Shortest path construction: 2nd stage (F) 1. (A..B)-F: 2+4=6 2. (A..C)-F: 4+2=6 3. (A..D)-F: 3+1=4 *) (A..C)-F: 4 ?

Shortest path construction: 2nd stage (F) 1. (A..B)-F: 2+4=6 2. (A..C)-F: 4+2=6 3. (A..D)-F: 3+1=4 *) (A..D)-F: 4

Shortest path construction: 2nd stage (G) 1. (A..B)-G: 2+6=8 *) 2. (A..C)-G: 4+6=10 3. (A..D)-G: 3+5= (A..B)-G: 8 ?

Shortest path construction: 2nd stage (G) 1. (A..B)-G: 2+6=8 *) 2. (A..C)-G: 4+6=10 3. (A..D)-G: 3+5= (A..B)-G: 8

Shortest path construction: 3rd stage (H) 1. (A..E)-H: 7+1=8 *) 2. (A..F)-H: 4+6=10 3. (A..G)-H: 5+3= (A..E)-H: 5

Shortest path construction: 3rd stage (H) 1. (A..E)-H: 7+1=8 *) 2. (A..F)-H: 4+6=10 3. (A..G)-H: 5+3= (A..E)-H: 5

Shortest path construction: 3rd stage (I) 1. (A..E)-I: 7+4=11 2. (A..F)-I: 4+3=7 *) 3. (A..G)-I: 5+3= (A..F)-I: 7

Shortest path construction: 3rd stage (I) 1. (A..E)-I: 7+4=11 2. (A..F)-I: 4+3=7 *) 3. (A..G)-I: 5+3= (A..F)-I: 7

Shortest path construction: 4th stage (J) 1. (A..H)-J: 8+3=11 *) 2. (A..I) -J: 7+4= (A..H)-J: 11

Shortest path construction: 4th stage (J) 1. (A..H)-J: 8+3=11 *) 2. (A..I) -J: 7+4= (A..H)-J: 11

Backtrack the shortest path

The shortest path Route A-C-E-H-J: =11

Trellis graph K-1 K

Trellis graph Distance (weight) from point i 1 at stage (j  1) to point i 2 at stage j : The total value of cost function:

Principle of optimality of Bellman An optimal path has the property that whatever the initial conditions and control variables (choices) over some initial period, the control (or decision variables) chosen over the remaining period must be optimal for the remaining problem, with the state resulting from the early decisions taken to be the initial condition.

Dynamic programming Initialization: Recursive eqution: Cost function:

Complexity Exhaustive search: O(n K ) Dynamic programming algorithm: O(Kn 2 ) where K is the number of stages, n is the number of points in a stage

Optimal allocation of constrained resource

Problem formulation N units of a resource; This resource must be distributed among K activities; Functions f k (x) - profit for allocated resource; Allocate N units of resource to K activities with given return functions so that the total profit is maximal: subject to:

Dynamic programming formulation Initialization: Recursive equation: Optimal value function:

Allocate 3 mln euros into four projects Profit f k (x), K=3, N=3.

Trellis graph

Solution #1: 2; f 1 (2)=8 #2: 1; f 2 (1)=5 #3: 0; f 3 (0)=0 #4: 0; f 4 (0)= N=3; G 4 (3)=13 *)

Search in the state space K N0 0 n k j G k (n) G k-1 (j) G K (N) Start state f k (n-j ) G k (n) = max{G k (0) + f k (n), G k (1) + f k (n-1),... G k (j-1)+ f k (j),... G k (n) + f k (0)} k-1 * A k (n)=j opt 1

Optimal partition of data sequence

Problem formulation Given a sequence of data X={x 1, x 2, …,x N } Do partition of the sequence X into to K groups with given cost functions f(x i,x j ) so that the total value of the cost function is minimal:

Partition into groups: Example Data: x 0 =  < x 1 <... < x j <... < x N Partition indices: i 0 = 0 < i 1 <... < i j <... < i M =N. Groups:... ]( ] ( #1 #2 #3 (x 0 =  ) x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 x 13 x 14 x N (i 0 =0) i 1 =4 i 2 =10 i K =N=15 K=3

Problem formulation Recursive equation: Cost function: Initialization:

Search in the state space  K N1 0 b n k j State space  G k (n) G k-1 (j) G K (N) Start state f(j,n ) G k (n) = min{G k (k) + f(k, n], G k (k) + f(k+1,n],... G k (j-1) + f(j, n]* ),... G k (n-1) + f(n, n]} k-1 * A k (n)=j opt

Scheme of the DP algorithm // Initialization G 1 (n) FOR n = 1 TO N DO G 1 (n)= f(1,n] // Minimum search FOR k = 2 TO K DO FOR n = k TO N DO d min   FOR j= k-1 TO n-1 DO G k-1 (j) c  G k-1 (j) + f(j,n] IF(c < c min ) c min  c; j min  j ENDIF ENDFOR G k (n) G k (n)  d min A k (n) A k (n)  j min ENDFOR Complexity: O(KN 2 )

Backtrack in the state space  K N1 0 b nj State space  A K (N) Start state S(M+1)= N FOR m = K+1 TO 2 DO S(m  1) = A(S(m), m)) G K (N) P = G K (N) S(M+1)= N FOR m = K+1 TO 2 DO S(m  1) = A(S(m), m)) G K (N) P = G K (N) N=22, K=8: S={22,18,14,12,9,6,4,3,1} (x 0,x 3 ], (x 3,x 4 ], (x 4,x 6 ], (x 6,x 9 ], (x 9,x 12 ], (x 12,x 14 ], (x 14,x 18 ], (x 18,x 22 ]