approximate knapsack n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Approximate Knapsack PowerPoint Presentation
Download Presentation
Approximate Knapsack

Loading in 2 Seconds...

play fullscreen
1 / 18

Approximate Knapsack - PowerPoint PPT Presentation


  • 199 Views
  • Uploaded on

Approximate Knapsack. Get as much value as you can into the knapsack. Approximate Knapsack. Ingredients: Instances: The volume V of the knapsack. The volume and price of n objects <<v 1 ,p 1 >,<v 2 ,p 2 >,… ,<v n ,p n >>.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Approximate Knapsack' - nico


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
approximate knapsack
Approximate Knapsack

Get as much value

as you can

into the knapsack

approximate knapsack1
Approximate Knapsack
  • Ingredients:
    • Instances: The volume V of the knapsack. The volume and price of n objects<<v1,p1>,<v2,p2>,… ,<vn,pn>>.
    • Solutions: A set of objects that fit in the knapsack.
      • i.e. iS vi V
    • Cost of Solution: The total value of objects in set.
      • i.e. iS pi
    • Goal: Get as much value as you can into the knapsack.
slide3

Approximate Knapsack

  • Dynamic Programming Running time = ( V × n ) = ( 2#bits in V× n )
    • Poly time if size of knapsack is small
    • Exponential time if size is an arbitrary integer.
slide4

Approximate Knapsack

  • Dynamic Programming Running time = ( V × n ) = ( 2#bits in V× n )
  • NP-Complete
  • Approximate Algorithm
    • In poly-time (n3/), solution can be found
    • that is perfect in iS vi V
    • (1+)as good as optimal wrt iS pi
    • Eg,  = .001, Time is 1000n3
approximate knapsack2

No

Approximate Knapsack
  • Subinstance: V’[0..V], i[0..n], knapsack(V’,i) = maximize iS pi
    • subject to S  {1..i} and iS vi V
  • Recurrence Relation
    • knapsack(V’,i) = max( knapsack(V’,i-1), knapsack(V’-vi,i-1)+pi )

Yes

slide6

same + pi

same

No

Approximate Knapsack

 V’[0..V], i[0..n], knapsack(V’,i)

1

0

2

V’-vi

V’

V

OptSol price

0

1

2

i-1

Yes

i

Take best of best.

Our price?

n

slide7

Approximate Knapsack

 V’[0..V], i[0..n], knapsack(V’,i)

1

0

2

V’

V

OptSol price

0

1

2

i-1

i

Time = O(nV)

n

approximate knapsack3
Approximate Knapsack
  • Ingredients: (strange version)
    • Instances: The price P wanted from the knapsack. The volume and price of n objects<<v1,p1>,<v2,p2>,… ,<vn,pn>>.
    • Solutions: A set of objects with total value P.
      • i.e. iS pi≥ P
    • Cost of Solution: The total volume of objects in set.
      • i.e. iS vi
    • Goal: Minimize the volume needed to obtain this value P. into the knapsack.
approximate knapsack4

No

Approximate Knapsack
  • Subinstance: P’[0..P], i[0..n], knapsack’(P’,i) = minimize iS vi
    • subject to S  {1..i} and iS pi≥ P
  • Recurrence Relation
    • knapsack’(P’,i) = min( knapsack’(P’,i-1), knapsack’(P’-pi,i-1)+vi )

Yes

slide10

same + pi

same

No

Approximate Knapsack

 V’[0..V], i[0..n], knapsack’(P’,i)

1

0

2

P’-pi

P’

P

OptSol volume

0

1

2

i-1

Yes

i

Take best of best.

Our volume?

n

slide11

Approximate Knapsack

Original problem knapsack(V,n)

1

0

2

P’

P

OptSol volume

0

1

2

i

Find largest pricenot using more than V volume

Time = O(nP)

n

P = i pi

slide12

Approximate Knapsack

  • Dynamic Programming Running time = ( V × n ) = ( 2#bits in V× n )
    • Poly time if size of knapsack is small
    • Exponential time if size is an arbitrary integer.
  • Strange Dynamic Programming Running time = ( P × n ) = ( 2#bits in P× n )
    • Poly time if prices are small
    • Exponential time if prices are arbitrary integers.
approximate knapsack5
Approximate Knapsack
  • Approximation Algorithm:
    • Given V, <<v1,p1>,<v2,p2>,… ,<vn,pn>>, & 
    • Let k be some # of bits chosen later
    • Let p’i = pi with low k bits zeroed
    • eg pi = 101101101011p’i = 1011011000002 k=4
    • (Lost precision in prices, but that is ok)
    • Solve knapsack using the strange algorithm.
slide14

Approximate Knapsack

Original problem knapsack(V,n)

1

0

2

P’

P

OptSol volume

0

1

2

i

Find largest pricenot using more than V volume

n

P = i pi

slide15

Approximate Knapsack

Original problem knapsack(V,n)

1

0

2

P’

P

OptSol volume

0

1

2

i

Time

Only every 2k th column matters

= O(n P/2k)

n

approximate knapsack6
Approximate Knapsack

pi

  • Let Palg =
  • be the price returned by our alg.

iSalg

pi

  • Let Popt =
  • be the price returned by our alg.

iSopt

  • Approximation Algorithm:
    • Let Salg be the set of items selected by our alg.
    • Let Sopt be the set of items in the optimal sol.
  • Need Palg ≥ Popt (1-)
approximate knapsack7
Approximate Knapsack

Palg

= pi

iSalg

≥ p’i

≥ p’i

≥ (pi -2k)

iSalg

iSopt

iSopt

because rounded down

because Salg is an optimal solutionfor the <vi,p’i> problem

because rounded by at most 2k.

= Popt – n 2k

approximate knapsack8
Approximate Knapsack

n2k

= 1 -

Popt

Popt

Popt

Popt

2k

=

n

= O( n2 P )

Popt

n

= O( n3)

Time

Palg

(need)

≥ Popt– n2k

= 1 - 

Time = O(n P/2k)

P = i pi

Popt ≥

P

maxi pi ≥

done