198 views

Uploaded by arun_vvv

save

- Optimal Allocation (1)
- Set-based-Design-Method-for-Multi-objective-Structural-Design-w_2015_Procedi.pdf
- EECS 281 Project 4
- 108 Goal Allignment
- Section 1.6.7
- 181604_DAA(1)
- Power System Operation and Control
- Mathematical Mode 00 Mcco
- Dynamic Programming
- genetic algorithm.txt
- Transportation Model
- Dynamic Programming
- Pereira Campodónico Kelman
- Free Video Lectures for MCA
- Design Optimization print.pdf
- Daniel_0530GB025TP2014
- TUGASMANDIRI 6 IMA.docx
- 287
- Chapter 26 Reliability Analysis of Tubular Joints in Offshore Structures
- Essential Thinking Intro
- Introduction
- Module 1
- Training Material GSM Adjacency Optimization OPT 3.0 CD3
- Brachistochrone-ProblemIPOPTinfo
- sm ch (10).pdf
- 07_2011_042_Stankovic_05
- Team 3 ME 558 Final Report
- Optimization
- 3G Radio Optimisation Process (2003)
- Rosenbrock Fin
- Sapiens: A Brief History of Humankind
- The Unwinding: An Inner History of the New America
- Yes Please
- Dispatches from Pluto: Lost and Found in the Mississippi Delta
- Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
- The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution
- John Adams
- Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
- A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
- This Changes Everything: Capitalism vs. The Climate
- Grand Pursuit: The Story of Economic Genius
- The Emperor of All Maladies: A Biography of Cancer
- The Prize: The Epic Quest for Oil, Money & Power
- Team of Rivals: The Political Genius of Abraham Lincoln
- The New Confessions of an Economic Hit Man
- The World Is Flat 3.0: A Brief History of the Twenty-first Century
- Rise of ISIS: A Threat We Can't Ignore
- Smart People Should Build Things: How to Restore Our Culture of Achievement, Build a Path for Entrepreneurs, and Create New Jobs in America
- The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
- How To Win Friends and Influence People
- Steve Jobs
- Angela's Ashes: A Memoir
- Bad Feminist: Essays
- The Light Between Oceans: A Novel
- The Silver Linings Playbook: A Novel
- Leaving Berlin: A Novel
- Extremely Loud and Incredibly Close: A Novel
- The Sympathizer: A Novel (Pulitzer Prize for Fiction)
- You Too Can Have a Body Like Mine: A Novel
- The Incarnations: A Novel
- Life of Pi
- The Love Affairs of Nathaniel P.: A Novel
- A Man Called Ove: A Novel
- Bel Canto
- The Master
- The Rosie Project: A Novel
- The Blazing World: A Novel
- We Are Not Ourselves: A Novel
- The First Bad Man: A Novel
- The Flamethrowers: A Novel
- Brooklyn: A Novel
- The Art of Racing in the Rain: A Novel
- Wolf Hall: A Novel
- The Wallcreeper
- Interpreter of Maladies
- Beautiful Ruins: A Novel
- The Kitchen House: A Novel
- The Perks of Being a Wallflower
- The Bonfire of the Vanities: A Novel
- Lovers at the Chameleon Club, Paris 1932: A Novel
- A Prayer for Owen Meany: A Novel
- The Cider House Rules
- Mislaid: A Novel

You are on page 1of 3

2/24/2005 1:46 AM

**Matrix Chain-Products
**

Matrix Chain-Product:

Dynamic Programming

Compute A=A0*A1*…*An-1 Ai is di × di+1 Problem: How to parenthesize?

Example

B is 3 × 100 C is 100 × 5 D is 5 × 5 (B*C)*D takes 1500 + 75 = 1575 ops B*(C*D) takes 1500 + 2500 = 4000 ops

Dynamic Programming

1

Dynamic Programming

4

**Outline and Reading
**

Matrix Chain-Product (§5.3.1) The General Technique (§5.3.2) 0-1 Knapsack Problem (§5.3.3)

Enumeration Approach

Matrix Chain-Product Alg.:

Try all possible ways to parenthesize A=A0*A1*…*An-1 Calculate number of ops for each one Pick the one that is best

Running time:

The number of parenthesizations is equal to the number of binary trees with n nodes This is exponential! It is called the Catalan number, and it is almost 4n. This is a terrible algorithm!

Dynamic Programming 2 Dynamic Programming 5

**Matrix Chain-Products
**

Dynamic Programming is a general algorithm design paradigm.

