Professional Documents
Culture Documents
problems. In its basic version, we are given a number of items from which we are required to
select a subset to carry in a fixed capacity knapsack. Items differ by their value and their required
place in the knapsack. The aim is to load items that maximize the overall reward without
exceeding the capacity.
The Solution is to be announced as
Maximize
Subject to:
Input
Weight Ai
Profit Pi
Knapsack capacity C
Output
The total max value from the best choice of
Item
Decision Variable
=1 if Selected
Problem Solution
1) Example 1
Item
1
P
9
A
47
K=187
2
12
6
3
95
23
4
69
1
5
27
43
6
98
3
7
91
31
8
47
41
9
41
36
10
74
16
a) Mathematical solution
max= 9*x1 +12*x2+ 95*x3 + 69*x4 +27*x5 +98*x6 +91*x7 +47*x8 +41*x9 +74*x10;
!subject to;
47*x1 +6* x2+ 23*x3 + 1*x4 +43*x5+3*x6+ 31* x7+ 41*x8+ 36*x9+ 16*x10 <=187;
b) The Inputs and outputs
Input
Weight Ai
Profit Pi
Knapsack capacity C =187
Output
The total max value from the best choice of
Item
Z(X)
9*x1
+12*x2+
95*x3
+6*
ii.
Max
x2+
23*x3<=187
Z(X)=
47*x8
+41*x9
=162
Subject to the knapsack capacity
41*x8+ 36*x9+ 16*x10 <=187
93<=187
e) Solving with lingo
max= 9*x1 +12*x2+ 95*x3 + 69*x4 +27*x5 +98*x6 +91*x7 +47*x8 +41*x9 +74*x10;
!subject to;
47*x1 +6* x2+ 23*x3 + 1*x4 +43*x5+3*x6+ 31* x7+ 41*x8+ 36*x9+ 16*x10 <=187;
@bin(x1);
@bin(x2);
@bin(x3);
@bin(x4);
@bin(x5);
@bin(x6);
@bin(x7);
@bin(x8);
@bin(x9);
@bin(x10);
+74*x10
f) Result Interpretation
Optimal solution: the resolution of the 0-1 KP yields to the optimal solution xi= (0, 1, 1, 1, 0, 1,
1, 1, 1,1). The objective function Z (Xi) = 527.
2) Example 2
a) Mathematical formulation
Max=19*x1+24*x2+15*x3+20*x4+25*x5;
Subject to:
16*x1+26*x2+12*x3+5*x4+13*x5<=50;
Output
The total max value from the best choice of
Item
Xi=1 if Selected
Xi=0 Otherwise
d) Feasible solutions
i) Let x1,x2,x4 =1 and x3,x5=0
Z (X)= 63
ii) Let x3,x4,x5 =1 and x1,x2 =0
Z (X)=75
e) Solving with lingo
f) Result Interpretation
Optimal solution: the resolution of the 0-1 KP yields to the optimal solution x = (1, 0, 1, 1,
1). The objective function Z (Xi) = 79.
3) Example 3
a) Mathematical function
Max=4*x1+12*x2+18*x3+15*x4+20*x5+8*x6+21*x7+17*x8;
Subject to: 50*x1+26*x2+23*x3+8*x4+23*x5+3*x6+24*x7+41*x8<=120;
Output
The total max value from the best choice of
Item
Xi=1 if Selected
Xi=0 Otherwise
d) Feasible Solutions
i) Let x1,x2,x3,x4,x5 =1 and x6,x7,x8 =0
Z(x) = 120
ii) Let x1, x8=1 and x2, ..., x7=0
Z(X) =21
e) Solving with Lingo
f) Result Interpretation
Optimal solution: the resolution of the 0-1 KP yields to the optimal solution xi = (0, 1, 1, 1,
1, 1, 1, 0). The objective function Z (Xi) = 94.
In fact, the KP models is used in a wide range of industrial situations belonging to the domains
of transportation as cargo loading, cutting stock, telecommunication, reliability, advertisement,
budget allocation and financial management.