CS 230A KP-0 ✬ ✫ ✩ ✪ 0-1 Knapsack Problem Define object o i with profit p i > 0 and weight w i > 0, for 1 ≤ i ≤ n. Given n objects and a knapsack capacity C> 0, the problem is to select a subset of objects with largest total profit and with total weight at most C . In other words, Maximize ∑ n i=1 p i x i Subject to ∑ n i=1 w i x i ≤ C . x i ∈{0, 1} ∀i UCSB TG
22
Embed
0-1 Knapsack Problem - sites.cs.ucsb.eduteo/cs230.f14/kp.pdf · CS 230A KP-0 0-1 Knapsack Problem Define object oi with profit pi > 0 and weight wi > 0, for 1 ≤ i ≤ n. Given
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
CS 230A KP-0✬
✫
✩
✪
0-1 Knapsack Problem
Define object oi with profit pi > 0 and weight
wi > 0, for 1 ≤ i ≤ n.
Given n objects and a knapsack capacity C > 0,
the problem is to select a subset of objects
with largest total profit and with total weight
at most C.
In other words,
Maximize∑n
i=1pixi
Subject to∑n
i=1wixi ≤ C.
xi ∈ {0, 1} ∀i
UCSB TG
CS 230A KP-1✬
✫
✩
✪
Example
Object Profit Weight
textbook 10 1
computer 50 10
ipod 8 3
iphone 22 4
pen 5 1
beer ?? 3
C = 15
UCSB TG
CS 230A KP-2✬
✫
✩
✪
Greedy Criterion
GC1: From the remaining objects, select one
with largest profit that fits into the knapsack.
Counter-example with n = 3.
C = 105 o1 o2 o3
Weight 100 10 10
Profit 20 15 15
GC2: From the remaining objects, select one
with smallest weight that fits into the
knapsack.
Counter-example with n = 3.
C = 25 o1 o2 o3
Weight 10 20 10
Profit 5 100 5
UCSB TG
CS 230A KP-3✬
✫
✩
✪
GC3: From the remaining objects, select one
with largest pi/wi that fits into the knapsack.
Counter-example with n = 3.
C = 30 o1 o2 o3
Weight 20 15 15
Profit 40 25 25
pi/wi 2 < 2 < 2
UCSB TG
CS 230A KP-4✬
✫
✩
✪
Approximations Via Rounding
Rounding Factor: δ(n, ǫ), where n is the problem
size and ǫ is the error.
δ(n, ǫ) is also called δ.
Let α be a positive value
Round up α means ... ⌈α
δ⌉
Round down α means ... ⌊α
δ⌋
Randomized Rounding means
Round up with prob. [αδ]
Round down with prob. 1− [αδ],
where [αδ] is fractional part of α
δ.
e.g., α = 7 and δ = 4
[ 74] → [ 3
4] so
Round to 2 with prob. .75, and
Round to 1 with probability .25.
UCSB TG
CS 230A KP-5✬
✫
✩
✪
Knapsack Instance (pi = wi ∀i)
C = 27 o1 o2 o3 o4 o5
pi and wi 1 2 4 8 16
Optimal xi 1 1 0 1 1
I.e., x1 = x2 = x4 = x5 = 1 and x3 = 0
Optimal solution can be found (next slides) in
O(min{2n, nF̃ , nC}) time, where F̃ is the
profit in an optimal solution.
UCSB TG
CS 230A KP-6✬
✫
✩
✪
Profit-Weight Pairs
Profit-Weight pairs are used to represent feasible