Rather than give the general structure, let us first give a motivating example: Matrix Chain-Products

Greedy Approach

f B e j

**Idea #1: repeatedly select the product that uses (up) the most operations. Counter-example:
**

A is 10 × 5 B is 5 × 10 C is 10 × 5 D is 5 × 10 Greedy idea #1 gives (A*B)*(C*D), which takes 500+1000+500 = 2000 ops A*((B*C)*D) takes 500+250+250 = 1000 ops

Dynamic Programming 6

**Review: Matrix Multiplication.
**

C = A*B A is d × e and B is e × f

O(d⋅e⋅f ) time

e A i C i,j f d

C[i, j ] = ∑ A[i, k ] * B[k , j ] d

k =0

e −1

Dynamic Programming

3

1

Dynamic Programming

2/24/2005 1:46 AM

**Another Greedy Approach
**

Idea #2: repeatedly select the product that uses the fewest operations. Counter-example:

A is 101 × 11 B is 11 × 9 C is 9 × 100 D is 100 × 99 Greedy idea #2 gives A*((B*C)*D)), which takes 109989+9900+108900=228789 ops (A*B)*(C*D) takes 9999+89991+89100=189090 ops

**Dynamic Programming Algorithm Visualization
**

The bottom-up N i , j = min{N i ,k + N k +1, j + d i d k +1d j +1} i ≤k < j construction fills in the N array by diagonals j … n-1 N 0 1 2 i Ni,j gets values from 0 previous entries in i-th 1 row and j-th column … answer Filling in each entry in i the N table takes O(n) time. Total run time: O(n3) j Getting actual parenthesization can be n-1 done by remembering “k” for each N entry

Dynamic Programming 10

The greedy approach is not giving us the optimal value. Dynamic Programming

7

“Recursive” Approach

Define subproblems:

Find the best parenthesization of Ai*Ai+1*…*Aj. Let Ni,j denote the number of operations done by this subproblem. The optimal solution for the whole problem is N0,n-1.

**Dynamic Programming Algorithm
**

Since Algorithm matrixChain(S): subproblems Input: sequence S of n matrices to be multiplied overlap, we don’t use recursion. Output: number of operations in an optimal Instead, we parenthesization of S construct optimal for i ← 1 to n − 1 do subproblems Ni,i ← 0 “bottom-up.” for b ← 1 to n − 1 do Ni,i’s are easy, so start with them { b = j − i is the length of the problem } Then do for i ← 0 to n − b − 1 do problems of j←i+b “length” 2,3,… subproblems, Ni,j ← +∞ and so on. for k ← i to j − 1 do Running time: Ni,j ← min{Ni,j, Ni,k + Nk+1,j + di dk+1 dj+1} O(n3) return N0,n−1

Dynamic Programming 11

**Subproblem optimality: The optimal solution can be defined in terms of optimal subproblems
**

There has to be a final multiplication (root of the expression tree) for the optimal solution. Say, the final multiply is at index i: (A0*…*Ai)*(Ai+1*…*An-1). Then the optimal solution N0,n-1 is the sum of two optimal subproblems, N0,i and Ni+1,n-1 plus the time for the last multiply. If the global optimum did not have these optimal subproblems, we could define an even better “optimal” solution.

Dynamic Programming 8

Characterizing Equation

The global optimal has to be defined in terms of optimal subproblems, depending on where the final multiply is at. Let us consider all possible places for that final multiply:

Recall that Ai is a di × di+1 dimensional matrix. So, a characterizing equation for Ni,j is the following:

**The General Dynamic Programming Technique
**

Applies to a problem that at first seems to require a lot of time (possibly exponential), provided we have:

Simple subproblems: the subproblems can be defined in terms of a few variables, such as j, k, l, m, and so on. Subproblem optimality: the global optimum value can be defined in terms of optimal subproblems Subproblem overlap: the subproblems are not independent, but instead they overlap (hence, should be constructed bottom-up).

N i , j = min{N i ,k + N k +1, j + d i d k +1d j +1}

i ≤k < j

**Note that subproblems are not independent–the subproblems overlap.
**

Dynamic Programming 9

Dynamic Programming

12

2

Dynamic Programming

2/24/2005 1:46 AM

**The 0/1 Knapsack Problem
**

Given: A set S of n items, with each item i having Goal: Choose items with maximum total benefit but with weight at most W. If we are not allowed to take fractional amounts, then this is the 0/1 knapsack problem.

In this case, we let T denote the set of items we take Objective: maximize Constraint: wi - a positive weight bi - a positive benefit

