40 likes | 70 Views
ECE 665 Spring 2005 Computer Algorithms. Dynamic Programming Knapsack revisited. Recurrence equation. Problem statement: max i pi , s.to: i w i M = knapsack volume p i = benefit of item i w i = weight of item i Optimum solution at decision variable x n
E N D
ECE 665Spring 2005Computer Algorithms Dynamic Programming Knapsack revisited
Recurrence equation • Problem statement: max i pi, s.to: i wi M = knapsack volume pi = benefit of item i wi = weight of item i • Optimum solution at decision variable xn Fn(M) = max{fn-1(M), fn-1(M-wn)+pn)
Recurrence equation • For arbitrary fi(X): fi(X) = max{ fi-1(X), fi-1(X-wi)+pi } If item i is not added. If item i is added (with benefit cost pi, contributing weight wi) • We can represent solution space conveniently in terms of pairs (wi, pi)
(P,W) =(ipi, iwi) (0,0) X1=1 X3=0 X1=0 X2=0 X2=0 X2=1 X2=1 (0,0) (0,0) (1,2) (0,0) (2,3) (3,5) (1,2) X3=0 X3=1 X3=0 X3=1 X3=1 X3=1 X3=0 (5,4) (2,3) (7,7) (1,2) (6,6) (3,5) (8,9) Knapsack Solution space (pi,wi) M=6 • Purge solution (Pj, Wj)dominated by (Pk, Wk)if Pj Pkand Wj Wk • Delete solutions with W > M (knapsack volume exceeded