Vous êtes sur la page 1sur 7

Binary Artificial Bee Colony Algorithm for Solving 0-1 Knapsack Problem

Liu Wei, Niu Ben, Chen Hanning

Binary Artificial Bee Colony Algorithm for Solving 0-1 Knapsack Problem
1,2

Liu Wei, 3Niu Ben, *2Chen Hanning


Jilin Normal University, Siping,136000,China,lwzxm1020@126.com
*2
Laboratory of Information Service and Intelligent Control, Shenyang Institute of
Automation, Chinese Academy of Sciences, Shenyang, 110016, China, chenhanning@sia.cn
3
College of Management, Shenzhen University, Shenzhen, 518060, China,
Drniuben@gmail.com
1

Abstract
In this paper, a binary artificial bee colony (BABC) algorithm is proposed to solve the 0-1
Knapsack problem. Unlike the original ABC algorithm, the proposed BABC represents a food source
as a discrete binary variable and applies discrete operators to change the foraging trajectories of the
employed bees, onlookers and scouts in the probability that a coordinate will take on a zero or one
value. To verify the performance of the proposed algorithms, we made a comparison between
algorithms of the proposed BABC with the standard binary particle swarm optimizer (BPSO) and the
genetic algorithm (BGA). The comparison results showed that the proposed algorithms outperform the
BPSO and BGA in terms of quality of solution found.

Keywords: 0-1 Knapsack Problem, Bee Colony, Swarm Intelligence


1. Introduction
The knapsack problem (KP) is a NP-hard problem [1]. It can be defined as follows:
Assuming that we have a knapsack with maximum capacity M and a set of n objects. Each
object i has a profit c i and a weight wi. The problem is to select a subset of items from the set of
n objects to maximize the value of all selected objects without exceeding the maximum capacity
of the knapsack. KP can be formulated as:
n

max f ( x) ci xi

(1)

i 1

g ( x) wi xi M 0
s.t.
i 1
x {0,1} (i 1, 2, , n)
i

(2)

KP has very important applications in financial and industry domain. Such as resource
distribution, investment decision-making, items shipment, budget controlling and projects
selection. Many methods have been used to solve the knapsack problem, such as dynamic
programming, greedy algorithm, genetic algorithm, ant colony optimization, and particle swarm
optimization (PSO). In this paper, we propose a binary artificial bee colony algorithm for
solving the 0-1 knapsack problem.
Recently, by modeling the cooperative foraging behaviors of honey bee colony, the artificial
bee colony (ABC) algorithm is developed by Karaboga [2]. ABC is a population-based SI
optimization tool, which could be implemented and applied easily to solve multi-variable and
multi-modal continuous functions. Due to its simplicity and efficiency, the ABC algorithm has
been applied to solve many practical optimization problems[3-5].
However, the original version of ABC algorithm is only able to optimize continuous
problems. Many optimization problems are set in a space featuring discrete, qualitative
distinctions between variables and between levels of variables. As any problem, discrete or
continuous, can be expressed in a binary notation, it is seen that an optimizer which operates on
two-valued functions might be advantageous. Hence, this paper aims at developing a novel
binary artificial bee colony (BABC) algorithm, which can solve general binary optimization
benchmarks and more complex real-word discrete problems. In the proposed binary ABC, we develop
a differential expression, in which the relevant variables are interpreted in terms of changes of

Advances in information Sciences and Service Sciences(AISS)


Volume4, Number22, Dec 2012
doi: 10.4156/AISS.vol4.issue22.57

464

Binary Artificial Bee Colony Algorithm for Solving 0-1 Knapsack Problem
Liu Wei, Niu Ben, Chen Hanning

probabilities that changed per iteration. The main feature of this new operator is that it works in binary
space, while still maintains the major characteristics of the original ABCs expression. In addition, in
order to restrict the bees positions within the range [0,1], the position clipping boundary condition
(PCBC) strategy is applied in the proposed model.
In order to test the potential of BABC algorithm for solving binary and discrete optimization
problems, we compared the performance of the BABC algorithm with that of discrete version of PSO
[6] and GA [7] on a set of KP tested cases with different numbers of items. The simulation results are
encouraging: the BABC algorithm has markedly superior search performance in terms of accuracy,
robustness and convergence speed on all tested instances.
The paper is organized as follows. Section 2 describes the proposed binary version of ABC
algorithm - BABC, including the discretized update formulas of employer, onlooker and scout, and the
algorithmic framework. In Section 3, the simulation results will be shown that BABC outperforms two
classical SI binary optimization tools on four KP cases. Finally, conclusions are drawn in Section 4.

2. Binary version of the ABC algorithm


The implementation of novel binary ABC algorithm consists of initialization, modification of
position by employed bees and onlooker bees and introduction of scout bees when there is no
improvement in the fitness function.

