Lecture 11 - Genetic Algorithms II (1)
Lecture 11 - Genetic Algorithms II (1)
• GAs are classified as global search heuristics, but they perform local search within
populations. Through evolution-inspired processes, they balance exploration (global
search) and exploitation (local search).
• GAs belong to a class of evolutionary algorithms, leveraging mechanisms inspired
by biological evolution, such as inheritance, mutation, selection, and crossover
(also called recombination).
Intuition Behind Genetic Algorithms
Inspired by Biological Evolution:
• Mimics the biological evolution process, where species evolve over generations to
adapt to their environments.
• In GAs, candidate solutions (individuals) evolve through processes like selection,
crossover, and mutation, imitating the way nature refines species.
• The fittest individuals — those with the best solutions to the problem — are more likely
to survive and pass advantageous traits to the next generation, gradually improving the
overall solution quality.
General Working of GA
• The evolution usually starts from a population of randomly
generated individuals and happens in generations.
• In each generation, the fitness of every individual in the population is
evaluated,
• Multiple individuals are selected from the current population (based
on their fitness),
• And modified to form a new population.
• The new population is used in the next iteration of the algorithm.
• The algorithm terminates when either a maximum number of
generations has been produced, or a satisfactory fitness level has
been reached for the population.
No convergence rule or
guarantee!
Vocabulary
• Population: Population is the subset of all possible or probable solutions,
which can solve the given problem.
• Genetic Operators: In a genetic algorithm, the best individual mate to regenerate offspring
better than parents. Here genetic operators play a role in changing the genetic
composition of the next generation.
• Selection: After calculating the fitness of every existent in the population, a selection
process is used to determine which of the individualities in the population will get to
reproduce and produce the seed that will form the coming generation.
How Genetic Algorithm Works?
The genetic algorithm works on the evolutionary generational cycle to generate high-
quality solutions. These algorithms use different operations that either enhance or
replace the population to give an improved fit solution.
It basically involves five phases to solve the complex optimization problems, which are
given as below:
o Initialization
o Fitness Assignment
o Selection
o Reproduction
o Termination
1. Initialization
The process of a genetic algorithm starts by generating the set of individuals, which is called
population. Here each individual is the solution for the given problem. An individual contains
or is characterized by a set of parameters called Genes. Genes are combined into a string and
generate chromosomes, which is the solution to the problem. One of the most popular
techniques for initialization is the use of random binary strings.
2. Fitness Assignment
After the selection process, the creation of a child occurs in the reproduction step. In this
step, the genetic algorithm uses two variation operators that are applied to the parent
population. The two operators involved in the reproduction phase are given below:
• Crossover
• Mutation
i. Crossover
The crossover plays a most significant role in the reproduction phase of the
genetic algorithm. In this process, a crossover point is selected at random
within the genes. Then the crossover operator swaps genetic information of
two parents from the current generation to produce a new individual
representing the offspring
The genes of parents are exchanged among themselves until the crossover point is met.
These newly generated offspring are added to the population. This process is also called or
crossover. Types of crossover styles available:
oOne point crossover
oTwo-point crossover
oLivery crossover
oInheritable Algorithms crossover
ii. Mutation
The mutation operator changes random genes in the offspring (new child) to maintain the
diversity in the population. It can be done by flipping some bits in the chromosomes.
Mutation helps in solving the issue of premature convergence and enhances diversification.
The below image shows the mutation process:
Types of mutation styles available,
o Flip bit mutation
o Gaussian mutation
o Exchange/Swap mutation
5. Termination
However, Instead of just viewing it as flipping all bits to 1, we can reframe the problem:
• Imagine each bit (1 or 0) represents the correct (1) or incorrect (0) answer to a series of
yes/no difficult questions.
• The GA's task is to iteratively evolve a population of candidate solutions, selecting those
with more correct answers and improving them over generations.
Example: the MAXONE problem
s1 = 1111010101 f (s1) = 7
s2 = 0111000101 f (s2) = 5
s3 = 1110110101 f (s3) = 7
s4 = 0100010011 f (s4) = 4
s5 = 1110111101 f (s5) = 8
s6 = 0100110000 f (s6) = 3
Step 2: Selection
• The probability of an individual being selected is proportional to its fitness.
• Higher fitness individuals have a greater chance of being selected.
13
Selected set
14
Step 3: Crossover
• Next, we recombine the strings for crossover. For each pair we first
decide (using some pre-defined probability, for instance 0.6)
whether to actually perform the crossover or not
• If we decide to actually perform crossover, we randomly extract the
crossover points, for instance 2 and 5
15
Crossover result
Before crossover:
s1` = 1111010101 s2` = 1110110101
After crossover:
s1`` = 1110110101 s2`` = 1111010101
16
Step 4: mutations
The final step is to apply random mutations: for each bit that we are to copy to the
new population we allow a small probability of error (for instance 0.1)
17
And now, iterate …
• In any copying process errors can occur, so single (point) mutations are
pretty common.
• Other types of errors, including affecting longer regions (either deletion,
inversions, substitutions etc.) can also occur
GA Operators
• Methods of representation
• Methods of selection
• Methods of Reproduction
Common representation methods
• Binary strings.
• Arrays of integers (usually bound)
• Arrays of letters
• ….
Methods of Selection
• Roulette-wheel selection.
• Elitist selection.
• Cutt-off selection.
• Tournament Selection
• Rank based selection.
• …
Roulette wheel selection
Conceptually, this can be represented as a game of roulette - each
individual gets a slice of the wheel, but more fit ones get larger
slices than less fit ones.
Roulette wheel selection
3 01000 64 5.5
Cross point
• Two point crossover (Multi point crossover)
→
Two-point crossover
Two crossover points are selected, and the genes between them are
swapped between two parents to create offspring.
Key Benefits:
• Preserves more genetic diversity than single-point crossover.
• Prevents important genes at the start and end from always being split.
• Encourages better mixing of genetic material
Two-point crossover
• Choose two points e.g. 2-8
• Apply cross over, including 2, excluding 8
• The indexing here starts from 0.
→
EXAMPLE
The Traveling Salesman Problem:
CityList1 (3 5 7 2 1 6 4 8)
CityList2 (2 5 7 6 8 1 3 4)
Crossover
Crossover combines inversion and recombination:
* *
Parent1 (3 5 7 2 1 6 4 8)
Parent2 (2 5 7 6 8 1 3 4)
Child (2 5 7 2 1 6 3 4)
Mutation
Mutation involves reordering of the list:
* *
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
y 60
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
y 60
40
20
0
0 10 20 30 40 50 60 70 80 90 100
x
Solution j(Distance = 800)
TSP30 (Performance = 800)
120
100
80
y 60
40
20
0
0 10 20 30 40 50 60 70 80 90 100
x
Solution k(Distance = 652)
TSP30 (Performance = 652)
120
100
80
y 60
40
20
0
0 10 20 30 40 50 60 70 80 90 100
x
Best Solution (Distance = 420)
TSP30 Solution (Performance = 420)
120
100
80
y 60
40
20
0
0 10 20 30 40 50 60 70 80 90 100
x
GA Applications
Domain Application Type
Control Gas pipeline, missile evasion
Design Aircraft design, keyboard configuration,
communication networks
Game Poker, checkers
playing
Security Encryption and Decryption