1 / 18

190 likes | 423 Views

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

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

**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<<v1,p1>,<v2,p2>,… ,<vn,pn>>. • Solutions: A set of objects that fit in the knapsack. • i.e. iS vi V • Cost of Solution: The total value of objects in set. • i.e. iS pi • Goal: Get as much value as you can into the knapsack.**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.**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 iS vi V • (1+)as good as optimal wrt iS pi • Eg, = .001, Time is 1000n3**No**Approximate Knapsack • Subinstance: V’[0..V], i[0..n], knapsack(V’,i) = maximize iS pi • subject to S {1..i} and iS vi V • Recurrence Relation • knapsack(V’,i) = max( knapsack(V’,i-1), knapsack(V’-vi,i-1)+pi ) Yes**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**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 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. iS pi≥ P • Cost of Solution: The total volume of objects in set. • i.e. iS vi • Goal: Minimize the volume needed to obtain this value P. into the knapsack.**No**Approximate Knapsack • Subinstance: P’[0..P], i[0..n], knapsack’(P’,i) = minimize iS vi • subject to S {1..i} and iS pi≥ P • Recurrence Relation • knapsack’(P’,i) = min( knapsack’(P’,i-1), knapsack’(P’-pi,i-1)+vi ) Yes**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**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**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 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.**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**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 Knapsack**pi • Let Palg = • be the price returned by our alg. iSalg pi • Let Popt = • be the price returned by our alg. iSopt • 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 Knapsack**Palg = pi iSalg ≥ p’i ≥ p’i ≥ (pi -2k) iSalg iSopt iSopt because rounded down because Salg is an optimal solutionfor the <vi,p’i> problem because rounded by at most 2k. = Popt – n 2k**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