<< Solvers Solvers pipe_network >>

metanet >> metanet > Solvers > knapsack

knapsack

solves a 0-1 multiple knapsack problem

Calling Sequence

[earn,ind] = knapsack(profit,weight,capa,[bck])

Parameters

profit

integer row vector

weight

integer row vector

capa

integer row vector

bck

integer

earn

integer

ind

integer row vector

Description

The 0-1 multiple knapsack problem with n (n >= 2) items and m knapsacks (m >= 1) is defined as follow:

Maximize the global profit E=profit*sum(X,1) under the constraints:

X*weight <= capa

sum(X,1) <= 1 ; i=1,...,n

X(j,i)= 0 or 1

Where

profit

is the vector of the "profits" of the n items. The entries must be positive integers.

weight

is the vector of the corresponding "weights". The entries must be positive integers.

capa

is the vector of the (integer) capacities of the m knapsacks.The entries must be positive integers.

X

is a m by n matrix.

est une matrice m par n à valeurs dans {0,1}.

[earn,ind] = knapsack(profit,weight,capa) solves the problem. It returns in

earn

the value of the criterium E for the "optimal" solution if it has been found. In case of error, earn is assigned to a negative value:

-3

means that a knapsack cannot contain any item.

-4

means that an item cannot fit into any knapsack.

-5

means that a knapsack contains all the items.

ind

the integer vector of the knapsack number where item i is inserted and this value is 0 if the item i is not in the optimal solution. The matrix X can be derived from ind by

items=1:n;
items(ind==0)==[];
ind(ind==0)=[];
X=sparse([ind;items]',ones(n,1),[m,n])
bck

is an optional integer: the maximum number of backtrackings to be performed if heuristic solution is required. If the exact solution is required bck must be omitted or assigned to a negative value.

Examples

weight=ones(1,15).*.[1:4];
profit=ones(1,60);
capa=[15 40 30 60];
[earn,ind]=knapsack(profit,weight,capa)

items=1:60;
items(ind==0)=[];
ind(ind==0)=[];
X=full(sparse([ind;items]',ones(ind),[4,60])) //one row per sacks
X*weight' //sack weights
x=sum(X,1);
and(x<=1) //contraints check
profit*x'==earn

See Also

Bibliography

Coppersmith, D. "Knapsack Used in Factoring." §4.6 in Open Problems in Communication and Computation (Ed. T. M. Cover and B. Gopinath). New York: Springer-Verlag, pp. 117-119, 1987.

Honsberger, R. Mathematical Gems III. Washington, DC: Math. Assoc. Amer., pp. 163-166, 1985.


<< Solvers Solvers pipe_network >>