Genetic Algorithms
Genetic Algorithms
GENETIC ALGORITHM
Introduced by Holland in 1975.
Adaptive heuristic search algorithm based
on evolutionary ideas of natural selection
and genetics.
More robust than conventional algorithms.
Do not break easily even if the inputs are
changed slightly or have reasonable noise.
INTRODUCTION
Genetic algorithms (GAs) are a technique to solve
problems which need optimization
Crossover:
Random exchange of parent's chromosomes during
reproduction resulting in:
offspring having some traits of each parent
Biological Background Reproduction
Mutation:
Rare occurrence of errors during the process of copying
chromosomes resulting in genetic variation
POSSIBILITIES
Changes that are nonsensical/
deadly producing organisms that
can't survive
What is evolution?
Evolution is a gradual process of change in the
genetic composition of a population, as a result of
natural selection acting on genetic variation
among individuals
Basic Principle
Select The Best, Discard The Rest
Biological Background An example of Natural selection
Millions Of Years
Evolved Species
(Favorable Characteristic Now A Trait Of Species)
Genetic Algorithms
Implement Optimization Strategies
by Simulating Evolution Of Species
through Natural Selection.
Genetic Algorithm Basic steps
Start
Terminate? Stop
no
Selection of individuals (proportional with fitness)
Defined as:
We are given a set of cities and a symmetric distance
matrix that indicates the cost of travel from each city to
every other city.
The goal is to find the shortest circular tour, visiting
every city exactly once, so as to minimize the total travel
cost, which includes the cost of traveling from the last city
back to the first city.
GA for Traveling Salesman problem
Problem Complexity
Well known combinatorial optimization problem
Problem belongs to NP-Hard category
N city TSP has N! possible combinations
Consider a 5 city TSP
1
4 5
GA for Traveling Salesman problem
1 2 3 4 5
1 0
2 5 0
3 8 3 0
4 2 4 9 0
5 7 10 6 8 0
Genetic Algorithm Nature to Computer
Mapping
Nature Computer
Problem Encoding
The path [1 2 3 4 5 ] represents a path from 1 to 2,
2 to 3, 3 to 4, 4 to 5and finally from 5 to 1.
This is an example of Permutation Encoding as
the position of the elements determines the fitness
of the solution.
Fitness Evaluation
For a chromosome [1 2 3 4 5], the total cost of
travel or fitness will be calculated as shown below
Fitness = 5 + 3 +9 +8 +7 = 32
Since our objective is to Minimize the distance, the
lesser the total distance, the fitter the solution.
Genetic Algorithm Operator Fitness evaluation
Start
Terminate? Stop
no
Selection of individuals (proportional with fitness)
4 1 5 3 2 =22 =0.333
3 4 2 5 1 =38 =0.149
Fitness function
Start
Terminate? Stop
no
Selection of individuals (proportional with fitness)
Strings that are fitter are assigned a larger slot and hence
have a better chance of appearing in the new population.
Roulette wheel selection
Start
Terminate? Stop
no
Selection of individuals (proportional with fitness)
Start
Terminate? Stop
no
Selection of individuals (proportional with fitness)
2
Genetic Algorithm Operator - Mutation
Exploitation ( Intensification ) Vs
Exploration ( Diversification)
Mutation
Shift operation
Rotation operation
GA for Traveling Salesman problem
4 1 5 3 2 =22 =0.333
3 4 2 5 1 =38 =0.149
GA for Traveling Salesman problem
Start
Terminate? Stop
no
Selection of individuals (proportional with fitness)
4 1 5 3 2 (2,4) 1 4 2 5 3 1 5 2 4 3 38
1 2 3 4 5 x 1 2 3 4 5 1 2 3 4 5 32
3 4 2 5 1 (2,4) 2 1 5 3 4 2 1 5 3 4 31
5 3 1 2 4 (3,4) 1 2 5 3 4 4 2 5 3 1 30
4 1 5 3 2 (3,4) 4 5 1 2 3 4 5 1 2 3 32
Pair 1 Pair 2
Parent 1 4 1 5 3 2 5 3 1 2 4
Parent 2 3 4 2 5 1 4 1 5 3 2
CROSSOVER (PMX)
Offspring 1 4 2 5 3 1 2 5 3 4
1
2 1 5 3 4 4 5 1 2 3
GA for Traveling Salesman problem
Start
Terminate? Stop
no
Selection of individuals (proportional with fitness)
Start
Terminate? Stop
no
Selection of individuals (proportional with fitness)
Population size:
Good population size is about 20-30,
However sometimes sizes 50-100 are reported as
the best.
Some research also shows, that the best population
size depends on the size of encoded string
(chromosomes).
Encoding:
Encoding depends on the problem and also on the
size of instance of the problem.
Selection:
Basic roulette wheel selection can be used, but
sometimes rank selection can be better.
Different selection schemes could be attempted for a
Genentic Algorithm Parameters
Crossover probability:
Crossover rate should be high generally, about 60%-
95%.
Mutation probability:
Mutation rate should be very low. Best rates seems to be about 5% -
15%.
Start
Terminate? Stop
no
Selection of individuals (proportional with fitness)
1: P Initial Population
2: Evaluate (P)
3: while (Termination Criterion not met) do
4: P Recombine (Select(P))
5: P Mutate (P)
6: P Evaluate (P")
7: P Replace (P U P")
8: end while
9: Output P
End