1 / 18

Approximate Knapsack

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 >>.

nico
Download Presentation

Approximate Knapsack

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Approximate Knapsack Get as much value as you can into the knapsack

  2. 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.

  3. 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.

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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.

  9. 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

  10. 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

  11. 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

  12. 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.

  13. 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.

  14. 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

  15. 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

  16. 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-)

  17. 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

  18. 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

More Related