Upload
terra
View
33
Download
7
Embed Size (px)
DESCRIPTION
Approximation Algorithms for Knapsack Problems. Tsvi Kopelowitz Modified by Ariel Rosenfeld. Given: a set S of n objects with weights and values, and a weight bound: w 1 , w 2 , …, w n , B (weights, weight bound). v 1 , v 2 , …, v n (values - profit). - PowerPoint PPT Presentation
Citation preview
Approximation Algorithms for Knapsack Problems
1
Tsvi KopelowitzModified by Ariel Rosenfeld
KnapsackGiven: a set S of n objects with weights
and values, and a weight bound:◦w1, w2, …, wn, B (weights, weight bound).◦v1, v2, …, vn (values - profit).
Find: subset of S with total weight at most B, and maximum total value.Formally :
Problem is known to be NP-hard2
Ti
iTi
i Bwv subject to max
Assumptions . (every item can be added to T) . (non-negative values)Values, weights, and bound are all integers.
Note:This is a maximum problem.Define: OPT = The optimal solution.We will see a 2-approximation for two versions of
knapsack.
3
Bwi i ,
0, ivi
Uniform Knapsack (simple form) (value=weight)
2-approximation algorithm:◦Sort the items such that v1 ≥ v2 ≥ … ≥ vn.
◦Pick such that and .
ii wvi ,
4
jvvA ,...,1 BAweight )(BvAweight j 1)(
Uniform Knapsack (proff) Claim: .
Proof: ◦ Assume (by contradiction): .
◦By the algorithm: => . ◦ => =>contradiction.
(Since items were sorted)
5
2)(
2)( OPTvalueBAvalue
2)( BAvalue
BvAweight j 1)(21Bv j
2)(1BAvaluev 11 jvv
2-approximation (general knapsack)
Define ratio:
Sort items such that r1 ≥ r2 ≥ … ≥ rn.Pick such that and
.
If( ) returnelse return A.
6
i
ii wvr
jvvA ,...,1 BAweight )(BwAweight j 1)(
)(max Avaluev }{ maxv
2-approximation try it yourself…
7
Claim:
Proof sketch (fill the details yourselves): Consider fractional knapsack (where we can take
some of each item)– the optimal solution is A’= (A and a fraction of vj+1.)◦ .
◦ .
2-approximation (general knapsack)
8
)()'()( 1 OPTvalueAvaluevAvalue j
)()( max1max OPTvaluevAvaluevv j
2)())(,max( max
OPTvalueAvaluev
2)())(,max( max
OPTvalueAvaluev
9
A(i,j) = Smallest weight subset of objects 1,…,i with a total value of j.
A DP algorithm for knapsack A 1 2 3 j n vmax
1 2 3
i
n
Upper bound on optimal profit
A DP algorithm for knapsack
The result is: max j such that A(n, j) ≤ B.The runtime is: O(n2vmax)Pseudo-polynomial
10
otherwisevjw
jA 11,1
ii wvjiAjiAjiA ,1,,1min,
11
Definition: Fully Polynomial Time Approximation Scheme (FPTAS)
Given ε, delivers a solution with a ratio of (1- ε) for maximum and a ratio of (1+ ε) for minimum, and runs in time polynomial in the size of the input and (1/ε)
Definition: Pseudo-polynomial
If input of integers is given in unary form, runs in polynomial time.
Definitions
FPTAS for knapsack The Idea – use scaling!! Given error bound , define .
For each object i, define . Use DP to find optimal solution OPT’ for
the rounded values. Return the set OPT’ with the original
values.
nvk max
kvv i
i'
12
0
Correctness
Claim:
Proof: For every i: .(1) => (3)
(2) (4)
13
iii kvvvk ')1'(
ii kvv '
OPTi
iOPTi
i vv '''
)()1()'('
OPTvaluevOPTvalueOPTi
i
kkvv ii ' knvkOPTkvkvOPTi
iOPTi
iOPTi
i
''
CorrectnessProof continued: (1) (3)
(2) (4)
)()1()(
''
))((max
)3()4('
)2('
max
OPTvaluevOPTvalue
knvvkvkv
OPTvaluev
OPTii
OPTii
OPTii
OPTii
14
ii kvv '
OPTi
iOPTi
i vv '''
kkvv ii ' knvkvOPTi
iOPTi
i
'
Complexity and NotesTime:
algorithm is a FPTAS.
32max2 nOnnO
kvnO
15