Download presentation
Presentation is loading. Please wait.
1
1 ECE 665 Spring 2005 Computer Algorithms Dynamic Programming Knapsack revisited
2
2 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 F n (M) = max{f n-1 (M), f n-1 (M-w n )+p n )
3
3 Recurrence equation For arbitrary f i (X): f i (X) = max{ f i-1 (X), f i-1 (X-w i )+p i } If item i is not added. If item i is added (with benefit cost p i, contributing weight w i ) We can represent solution space conveniently in terms of pairs (w i, p i )
4
4 Knapsack Solution space Purge solution ( P j, W j ) dominated by ( P k, W k ) if P j P k and W j W k ( p i,w i ) 12 23 54 X 1 =0 (0,0) X 1 =1 (1,2) (0,0) (P,W) =( i p i, i w i ) X 2 =0 (0,0) X 2 =1 (2,3) X 2 =0 (1,2) X 2 =1 (3,5) X 3 =0 (0,0) X 3 =1 (5,4) X 3 =1 (7,7) X 3 =0 (2,3) X 3 =1 (6,6)(1,2) X 3 =0 X 3 =1 (8,9)(3,5) X 3 =0 M=6 Delete solutions with W > M (knapsack volume exceeded
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.