Genetic Algorithm
Genetic Algorithm
ALGORITHMS
Survived
Indivd u als
Individ u al
reproduce
Populatio GAs
n a n d pass
their
features
Species
evolution
GENETIC ALGORITHM
Genetic Algorithm works in following phases:
1) Initial Population: It begins with randomly selected
population (states) which are satisfactory to the problem.
For example, for travelling salesman problem with ten cities,
the initial population may contain any sequence of states
from start city.
Encode the population as strings, strings of bits or in
octal form or hexadecimal form (if required).
Usually for n variables, the size of population varies
from 2n to 4n.
2) Calculate the value of the fitness function (i.e. objective
function) which needs to be maximized or minimized. For
objective function which need to minimized can be
converted into a maximum problem by taking reciprocal/
negative of the original function.
GENETIC ALGORITHM CONTD…..
3)Apply the following operators on the initial population to generate child
(offspring's) . These child will act as parents for the next iteration.
(a)Selection: Parent Selection is the process of selecting parents which mate
and recombine to create off-springs for the next generation. Parent selection is
very crucial to the convergence rate of the GA as good parents drive
individuals to a better and fitter solutions (Various methods of selection
are explained in the later slides).
(b)Crossover: The crossover operator is analogous to reproduction and
biological crossover. In this more than one parent is selected and one or
more off-springs are produced using the genetic material of the parents
(Various methods of selection are explained in the later slides).
(c)Mutation: Mutation may be defined as a small random change in the
chromosome, to get a new solution. It is used to maintain and introduce
diversity in the genetic population and is usually applied with a low
probability. If the probability is very high, the GA gets reduced to a
random search.
4) Repeat step 3 on the new offspring’s produced to produce offspring’s for
next iteration.
GENETIC ALGORITHM CONTD…..
Nature GA
Population No. of candidate solutions.
Individual Each Candidate solution.
Chromosome Encoding of each indivudal
Gene Each bit ofChromosome
GENETIC ALGORITHMS FLOW CHART
SELECTION METHODS IN GAS
Roulette Wheel Selection-random number
Actual Count --- Best Method
Rank
K-Tournament Selection
SELECTION METHODS IN GAS
Roulette Wheel Selection (example explained at the end)
1) Compute the probability of selection for each population
and convert into percentageas:
X 100%
where
n =no of populations f(x)=fitness value corresponding to a
particular individual in the population
2) Represent these probabilities on the roulette wheel
according to the percentage of their probabilities. A fixed
point is chosen on the wheel circumference as shown and
the wheel is rotated. The region of the wheel which comes
in front of the fixed point is chosen as the parent. For the
second parent, the same process isrepeated.
EXAMPLE- ROULETTE WHEEL-RANDOM
f(x) = 2x ; 0<x<31
4 random numbers :-
Two-Point Crossover
In two-point crossover, two positions are selected a n d
segments are swapped;
11101001000 00101000101
00001010101 11001011000
CROSSOVER METHODS IN GAS
Uniform crossover
In uniform crossover, individual bits are chosen a t
random for swapping
11101001000 10001000100
00001010101 01101011001
MUTATION
Bit Flip Mutation
In this bit flip mutation, we select one or more
random bits and flip them.
Swap Mutation
In swap mutation, we select two positions on the
chromosome a t random, an d interchange the
values. This is common in permutation based
encodings.
MUTATION
Swap Random Piece of path
In this bit flip m u ta tion, we select one or more
random bits and flip them.
If we have 3 parts chosen out of 8 i.e. L to R, we
have to reverse the order from R to L.
P1
P2
P3
P4
P5
P6
SOLUTION CONTD….
Now, th e spin is selected and the mating parent s are
selected.
Let us decide t h a t one with probability more t h a n 25%
is selected twice a nd one with probability less t h a n 5%
is not selected. So the new mating pool for crossover is:
Population Chromosome
P1 10001
P1 10001
P3 00100
P4 11001
P5 11111
P6 00110
RANK SELECTION
Chrom Fitness Chrom Ran
# Chrom Fitness # k
Sort
P1 50 according # Assign raking P1 6
P2 6 to fitness P1 50 P3 5
P3 36 P3 36 P5 4
P4 30 P5 36 P4 3
P5 36 P4 30 P6 2
P6 28 P6 28 P2 1
P2 6
Chrom Prob Roulette
Chrom # Mating Pool
wheel
# % P1 10001
P1 29 P1 10001
P3 24
P3 00100
P5 19
P4 14 P5 11111
P6 10 P4 11001
6 5 4 3 24A pril
P2 5 2 1
P6 2015 00110
S OLUTION C ONTD …..
Crossover using single point method:
Let P1 and P3 are choose as parents:
10001 10100
00100 00001
Let P1 and P4 are choose as parents:
10001 10001
11001 11001
Let P5 and P6 are choose as parents:
11111 10110
00110 01111
EXAMPLE II
Con sider t h e following t ravellin g salesman problem wh ich u ses
following distance matrix and starting city A.
A B C D E F G H
A 0 1 4 2 9 8 3 2
B 1 0 5 3 7 2 5 1
C 2 5 0 6 1 4 7 7
D 4 3 6 0 5 2 1 6
E 9 7 1 5 0 9 1 1
F 8 2 4 2 9 0 3 5
G 3 5 7 1 1 3 0 2
H 2 1 7 6 1 5 2 0
P3,P3, P4,P4
C ROSSOVER IN TSP
Partially Mapped Crossover Operator
Consider, for example, the two parents tours with
randomly one cut point between 3rd an d 4t h bits an d
other cut point between 6th a nd 7th bits are as follows
(the two cut points marked with “|”):
C ROSSOVER IN TSP
Partially Mapped Crossover Operator
Consider, for example, the two parents tours with
randomly one cut point between 3rd an d 4t h bits an d
other cut point between 6th a nd 7th bits are as follows
(the two cut points marked with “|”):
C ROSSOVER IN TSP
Partially Mapped Crossover Operator
C ROSSOVER IN TSP
Partially Mapped Crossover Operator
0/1 Knapsack