15
Approximation Algorithms for Knapsack Problems 1 Tsvi Kopelowitz Modified by Ariel Rosenfeld

Approximation Algorithms for Knapsack Problems

  • 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

Page 1: Approximation Algorithms  for Knapsack Problems

Approximation Algorithms for Knapsack Problems

1

Tsvi KopelowitzModified by Ariel Rosenfeld

Page 2: Approximation Algorithms  for Knapsack Problems

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

Page 3: Approximation Algorithms  for Knapsack Problems

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

Page 4: Approximation Algorithms  for Knapsack Problems

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)(

Page 5: Approximation Algorithms  for Knapsack Problems

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

Page 6: Approximation Algorithms  for Knapsack Problems

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

Page 7: Approximation Algorithms  for Knapsack Problems

2-approximation try it yourself…

7

Page 8: Approximation Algorithms  for Knapsack Problems

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

Page 9: Approximation Algorithms  for Knapsack Problems

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

Page 10: Approximation Algorithms  for Knapsack Problems

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,

Page 11: Approximation Algorithms  for Knapsack Problems

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

Page 12: Approximation Algorithms  for Knapsack Problems

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

Page 13: Approximation Algorithms  for Knapsack Problems

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

''

Page 14: Approximation Algorithms  for Knapsack Problems

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

'

Page 15: Approximation Algorithms  for Knapsack Problems

Complexity and NotesTime:

algorithm is a FPTAS.

32max2 nOnnO

kvnO

15