**A 0/1 Knapsack Algorithm, Second Attempt
**

Sk: Set of items numbered 1 to k. Define B[k,w] to be the best selection from Sk with weight at most w Good news: this does have subproblem optimality.

∑b

i∈T

B[k − 1, w] if wk > w ⎧ B[k , w] = ⎨ else ⎩max{B[k − 1, w], B[k − 1, w − wk ] + bk }

I.e., the best subset of Sk with weight at most w is either

the best subset of Sk-1 with weight at most w or the best subset of Sk-1 with weight at most w−wk plus item k

i

∑w

i∈T

i

≤W

13

Dynamic Programming

Dynamic Programming

16

Example

Given: A set S of n items, with each item i having Goal: Choose items with maximum total benefit but with weight at most W. “knapsack” Items:

1 2 3 4 5

0/1 Knapsack Algorithm

B[k − 1, w] if wk > w ⎧ B[k , w] = ⎨ else ⎩max{B[k − 1, w], B[k − 1, w − wk ] + bk } Algorithm 01Knapsack(S, W): Recall the definition of Input: set S of n items with benefit bi B[k,w] and weight wi; maximum weight W Output: benefit of best subset of S with Since B[k,w] is defined in weight at most W terms of B[k−1,*], we can let A and B be arrays of length W + 1 use two arrays of instead of a matrix for w ← 0 to W do B[w] ← 0 Running time: O(nW). for k ← 1 to n do Not a polynomial-time copy array B into array A algorithm since W may be large for w ← wk to W do if A[w−wk] + bk > A[w] then This is a pseudo-polynomial time algorithm B[w] ← A[w−wk] + bk return B[W]

Dynamic Programming 17

bi - a positive “benefit” wi - a positive “weight”

box of width 9 in

Weight: Benefit:

4 in $20

2 in $3

2 in $6

6 in $25

2 in $80

Solution:

**• item 5 ($80, 2 in) • item 3 ($6, 2in) • item 1 ($20, 4in)
**

14

Dynamic Programming

**A 0/1 Knapsack Algorithm, First Attempt
**

Sk: Set of items numbered 1 to k. Define B[k] = best selection from Sk. Problem: does not have subproblem optimality:

Consider set S={(3,2),(5,4),(8,5),(4,3),(10,9)} of (benefit, weight) pairs and total weight W = 20

Best for S4:

Best for S5:

Dynamic Programming

15

3

- Optimal Allocation (1)Uploaded byRoss Zhou
- Set-based-Design-Method-for-Multi-objective-Structural-Design-w_2015_Procedi.pdfUploaded byMohd Tariq
- EECS 281 Project 4Uploaded byAnonUnlikely
- 108 Goal AllignmentUploaded byMunyaradzi Mukazika
- Section 1.6.7Uploaded byabdulkbasit
- 181604_DAA(1)Uploaded byJigar Thakkar
- Power System Operation and ControlUploaded byDebabrata
- Mathematical Mode 00 MccoUploaded bySaurabh Kumar Nirwal
- Dynamic ProgrammingUploaded byGiri Saranu
- genetic algorithm.txtUploaded bysuraj
- Transportation ModelUploaded byKaren Kaye Bulan
- Dynamic ProgrammingUploaded bykirsh123
- Pereira Campodónico KelmanUploaded byPatricio Guillermo Soto Abarca
- Free Video Lectures for MCAUploaded byedholecom
- Design Optimization print.pdfUploaded bykarthipriya
- Daniel_0530GB025TP2014Uploaded byAkindunni Daniel
- TUGASMANDIRI 6 IMA.docxUploaded byFaidul
- 287Uploaded byjin11004
- Chapter 26 Reliability Analysis of Tubular Joints in Offshore StructuresUploaded byMARIA
- Essential Thinking IntroUploaded byTeklit Berihu
- IntroductionUploaded byakbisoi1
- Module 1Uploaded byPriyanshu Reddy
- Training Material GSM Adjacency Optimization OPT 3.0 CD3Uploaded byMoses Gitonga Kathuri
- Brachistochrone-ProblemIPOPTinfoUploaded byNumkang Kang
- sm ch (10).pdfUploaded byHector Naranjo
- 07_2011_042_Stankovic_05Uploaded byklomps_jr
- Team 3 ME 558 Final ReportUploaded byingmecandres
- OptimizationUploaded byRupak Sapkota
- 3G Radio Optimisation Process (2003)Uploaded byJeffrey Price
- Rosenbrock FinUploaded byIgnacioF.FernandezPaba