2.1. Initialization phase


In the proposed BABC model, food sources in a binary space exploited by bees represent possible
solutions to a given binary optimization problem. The amount of nectar represents the fitness function.
All foragers, that leave the hive to search for promising flower patches, may be seen to move to nearer
and farther corners of the hypercube by flipping various numbers of bits.
At the initialization stage, a set of food source positions are randomly selected by the bees. That is,
the bee colony is initialized randomly over the entire search space as follows:

xij (t 0) LB j (UB j LB j ) rand [0,1]


for i 1,2,..., N and j 1,2,..., D

(3)

where N is the number of bees in the colony; D is the dimensionality of the search space; LBj
and UBj are the lower and upper bounds for the dimension j that are assigned 0 and 1
respectively in the binary space; rand[0,1] is a binary value randomly selected from binary
values 0 and 1. At the position of the food source x i discovered by the i th bee, each bit is
completely random, hence the first created solution is uniformly distributed over {0, 1}D .

2.2. Employed bee phase


After all the bees return to the hive with a certain amount of nectar, the first half (SN) that
found the best food sources become employed bees. At this stage, each employed bee x i
generates a new food source v i in the neighborhood of its present position as follows.

vij (t ) xij (t 1) ij ( xkj (t 1) xij (t 1))

(4)

for j 1,2,..., D
where k (1, 2,..., SN) and j (1, 2,..., D) are randomly chosen indexes, and ki. ij is a
random number generated in the range ( 1, 1). In sum, the employed bee formula remains
unchanged in the proposed binary ABC, except that now xij and x kj are integers in {0, l} and
each bit of x i will be updated simultaneously.

465

Binary Artificial Bee Colony Algorithm for Solving 0-1 Knapsack Problem
Liu Wei, Niu Ben, Chen Hanning

Table 1. Pseudocode for BABC algorithm.


procedure BABC
generate 2*NS random binary solutions X1, X2,., X2NS
best_sol := best solution among X1, X2,., XNS
repeat
for i:=1 to NS do
for j:=1 to D do
/* Employer Phase */
Xe:= Generate_Neighboring_Solution(Xij)
if (Xe is worse than Xij) then
Xij dont change
else if (Xe is better than Xij) then
Xij := Xe
end for
if (Xi has not changed over last Limit iterations) then
/* Scout Phase */
replace Xi with a random solution
if (Xi is better than best_sol) then
best_sol := Xi
end for
for i:= 1 to NS do
ki := Select_and_Return_Index(X1, X2,., XNS)
/* Onlooker Phase */
for j:=1 to D do
Xo := Generate_Neighboring_Solution( Xkij )
if (Xo is worse than Xkij) then
Xkij dont change
else if (Xo is better than Xkij) then
Xki := Xo
end for
if (Xki is better than best_sol) then
best_sol := Xki
end for
until (termination condition is satisfied)
return best_sol
end procedure
In order to restrict the bees positions within the range [0,1], A normalization method and a
threshold level has to be introduced to map all real valued numbers of v ij to the range [0,1]. The
round function and the position clipping boundary condition (PCBC) can be used to accomplish
this last modification. The resulting change in position then is defined by the following rule:

xije (t ) round (vij (t ))

PCBC:

(5)

if xije (t ) UB, then xije (t ) UB


else if xije (t ) LB, then xije (t ) LB

(6)

Here the round () function rounds the elements of v ij to the nearest integers and the PCBC
strategy handles the bounded search space. Once the new food source x i(t) is obtained, it will be
evaluated and compared to x i(t-1). If the fitness of x i(t) is equal to or better than that of x i(t-1),
x i(t) will replace x i(t-1) and become a new member of the population; otherwise x i(t) is retained.
In other words, a greedy selection mechanism is employed as the selection operation between
the old and the current food sources.

466

Binary Artificial Bee Colony Algorithm for Solving 0-1 Knapsack Problem
Liu Wei, Niu Ben, Chen Hanning

2.3. Onlooker bee phase


The remainder of the bees (onlooker bees) watches the waggle dance to decide which of the
employed bees should be followed. An onlooker bee selects a food source found by the employed bee
xi depending on its probability value pi calculated by the following expression:
(7)
fiti

pi

SN

fit
i 1

where f i is the nectar amount (i.e., the fitness value) of the i th food source. Obviously, the
numbers of onlooker bees that will fly to a food source depend upon the amount of nectar at the
source. This means that the higher the f i is, the more probability that the ith food source is
selected.
Once the onlooker has selected her food source found by the employed bee x i, she produces a
modification on the position xi by using Eq. (4-5). As in the case of the employed bees, if the
modified food source has a better or equal nectar amount than x i, the modified food source will
replace xi and become a new member in the population.

2.4. Scout bee phase


