• Nie Znaleziono Wyników

The knapsack problem Formulation. Given (i) m ∈ N, (ii) volumes a

N/A
N/A
Protected

Academic year: 2021

Share "The knapsack problem Formulation. Given (i) m ∈ N, (ii) volumes a"

Copied!
7
0
0

Pełen tekst

(1)

Formulation. Given (i) m ∈ N,

(ii) volumes a1, . . . , am > 0, (iii) values c1, . . . , cm > 0, (iv) the total volume b, find

max m

i=1cixi

subject to m

i=1aixi � b, where xi ∈ N ∪ {0}.

Binary version: As above but here xi ∈ {0, 1}.

Assumptions: ai, b ∈ N, ai are pairwise different.

Notation. For k � m and y ∈ {0, 1, . . . , b} write F(k, y) = max

k

i=1cixi : k

i=1aixi � y, xi ∈ N

. Recurrence formula.

F(k, y) = max (F (k − 1, y), ck + F (k, y − ak))

1

(2)

Example

max 5x1 + 10x2 + 12x3 + 6x4

subject to 4x1 + 7x2 + 9x3 + 5x4 � 15

F(k, y) = max (F (k − 1, y), ck + F (k, y − ak))

k / y 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 0 0 0 0 5 5 5 5 10 10 10 10 15 15 15 15 2 0 0 0 0 5 5 5 10 10 10 10 15 15 15 20 20 3 0 0 0 0 5 5 5 10 10 12 12 15 15 17 20 20 4 0 0 0 0 5 6 6 10 10 12 12 15 16 17 20 20

(3)

Approximating the optimal solution1

Naive approach. Assume c1 � c2 � . . .. Set x1 =

b a1

x2 =

b− a1x1

a2

, x3 =

b− a1x1 − a2x2

a3

and so on.

Example. Let θ ∈ N.

max(θx1 + (θ − 1)x2) subject to θx1 + x2 � θ.

The optimal solution is (0, α) giving the value θ(θ − 1).

The naive solution is (1, 0) giving θ.

1Here we use 15.083J Integer Programming and Combinatorial Optimization from MIT OpenCourseWare.

(4)

Less naive approach

Greedy Algorithm Assume c1/a1 � c2/a2 � . . .. Set x1 =

b a1

x2 =

b− a1x1 a2

, x3 =

b− a1x1 − a2x2 a3

and so on.

Example. Let θ ∈ N.

max(2θx1 + 2(θ − 1)x2)

subject to θx1 + (θ − 1)x2 � 2(θ − 1).

The optimal solution is (0, 2) giving the value vopt = 4(θ−1).

The greedy solution is (1, 0) giving vgreedy = 2θ.

vgreedy/vopt = θ/(2θ − 1) → 1/2.

(5)

Asymptotic optimal solutions

Definition. Given ε > 0, a feasinle vector x is ε-optimal if c · x � (1 − ε)c · x,

where x is an optimal solution.

The above condition is equivalent to c · x − c · x

c · x � ε.

Theorem. If x is given by Greedy Axiom then x is 1/2- optimal.

Proof.

c· x � c1x1 = c1

b a1

c· x � c1 b

a1 � c1

b a1

+ 1

� 2c1

b a1

� 2c · x.

(6)

Binary knapsack

Formulation. Given (i) m ∈ N,

(ii) volumes a1, . . . , am > 0, (iii) values c1, . . . , cm > 0, (iv) the total volume b, find

max m

i=1cixi

subject to m

i=1aixi � b, where xi ∈ {0, 1}.

Notation. For k � m and y ∈ {0, 1, . . . , b} write F(k, y) = max

k

i=1cixi : k

i=1aixi � y, xi ∈ N

. Recurrence formula.

F(k, y) = max (F (k − 1, y), ck + F (k − 1, y − ak))

Remark. Write cmax = maxi�m ci.

Using the formula we need cmaxm2 operations do solve the problem

(7)

Approximating binary knapsack

Theorem. An ε-optimal solution of a binary klapsack pro- blem can be found after 10m3 steps.

Fix some natural number t and let cibe ciwith the last t digits replaced by 0. Moreover, ci = ci

10t.

Let S, S be the optimal choices for ci’s and ci giving the values v and v, respectively.

Then

i∈S

ci

i∈S

ci

i∈S

ci

i∈S

ci

i∈S

(ci− 10t) =

i∈S

ci− m10t. Hence

v − v

v m10t cmax.

Fix ε > 0. If m/cmax > ε then we apply the exact algorithm requiring m2cmax so at most m3 operations.

Otherwise, choose t such that ε

10 � m10t

cmax < ε.

Then we apply the exact algorithm for the prices ci. Note that cmax= 1

10tcmax 1

10tcmax� 10m/ε, so we need

m2cmax 10m3 ε , operations.

Cytaty

Powiązane dokumenty

Г In the compensating computation the so-called compensation of the direct conditioned observations leads to looking for corrections V fulfilling conditions (3),

The levels of such parameters characterizing dynamic loads and overloads of examined movement structures as: maximal and average values of vertical ground reaction forces, total

W miarę upływu czasu zmniejsza się strumień odparowania, zarazem mniejsza ilość ciepła jest pobierana na odparowanie fazy ciekłej, w konsekwencji temperatura

NNB parent (a non-native bilingual parent) – in the context of the research on NNB in Poland it means a person who, while being a Pole and living in Poland, talks to the child in

Applying the simplex method with this point as starting one, we shall obtain a solution of the problem (30)- (31) within …nite steps (from Theorem 2 it follows that inf. u2U J (u)

Algorithm of Gilmore and

The co-operation of parallel simulated annealing processes to solve the vehicle routing problem with time windows (VRPTW) is considered.. The objective is to investigate how the

The algorithm finishes if the number of generations in the steady state is larger than the defined maximum, maximal number of generations maxGen is reached or the maximal