Genetic Algorithm
Genetic Algorithm
Genetic Algorithm
Genetic Algorithm(GA)
possible solution.
Therefore every point has a fitness 1
definition.
GAs are used to search the search 0
0 100 200 300 400 500 600 700 800 900 1000
Initial population
Selection
• All individuals in population
evaluated by fitness function.
Termi
No
nate
yes
Best Individuals
Flowchart of GA
Output
Stop
Operators in Genetic
Algorithm
So..
Encoding
Selection
Cross Over (Recombination)
Mutation Operators
Encoding
• Encoding is a process of representing individual genes.
• The process can be performed using bits, numbers, trees,
arrays, lists or any other objects.
• The encoding depends mainly on solving the problem.
• For example, one can encode directly real or integer
numbers.
Different Encodings
• Binary Encoding
• Octal Encoding
• Hexadecimal Encoding
• Permutation Encoding(Real Number Encoding)
• Value Encoding
• Tree Encoding
Binary Encoding
• The most common way of encoding is a binary string, which
would be represented as
• Hexadecimal Encoding
Proportionate-based selection
Ordinal based selection.
• Proportionate-based selection picks out individuals based
upon their fitness values relative to the fitness of the other
individuals in the population.
• Ordinal-based selection schemes select individuals not upon
their raw fitness, but upon their rank within the population.
• This requires that the selection pressure is
independent of the fitness distribution of the population,
and is solely based upon the relative ordering (ranking) of the
population.
• The various selection methods
• Roulette Wheel Selection
• Random Selection
• Rank Selection
• Tournament Selection
• Boltzmann Selection
Roulette Wheel Selection
• The principle of Roulette selection is a linear search through a Roulette
wheel.
• Each individual is assigned a slice of the Roulette wheel.
• The size of the slice being proportional to the individual's fitness.
• The wheel is spun N times, where N is the number of individuals in the
population.
• On each spin, the individual under the wheel's marker is selected to be in
the pool of parents for the next generation.
• A target value(marker) is set, which is a random proportion of the sum
of the fitnesses in the population.
Implementation
• Here equally spaced pointers are placed over the line, as many
as there are individuals to be selected
• provides zero bias and minimum spread.
• Consider NPointer the number of individuals to be
selected,
• Then the distance between the pointers are 1/NPointer
• The position of the first pointer is given by a randomly
generated number in the range [0, 1/NPointer].
• For 6 individuals to be selected, the distance
between the pointers is 1/6 = 0.167.
• Sample of 1 random number in the range [0, 0.167]:
0.1.
• After selection the mating population consists of the
individuals,
1,2,3,4,6,8
Crossover(Recombination)
• Crossover is the process of taking two parent solutions and
producing from them a child.
• Crossover operator is applied to the mating pool with the
hope that it creates a better offspring.
• Crossover is a recombination operator that proceeds in
three steps:
• The selection operator selects at random a pair of two
individual strings for the mating.
• A cross site(point) is selected at random along the
string length.
• Finally, the position values are swapped between the
two strings following the cross site.
Single Point Crossover
Two chromosomes are cut once at corresponding points and
The sections after the cuts exchanged.
Here, a cross site or crossover point is selected randomly
Split parents at the crossover point.
Generalization of 1 point.
Uniform Crossover
• Each gene in the offspring is created by copying the
corresponding gene from one or the other parent
• chosen according to a random generated binary
crossover mask of the same length as the chromosomes.
• Where there is a 1 in the crossover mask, the gene is
copied from the first parent, and where there is a 0 in the
mask the gene is copied from the second parent
• Offspring, therefore, contain a mixture of genes from each
parent.
Three Parent Crossover
• Three parents are randomly chosen.
• Each bit of the first parent is compared with the bit of the
second parent.
• lf both are the same, the bit is taken for the offspring,
otherwise the bit from the third parent is taken for the
offspring.
Crossover with Reduced Surrogate
• The reduced surrogate operator constraints crossover to
always produce new individuals wherever possible.
• This is implemented by restricting the location of crossover
points such that crossover points only occur where gene
values differ.
Shuffle cross over
• Related to uniform crossover.
• A single crossover position is selected.
• But before the variables are exchanged, they are randomly
shuffled in both parents.
• After recombination, the variables in the offspring are
unshuffled.
Precedence Preservative Crossover (PPX)
• The operator passes on precedence relations of operations
given in two parental permutations to one offspring at the
same rate.
• Flipping
• Interchanging
• Reversing
Flipping
1/6 = 17%
fitness(A) = 3
A B
C fitness(B) = 1
3/6 = 50% 2/6 = 33% fitness(C) = 2
Genetic Algorithm – An Example
Simple problem: max x2 over {0, 1, …, 31}
GA approach:
• Representation: binary code, e.g. 01101 13
• Population size: 4
• 1-point xover, bitwise mutation
• Roulette wheel selection
• Random initialisation
4 1
31% 14%
5% 3
49%
2
Example : Crossover
Example : Mutation
• From the tables population average fitness has
improved from 293 to 588
• The maximum fitness has increased from 576 to
729
• random processes make this best solution, its
improvement can also be seen successively.
• The best string of the initial population (1 1 0 0 0
receives two chances for its existence because of
its high, above-average performance.
• When this combines at random with the next
highest string (1 0 0 1 1) and is crossed at crossover
point 2 one of the resulting strings (1 1 0 11)
proves to be a very best solution indeed.
• Thus after mutation at random, a new offspring
(11 011) produced which is an excellent choice.
Comparison of GA with Traditional Optimization Techniques
GA works with the coding of solution set and not with the solution itself.
CityList1 (3 5 7 2 1 6 4 8)
CityList2 (2 5 7 6 8 1 3 4)
Crossover
Child (5 8 7 2 1 6 3 4)
* *
Before: (5 8 7 2 1 6 3 4)
After: (5 8 6 2 1 7 3 4)
TSP Example: 30 Cities
120
100
80
60
y
40
20
0
0 10 20 30 40 50 60 70 80 90 100
x
Solution i (Distance = 941)
TSP30 (Performance = 941)
120
100
80
60
y
40
20
0
0 10 20 30 40 50 60 70 80 90 100
x
Solution j(Distance = 800)
44
62 TSP30 (Performance = 800)
69
67 120
78
64
100
62
54
42 80
50
40
60
40
y
38
21 40
35
67
20
60
60
40 0
0 10 20 30 40 50 60 70 80 90 100
x
Solution k(Distance = 652)
TSP30 (Performance = 652)
120
100
80
60
y
40
20
0
0 10 20 30 40 50 60 70 80 90 100