{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lab 9 - A[0,w = 0 ‐ When there are no items to be...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab 9 – Dynamic Programming 1. 0 1 Knapsack Problem The 0 1 Knapsack Problem is a common problem in Integer Programming. We are given a set of items, each with a certain value and weight. The problem is to choose the items to place into the knapsack (which has a certain weight limit) that maximized the total value. 2. IP Formulation The problem can be easily formulated into a Binary Integer Program: Let x i = 1 if we include item i in the knapsack and 0 otherwise Let v i and w i represent the value and weight of each item i Let W be the weight limit of the knapsack min ෍ ݔ ݒ ௜ୀଵ ݏݑܾ݆݁ܿݐ ݐ݋: ෍ ݔ ݓ ൑ ܹ ௜ୀଵ 3. Dynamic Programming Formulation It is also possible to formulate the problem as a DP if the weights are integers: Let A[i,w] be the value of the best knapsack given we use up to items i and weight w The optimality equations and boundary conditions are as follows:
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: A[0,w] = 0 ‐ When there are no items to be considered, there is no value A[i, 0] = 0 – When there is no weight remaining, there is no value A[i, w] = A[i ‐ 1,w ] ( if w i > w) – New item being considered weighs more than the current limit A[i, w] = max(A[i ‐ 1,w], m[i ‐ 1,w ‐ w i ]+v i ) (if w i ≤ w) Calculating A[N,W] given there are N items and a total Weight of W gets the optimal solution to the DP 4. MATLAB Code A Dynamic Programming Problem has been written in MATLAB and can be downloaded from: http://www.mathworks.com/matlabcentral/fileexchange/22783 ‐ ‐ 1 ‐ knapsack Download and look at the code to see the Dynamic Programming Algorithm at work. 5. Extension Study the MATLAB code for the Knapsack DP for next week’s lab....
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online