In this stage, a random selection process carried out by the scout bees to explore new potential food
sources. This is simulated as: if a position cannot be improved further through a predetermined number
of cycles called limit, then the food source is assumed to be abandoned, and the corresponding
employed bee becomes a scout that randomly reinitializes in the fitness landscape. The pseudocode of
BABC framework is illustrated in Table 1.

3. Experimental result
To verify and compare the performance of the proposed BABC, the classical BGA and BPSO
algorithms, four instances with different numbers of items were generated. In the first instance
the number n of objects is equal to 20, in the second instance n = 50, in the third one n = 80 and
100 in the fourth instance. The item profit set, item capacity set, and knapsack capacity for each
tested instance is as follows:
1 KP20
Item profit set:
{92,4,43,83,84,68,92,82,6,44,32,18,56,83,25,96,70,48,14,58}

Item capacity set:


{44,46,90,72,91,40,75,35,8,54,78,40,77,15,61,17,75,29,75,63}
Knapsack capacity: 878
2 KP50
Item profit set:
{220, 208, 198, 192, 180, 180, 165,162, 160, 158, 155, 130, 125, 122, 120, 118,115, 110,
105, 101, 100, 100, 98, 96, 95,90, 88, 82, 80, 77, 75, 73, 72, 70, 69, 66,65, 63, 60, 58, 56,
50, 30, 20, 15, 10, 8,5, 3, 1}
Item capacity set:
{80, 82, 85, 70, 72, 70, 66, 50,55, 25, 50, 55, 40, 48, 50, 32, 22, 60, 30,32, 40, 38, 35, 32,
25, 28, 30, 22, 50, 30,45, 30, 60, 50, 20, 65, 20, 25, 30, 10, 20,25, 15, 10, 10, 10, 4, 4, 2, 1}
Knapsack capacity: 1000
3 KP 80
Item profit set:

467

Binary Artificial Bee Colony Algorithm for Solving 0-1 Knapsack Problem
Liu Wei, Niu Ben, Chen Hanning

{199,194,193,191,189,178,174,169,164,164,161,158,157,154,152,152,149,142,131,125,12
4,124,124,122,119,116,114,113,111,110,109,100,97,94,91,82,82,81,80,80,80,79,77,76,74,7
2,71,70,69,68,65,65,61,56,55,54,53,47,47,46,41,36,34,32,32,30,29,29,26,25,23,22,20,11,10
,9,5,4,3,1}

Item capacity set:


{40,27,5,21,51,16,42,18,52,28,57,34,44,43,52,55,53,42,47,56,57,44,16,2,12,9,40,23,56,3,3
9,16,54,36,52,5,53,48,23,47,41,49,22,42,10,16,53,58,40,1,43,56,40,32,44,35,37,45,52,56,4
0,2,23,49,50,26,11,35,32,34,58,6,52,26,31,23,4,52,53,19}
Knapsack capacity: 1173
4 KP100:
Item profit set:
{297,295,293,292,291,289,284,284,283,283,281,280,279,277,276,275,273,264,260,257,25
0,236,236,235,235,233,232,232,228,218,217,214,211,208,205,204,203,201,196,194,193,19
3,192,191,190,187,187,184,184,184,181,179,176,173,172,171,160,128,123,114,113,107,10
5,101,100,100,99,98,97,94,94,93,91,80,74,73,72,63,63,62,61,60,56,53,52,50,48,46,40,40,3
5,28,22,22,18,15,12,11,6,5}
Item capacity set:
{54,95,36,18,4,71,83,16,27,84,88,45,94,64,14,80,4,23,75,36,90,20,77,32,58,6,14,86,84,59,
71,21,30,22,96,49,81,48,37,28,6,84,19,55,88,38,51,52,79,55,70,53,64,99,61,86,1,64,32,60,
42,45,34,22,49,37,33,1,78,43,85,24,96,32,99,57,23,8,10,74,59,89,95,40,46,65,6,89,84,83,6,
19,45,59,26,13,8,26,5,9}
Knapsack capacity: 3820
Table 2. Results comparison of three algorithms on all tested cases for 30 runs.
Problem
KP20
KP50
KP80
KP100
Algorithm
Best
1042
3110
5183
15170
Mean
1.0397e+003
3.0875e+003
5.1477e+003
1.5093e+004
BABC
Std
3.1873
13.2546
29.3876
66.3560
Best
1042
3112
5183
15158
Mean
1.0400e+003
3.0931e+003
5.1326e+003
1.5104e+004
BPSO
Std
2.7611
13.2362
34.6950
47.0648
Best
995
2868
4517
14095
Mean
1.0343e+003
2.9934e+003
4.8246e+003
1.4668e+004
BGA
Std
10.8742
45.4066
120.5343
170.2395
The population size for all algorithms was set at 60. The max generation of each run is 100. For
BABC, the Limit parameter was set to be 4. For BGA, single point crossover operation with the rate of
0.8 was employed and mutation rate was set to be 0.01 [8]. For BPSO, the learning rate parameters
were set to the values c1= c2=2 and the inertia weight w=1 [9].
The experimental results, including the best, mean and standard deviation of the function values
found in 30 runs are proposed in Table 2. The mean convergence results of four KP instances with
different items are showed in Fig.1.

