Genetic Algorithm
Md Tanvir Rouf Shawon
Lecturer
Ahsanullah University of Science and Technology
Genetic Algorithm?
● The class of evolutionary algorithms that includes genetic algorithms was
largely influenced by biological evolution.
● We are all aware of the three components of biological evolution:
❖ The selection of parents
❖ Reproduction
❖ Offspring mutation
Genetic Algorithm?
● To produce offspring that are biologically superior to their parents is the
primary goal of evolution.
● A genetic algorithm attempts to imitate Darwin's Theory of Evolution by
Natural Selection. It is based primarily on this theory.
Algorithm
● Initialize population
● Select parents by evaluating their fitness
● Crossover parents to reproduce
● Mutate the offsprings
● Evaluate the offsprings (Survivor Selection)
● Merge offsprings with the main population and sort
Chromosome, Gene and Population
1. Initialization
● The algorithm generally starts with the randomly generated population.
● The size of the population depends on the nature of the problem.
● We can use 0s and 1s encoding or uniformly distributed numbers.
2. Parent Selection
During each successive generation, a portion of the existing population is selected
to breed a new generation.
● Random selection: Shuffle the population by performing permutation and
select the first two individuals as parents for breeding.
● Tournament selection: Run several tournaments among a randomly
selected group of individuals, select one individual from each group as the
winner, and again run the tournament by grouping winners from the first
iteration, repeat the process until the convergence to two winners parents for
breeding.
2. Parent Selection
● Roulette wheel selection: We all know
how the roulette wheel works in casinos,
drop the ball, spin the wheel, and wait till
the wheel stops to see which pot the ball
falls in.
2. Parent Selection
Casino roulette wheel: Each pot
has an equal probability of holding
the ball when the wheel stops
rotating.
In our roulette wheel: Define the
probability for each pot(individual of
the population). The probability of
each individual is called the fitness
of the individual.
3. Crossover
Crossover describes the process by which some genes from both parent
chromosomes are overlapped, jumbled together, or swapped to create new
children. Because of the crossing of the parent chromosomes, the offspring
possesses traits from both parents.
3. Crossover
Single-point crossover: In this method, both the parent chromosomes are cut at
the same random point, and the leftover parts are swapped to produce two new
offspring chromosomes.
3. Crossover
Two-point crossover: A method similar to the single-point crossover, but the only
difference is that the parent chromosomes are cut at two random points.
3. Crossover
Uniform crossover: Randomly choose which genes are supposed to be inherited
from both the parent chromosomes. Then, model them as 0s and 1s.. The gene to
be inherited is encoded as 1, and the gene that should not be inherited is encoded
as 0.
4. Mutation
Mutation is a natural process that occurs due to an error in replication or copying
of genes. By mixing and matching the genes from both parents, we were able to
reproduce the parent chromosomes during crossover. There is no guarantee that
the copying of the parent gene is 100% accurate. There always occurs an error,
which leads to the scope of exploration.
Mutating the chromosome in the genetic algorithm is necessary because it may
result in revolutionary results that will help solve our problem more efficiently.
4. Mutation
Bit Flip Mutation
Swap Mutation
4. Mutation
Scramble Mutation
Inversion Mutation
5. Evaluate the offsprings (Survivor Selection)
The Survivor Selection Policy determines which individuals are to be kicked out
and which are to be kept in the next generation.
It is crucial as diversity should be maintained in the population.
5. Evaluate the offsprings (Survivor Selection)
Age-Based Selection: It is based on the premise that each individual is allowed
in the population for a finite generation where it is allowed to reproduce, after that,
it is kicked out of the population no matter how good its fitness is.
5. Evaluate the offsprings (Survivor Selection)
Fitness based selection: The children tend to replace the least fit individuals in
the population. (Can be achieved by sorting)
6. Merge Offsprings with the Main Population and Sort
Merging the offsprings is vital for them to be considered as parents to reproduce
the next generation. Upon sorting the new population, better individuals are at the
top.
Since the population size remains the same as the first iteration, the number of
individuals at the bottom of the sorted population equal to the number of new
offsprings produced in the previous iteration are eliminated from the selection
process to breed new offsprings.
- Repeat the full process
6. Merge Offsprings with the Main Population and Sort
References
1. https://pub.towardsai.net/genetic-algorithm-ga-introduction-with-example-
code-e59f9bc58eaf
1. https://www.tutorialspoint.com/genetic_algorithms/genetic_algorithms_survivo
r_selection.htm