Professional Documents
Culture Documents
Selection- In this step members of present populations are Termination - The process of selection and reproduction
selected based on their fitness value to reproduce another are repeated continuously until some termination is
generation of population. The chromosomes having reached. These conditions may be one of the following:
higher fitness value is more likely to survive and may
contribute several times to the new population. The • A solution is found that satisfies minimum
chromosomes with low fitness value will have fewer criteria
members in the new population or some of them may get
eliminated also. The size of population remains fixed in • Maximum number of generations reached
each population. The selection process is random in • Time allocated has expired
nature. Some of the popular selection methods are: • Combinations of the above
1: Roulette-wheel
2: Tournament selection Simple Genetic Algorithm Pseudo Code
3: Stochastic selection
1. Choose the initial population of individuals
4: Remainder Selection 2. Evaluate the fitness of each individual in that
population
Reproduction - In this step the next generation of 3. Create a new population by the following steps :
population is created using the following genetic • Selection
operators: • Reproduction (Mutation , Crossover)
4. Replace the present population with the new one.
1: Crossover - In crossover new offspring’s are produced 5. If termination condition is satisfied then exit
from a pair of chromosome called parent. In this process otherwise go to step 2
first a specific position ‘p’ along the string of
chromosome is selected such that 1<=p<l, where l is the
III. KNAPSACK PROBLEM 0 0 0 1 5 25
Item Value Weight Hence for the above a problem 16 number of solutions are
A 42 7 possible but there is only one optimum solution having
B 12 3 value=65 when A=0 and B=0 and C = D= 1. This means
C 40 4 the value of items are maximized when object C and D is
D 25 5 placed in the knapsack.
The aim of the Knapsack problem is to:
4 IV. IMPLEMENTATION OF 0-1
∑max Di Vi = 42D1 + 12D2 + 40D3 + 25D4 KNAPSACK PROBLEM USING GA
i=1
Representation of items - Items can be represented using
Where Di Є { 0, 1} and a 2D Array having two columns containing value and
weight of items respectively.
4 1 2
∑ Di Wi = 7D1 + 7D2 + 4D3 + 5D4 ≤ 10 42 7
i=1 1
12 3
I [ ][ ]= 2
There are 24 solutions possible for the above problem: 40 4
3
25 5
A B C D Weight of the set Value of 4
the set Values Weight
Representations of Chromosomes -The number of bits
0 0 0 0 0 0 in the chromosomes will be equal to the number of items
with ith bit denoting the presence of the ith item in the
Knapsack. If ith bit is 0 means the item is not present in
the knapsack and value 1 indicates its presence. For e.g. Fitness Function - Let F (D) defines a fitness function:
consider the following chromosome:
Chromosome: 1 0 1 0 F(D) = I[1][1] D[1] + I[2][1] D[2] + I[3][1] D[3] +........+ I[n-1][1] D[n-
The above chromosome corresponds to the presence of 1st 1] + I[n][1] D[n]
and 3rd item in the Knapsack.
Constraint - Let G (D) defines a Constraint function:
Main Program
G(D) = I[1][2] D[1] + I[2][2] D[2] + I[3][2] D[3] .....+ I[n-1][2] D[n-1]
+ I[n][2] D[n] ≤ C
START
I = 2D Array containing the Weight of items in the second
column
Initialize the 2D array with the D= Chromosome bit string where Dn refers to the bit
weight and value of the given Items value of nth bit.
C= Capacity of the Knapsack
Randomly create the initial population of Termination Condition - The program terminates when
fixed size i.e. chromosomes representing the 95% of the chromosomes have same fitness value or
the items present in the Knapsack when the number of generations exceeds the predefined
upper limit.
Initialize Gen=0
Now let us apply Genetic Algorithm on the following
Knapsack Problem
Compute Fitness Value for each of Consider the previous Knapsack Problem having a
the chromosome in the population Knapsack capacity of 10 and four items:
Fitness Function
Perform crossover and mutation F (D) = 42 D[1] + 12 D[2] + 40 D[3] + 25 D[n]
on the new population
Constraint
G(D) = 7 D[1] + 3 D[2] + 4 D[3] + 5 D[n] ≤ 10
Replace old population with the new one
As we Know the solution of above Problem is: 0 0 1 1
Gen = Gen +1
This means the value of items are maximized when item 3
and 4 is placed in the Knapsack.
No On solving above problem in Mat lab using different
Gen >Max
Exit Selection Methods of Genetic Algorithm we obtained the
Yes following results:
Figure 1. Algorithm for simulation
Stochastic selection Tournament Selection
Generation f(x) constraint Generation f(x) constraint
1 -65 1 1 -65 1
2 -107 1 2 -107 1
3 -65 1 3 -65 1
4 -65 1 4 -65 1
5 -65 1 5 -65 1
Optimization terminated Optimization terminated
Best: -65 Mean: -65 Best: -65 Mean: -65
0
Best fitness
0
Mean fitness Best fitness
F it n e s s v a lu e
-50
Mean fitness
F it n e s s v a lu e
-50
-100
-100
-150
0 10 20 30 40 50 60 70 80 90 100
Generation
Current Best Individual -150
1 0 10 20 30 40 50 60 70 80 90 100
C u rre n t b e s t in d iv id u a l
Generation
Current Best Individual
0.5 1
C u rre n t b e s t in d iv id u a l
0
1 2 3 4 0.5
Number of variables (4)
Roulette-wheel Selection 0
Generation f(x) constraint 1 2 3 4
1 -65 1 Number of variables (4)
2 -65 1
.Figure 4. Output using tournament selection
3 -65 1
Optimization terminated. V. CONCLUSION
Genetic Algorithms can be used to solve the NP Complete
Best: -65 Mean: -65 Knapsack Problem. Traditional methods like “Dynamic
-50
Best fitness Programming” which is used to solve Knapsack Problem
-55 Mean fitness have exponential complexity. But Genetic Algorithms
Fitness value
-60
provide a way to solve the above problem in linear
amount of time.
-65
-70 ACKNOWLEDGMENT
0 10 20 30 40 50 60 70 80 90 100
Generation I would like to acknowledge the assistance of Assistant
Current Best Individual Professor Mrs. Jyotsna Yadav in the preparation of this
1
paper.
Current best individual
REFERENCES
0.5
[1] Genetic Algorithms in Search, Optimization and
Machine Learning – David E. Goldberg.
0 [2] An Introduction To Genetic Algorithm- Melanie
1 2 3 4
Number of variables (4)
Mitchell.
Figure 3 Output using roulette-wheel selection