468

Binary Artificial Bee Colony Algorithm for Solving 0-1 Knapsack Problem
Liu Wei, Niu Ben, Chen Hanning

KP50a Problem
3100

1000

3000
Value

Value

KP20 Problem
1050

950
BABC
BGA
BPSO

900

850
0

50
100
Generations

2900
BABC
BGA
BPSO

2800

2700
0

150

50
100
Generations

(a) KP20

150

(b) KP50

KP80 Problem

KP100 Problem

5500

1.6

x 10

1.5

5000

Value

Value

1.4
4500
4000

3000
0

1.2

BABC
BGA
BPSO

3500

50
100
Generations

(c) KP80

1.3
BABC
BGA
BPSO

1.1
150

1
0

20

40

60
80
Generations

100

120

(d) KP100

Figure 1. The median convergence characteristics on all tested cases for 30 runs.
From all the results for the four KP instances, we can observe that the BABC algorithm obtain an
obviously remarkable performance. We can see it clearly that the BABC converged greatly faster and
to significantly better results than the BPSO and BGA on all instances.
For the KP20 problem, all the algorithms are able to consistently find the minimum within 100
generations.
For KP50 and KP80 problems, the BABC and BGA clearly do not suffer from premature
convergence. In the 100 generations of the test runs on KP100, the BABC continues to find better
results even after the BGA and BPSO seem to have stagnated. It should be mentioned that the BABC is
able to consistently find the minimum of all the KP instances.
In fact, with an increasing in the number of the items, the problem of finding best KP solution
becomes intractable. However, it can be see cleanly, our proposed method is able to find the optimal
results of the larger scale KP problems robustly and consistently.

4. Conclusions
Since the original ABC algorithm cannot be directly applied to solve knapsack problem, this paper
proposed a novel discrete artificial bee colony algorithm BABC. The BABC model can be applied in
binary work space, while still maintains the major characteristics of the original ABCs expression.
From the simulation results, it is concluded that the performance of the proposed algorithm is better
than BGA and BPSO on four instances of knapsack problem.

469

Binary Artificial Bee Colony Algorithm for Solving 0-1 Knapsack Problem
Liu Wei, Niu Ben, Chen Hanning

The Future work should focus on how practically useful the BABC algorithm are for engineering
optimization problems. These depend on extensive evaluation on many benchmark functions and realworld problems.

5. Acknowledgements
This work was supported in part by the Natural Science Foundation of China under Grant 61105067,
71001072, 71271140 and 61174164.

6. References
[1] D. Pisinger, Where are The Hard Knapsack Problems? Computers and Operations Research, vol.
32, no.9, pp. 2271-2284, 2005.
[2] D.Karaboga, B.Basturk, On the Performance of Artificial Bee Colony (ABC) algorithm, Applied
Soft Computing, vol.8, pp. 687-697, 2008.
[3] W.Y. Qi, H. Shen, H.N. Chen, A Discrete Artificial Bee Colony Algorithm for RFID Network
Scheduling, International Journal of Advancements in Computing Technology, vol.4, no.14, pp.
324 - 332, 2012.
[4] D. Karaboga, B. Basturk Akay, Artificial Bee Colony Algorithm on Training Artificial Neural
Networks, Proceeding of 15th. Signal Processing and Communications Applications, pp.1-4,
2008.
[5] D. Karaboga, C. Ozturk, A novel clustering approach: Artificial Bee Colony (ABC) algorithm,
Applied Soft Computing, vol.11, no.1, pp. 652-657, 2011.
[6] J. Kennedy, R. C. Eberchart, Y. Shi, Swarm intelligence, Morgan Kaufmann Publishers, San
Francisco, 2001.
[7] S. Sumathi, T. Hamsapriya, P. Surekha, Evolutionary Intelligence: An Introduction to Theory and
Applications with Matlab, Springer, 2008.
[8] Liu W., Chen H.N., BABC: A Binary Version of Artificial Bee Colony Algorithm for Discrete
Optimization, International Journal of Advancements in Computing Technology, vol.4, no.14, pp.
307-314, 2012.
[9] Chen, H. N., Zhu, Y. L., Hu, K. Y., Discrete and Continuous Optimization based on Multi-swarm
Coevolution, Natural Computing, vol.9, no.3, pp. 659-682, 2010.

470

Vous aimerez peut-être aussi