Professional Documents
Culture Documents
Knapsack
Knapsack
Knapsack
net/publication/301409726
Solving the 0–1 Knapsack problem using Genetic Algorithm and Rough Set
Theory
CITATIONS READS
5 5,917
3 authors, including:
Tribikram Pradhan
Indian Institute of Technology (Banaras Hindu University) Varanasi
40 PUBLICATIONS 318 CITATIONS
SEE PROFILE
All content following this page was uploaded by Tribikram Pradhan on 01 February 2020.
Abstract-This paper describes a hybrid algorithm to solve evaluated; the fitness is usually the value of the objective
the 0-1 Knapsack Problem using the Genetic Algorithm function in the optimization problem being solved. The more
combined with Rough Set Theory. The Knapsack problem is a fit individuals are selected from the current population, and
combinatorial optimization problem where one has to maximize
each individual's genome is modified (recombined and
the benefit of objects in a knapsack without exceeding its
possibly randomly mutated) to form a new generation. The
capacity. There are other ways to solve this problem, namely
Dynamic Programming and Greedy Method, but they are not
new generation of candidate solutions is then used in the next
very efficient. The complexity of Dynamic approach is of the iteration of the algorithm. Commonly, the algorithm
3 terminates when either a maximum number of generations has
order of 0(n ) whereas the Greedy Method doesn't always
l2 1 been produced, or a satisfactory fitness level has been reached
converge to an optimum solution • The Genetic Algorithm
provides a way to solve the knapsack problem in linear time for the population. Each iteration of the algorithm is called
l21
complexity . The attribute reduction technique which generation.
incorporates Rough Set Theory finds the important genes, hence
reducing the search space and ensures that the effective C Rough Set Theory
information will not be lost. The inclusion of Rough Set Theory In the ordinary set theory, crisp sets are used. A set is then
in the Genetic Algorithm is able to improve its searching
defined uniquely by its elements, i.e., to define a set we have
efficiency and quality.
to point out its elements. The membership function, describing
Keywords-Genetic Algorithm (GA), Rough Set Theory, Attribute
the belongingness of elements of the universe to the set, can
4
reduction Techniques, Knapsack Problem, 0-1 Knapsack attain one of the two values, 0 or 1 [ 1. 1 indicates that the
Problem. element belongs to the set and 0 indicates that it does not.
Item (X) A B C indicates that the 1st and the 3rd item (A and C) are included
Profit (P) 4 3 5 in the knapsack.
Wight (W) 6 7 8
Fitness Function: GAs require a fitness function which
We seek to maximize the total benefit: allocates a score to each chromosome in the current
population. Thus, it can calculate how well the solutions are
coded and how well they solve the problem. For solving the
I Pi Xi = 4X1 + 3X2 + 5X3
i�' 0-1 knapsack problem using genetic algorithm, the fitness
Subject to the constraints: function of a chromosome is the total profit of the
chromosome. For example, consider the chromosome:
I Wi Xi = 6X, + 7X2 + 8X3 ::; 13
Fl A B C
o
And
Xi € {0,1} ; for i = 1, 2, . . . , n.
The profit values of A, B and C are 4, 3 and 5 respectively.
3 Since only A and B are included in the knapsack, the fitness of
For this problem there are 2 = 8 possible ways to select items:
the above chromosome will be the sum of the profit of A and
A B C Total Total B. Hence, we have:
Weight Profit Fitness of the chromosome = 4 + 3 = 7.
0 0 0 0 0
Selection: The selection process is based on fitness.
0 0 1 8 5
Chromosomes that are evaluated with higher fitness values
0 1 0 7 3
will most likely be selected to reproduce, whereas, those with
0 1 1 15 -
low values will be discarded. The fittest chromosomes may be
1 0 0 6 4
selected several times, however, the number of chromosomes
1 0 1 14 -
selected to reproduce is equal to the population size, therefore,
1 1 0 13 7
keeping the size constant for every generation. This phase has
1 1 1 21 - an element of randomness just like the survival of organisms
in nature. There are different types of selection methods. In
In order to find the best solution we have to identify a subset our implementation, we have used roulette- wheel selection.
that meets the constraint and has the maximum total benefit. In
our case, only rows given in italics satisfy the constraint. Crossover: Crossover is analogous to biological reproduction.
Hence, the optimal benefit for the given constraint can only be It is the process of combining the bits of one chromosome
obtained with one quantity of A, one quantity of B, and zero with those of another. This is to create an offspring for the
quantity of C, and it is 7. Thus, the row in bold is the solution. next generation that inherits traits of both parents. Crossover
randomly chooses a locus and exchanges the subsequences
B. Basic Elements of the Genetic Algorithm before and after that locus between two chromosomes to
create two offspring. For example, consider the following
Most GA methods are based on the following elements:
parent chromosomes and a crossover point at position 3:
populations of chromosomes, selection according to fitness,
crossover to produce new offspring, and random mutation
Parent 1 : 1 0 01 0 1 1 1
of new offspring.
Parent 2 : 1 1 11 1 0 0 0
Offspring 1 : 100 1000
Chromosomes: The chromosomes in GAs represent the space
Offspring 2 : 111 0111
of candidate solutions. There are many types of chromosome
encodings. For the Knapsack problem, we use binary
encoding, where every chromosome is a string of bits, 0 or 1.
1121
2014 IEEE International Conference on Advanced Communication Control and Computing Technologies (lCACCCT)
Mutation: It is analogous to biological mutation. It changes rough set theory) is carried out after every iteration of the
the new offspring by flipping bits from 1 to 0 or from 0 to 1. It genetic algorithm.
is done to maintain genetic diversity from one generation of a
population of genetic algorithm chromosomes to the next.
For example, consider the following chromosome with
mutation point at position 2:
1122
2014 IEEE International Conference on Advanced Communication Control and Computing Technologies (lCACCCT)
h
The 6th, i , 9th and 10th rows are unfit chromosomes as their U/ind(C-C,)= {{l,2,15,17}, {3,4,19}, {5,13}, {6,16}, {7,9},
total weight exceeds the capacity of the knapsack, so they are {8,14}, {l8,20}}
not included in Table 2. Pos{c.cl}(D) = {2,3,6,11,16} (5 items in Group 1)
Therefore, the importance of C 1:
TABLE 2. CROSSOVER AND MUTAnON
O)e1 = 1 - (5/20) = 15/20 = 314 = 0.75
Crossover Crossover Mutation Fitness Group
Index (C) (D)
0001 2 0001 0101 3 2 TABLE 4. REMOVING C2
1001 2 1001 1000 8 2
1010 3 1011 1001 10 2 S.no C-C2 Crossover Mutation Fitness Group
0101 3 0100 OlIO 5 I (C) (D)
1 001 101 001 2 2
1000 I 1011 1001 10 2
0011 I 0000 0100 I I 2 101 001 101 10 1
1100 2 1110 1010 12 2
3 010 010 110 12 I
0010 2 0000 0100 I I
4 110 110 010 4 2
Crossover and mutation are carried out. The fit items are put 5 001 101 III 14 2
in group 1 and unfit ones are put in group 2. We analyze the 6 100 000 001 2 2
relationship between the gene position and the fitness function 7 OIl 010 110 12 I
by using the concepts of positive region and attribute 8 100 101 III 14 2
importance. Then the important genes (attributes) are found.
9 III III 110 12 I
10 III III 101 10 I
U 1 ind(C) = {{l},{2},{3},{4},{5}, {6},{7},{8}}
U 1 ind(D) = {{1,2, 3,5, 7}, {4, 6,8}} II OIl 010 110 12 I
112 3
2014 IEEE International Conference on Advanced Communication Control and Computing Technologies (lCACCCT)
14 100 000 010 I 2 VI. IMPLEMENTAnON
15 101 100 101 10 I
16 010 OIl III II I
Figure 2 shows the snapshot of the application designed to
17 101 001 OIl 3 2
implement the hybrid algoritlun. The application works for 4
18 010 110 III 11 1
items in the knapsack. It takes the weight and profit values of
19 100 100 000 0 2
the items as the input and displays the optimal solution along
20 010 010 000 0 2 with the items included in the knapsack.
Qj
> 2
ct
We know that keeping the most important attributes (genes) as 0
1 is a good choice. The most important attribute is Ct.
0 5 10 15 20 25 30
Keeping C,=1 gives the chromosome 1000, which is a
solution. C3 is the second most important attribute. Keeping No. of generations
C,=l and C3=1 gives the chromosome 1010, which is the
optimal solution. Hence, knowing which attribute is important
reduces the search space and helps to find the optimal
F'GURE 3. GRAPH FOR COMPARING GA AND THE HYBRID APPROACH
solution.
1124
2014 IEEE International Conference on Advanced Communication Control and Computing Technologies (lCACCCT)
Algorithm (GA) indicated by the blue line, and the Genetic [8] D.E. Goldberg. Genetic Algorithms in Search, Optimization, and
Machine Learning. (Addison-Wesley, New York, 1989).
Algorithm and Rough Set Theory Hybrid algorithm, indicated
[9] 1.H. Holland. Adaptation in Natural and Artificial Systems (University of
by the red line. The y-axis shows the average fitness value of
MichiganPress,1975;MlT,London,1992).
the chromosomes in one generation and the x-axis shows the
number of generations. As shown in the figure, the hybrid
algorithm produced the optimal solution in the 15th generation
whereas the genetic algorithm did the same in the 25th
generation. Also, the hybrid approach produced a better
solution than the genetic algorithm, as indicated by the higher
fitness values achieved by the hybrid approach.
REFERENCES
[I] Ritika Mahajan and Sarvesh Chopra. Analysis of Oil knapsack problem
using deterministic and probabilistic techniques. In Proc. IEEE
International Conference on Advanced Computing and Communication
Technologies (ACCI' 12), pages 150-155, Rohtak, Haryana, January
2012.
[2] R.P. Singh. Solving the 0-1 knapsack problem using genetic algorithm.
In Proc. International conference on Communication software and
Networks (lCCSN' II), pages 591-595, Xian,China, May 2011.
[3] P.G. Tharanipriya and P.Vishnuraja. Hybrid genetic algorithm for
solving knapsack problem. In Proc. International conference on
Information Communication and Embedded Systems (ICICES' 13),
pages 416-420, Chennai,lndia, February 2013.
[4] D.L. Massart and B.Walczak. Rough set theory. Tn Proc. International
conference on Chemometrics and intelligent systems, pages 1-16,
Belgium, December 1998.
[5] Han K H, Kim J H. Genetic quantum algorithm and its application to
combinatorial optimization problem [C]. In Proc Proceedings of the
2000 Congress on Evolutionary Computation, Piscataway, 2000, 2:
1354 -1360.
[6] Han K H, Park K H, Lee C H, et al. Parallel quantum-inspired
genetic algorithm for combinatorial optimization problem[C]. In
Proceedings of the 2001 IEEE Congress on Evolutionary Computation,
2001: 1422-1429.
[7] S. Martello, D. Pisinger, P. Toth. New Trend in exact algorithms for
the 0-1 knapsack problem, European Journal of Operational Research
123 (2000) 325-332.
1125