Unit 3 Genetic Algorithm Final
Unit 3 Genetic Algorithm Final
UNIT - III
3 Genetic Algorithms
Syllabus
Chromosome Encoding Schemes -Population initialization and selection methods
– Evaluation function - Genetic operators- Cross over – Mutation - Fitness Function
– Maximizing function
Fig. 3.1.2
Genetic algorithm starts with the current population. Selection is applied to the current
population to create an intermediate population. Then recombination and mutation are
applied to the intermediate population to create the next population. The process of going
from the current population to the next population constitutes one generation in the
execution of a genetic algorithm.
➥ 3.1.1 Biological Terminology
In genetic algorithms, biological terms are used to describe the various parts of the
algorithm. Chromosome refers to a potential solution to a problem. The evolution process
that is performed on a population of these chromosomes is analogous to a search through a
space of potential solutions.
Three functions are performed on one population of chromosomes to generate the next. The
functions are crossover, mutation and inversion.
1. Cell : Animal or human cell is a complex of many small factories that work together.
The center of all this is the cell nucleus. The genetic information is contained in the cell
nucleus. Each cell contains the same set of one or more chromosomes.
2. Chromosomes : All the genetic information gets stored in the chromosomes. Each
chromosome is build of Dioxy Ribo Nucleic Acid (DNA). In human body, a
chromosome exists in the form of pairs (23 pairs).
3. Genes : A chromosome can be conceptually divided into genes. Each of which encodes
a particular protein. Genes code the properties of species i.e., the characteristics of an
individual. Every gene has an unique position on the chromosome. The possibilities
values of the genes for one property are called allele and a gene can take different
alleles. Alleles can be either dominant or recessive.
4. Genome : The set of all possible alleles present in a particular population forms a gene
pool. This gene pool can determine all the different possible variations for the future
generations. The set of all the genes of a specific species is called genome. The term
genotype refers to the particular set of genes contained in a genome.
5. Each gene has a unique position on the genome called locus. Most living organisms
Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D
Soft Computing Genetic Algorithms
store their genome on several chromosomes, but in the Genetic Algorithms, all the genes
are usually stored on the same chromosomes. Thus chromosomes and genomes are
synonyms with one other in GAs.
6. For a particular individual, the entire combination of genes is called genotype. The
phenotype describes the physical aspect of decoding a genotype to produce the
phenotype. A genotype develops to a phenotype. Phenotype describe physical
characteristic of the genotype (smart, beautiful, healthy, etc.).
7. Organisms whose chromosomes are arrayed in pairs are called diploid; organisms
whose chromosomes are unpaired are called haploid. In haploid representation, only
one set of each gene is stored, thus the process of determining which allele should be
dominant and which one should be recessive is avoided. Most GA concentrates on
haploid chromosomes because they are much simple to construct.
The following table gives a list of different expressions, which are common in genetics,
along with their equivalent in the framework of GAs :
Natural Evolution Genetic Algorithm
genotype coded string
phenotype uncoded point
chromosome string
gene string position
allele value at a certain position
fitness objective function value
❒ Common Term used in GA
1. Individual :- Any possible solution
2. Population :- Group of all individuals
3. Search Space :- All possible solutions to the problem
4. Chromosome :- Blueprint for an individual
5. Trait :- Possible aspect (features) of an individual
6. Allele : - Possible settings of trait (black, blond, etc.)
7. Locus :- The position of a gene on the chromosome
8. Genome :- Collection of all chromosomes for an individual
➥ 3.1.4 Limitations of GA
GAs are not guaranteed to find the global optimum solution to a problem.
GAs are an extremely general tool and they have no specific way for solving particular
problems.
GAs are usually used when everything else is failed or when we don't have enough
knowledge of the search space.
Even when such specialized techniques exist, it often interesting to hybridise them with a
GA in order to possibly gain some improvements.
Fig. 3.2.1
Genetic operator is the operator for generating new gene based on fitness of each
individual.
Crossover means choosing a random position in the string (say, after 2 digits) and
exchanging the segments either to the right or to the left of this point with another string
partitioned similarly to produce two new off spring.
Crossover produces two new offspring from two parent strings by copying selected bits
from each parent. Bit at position “i” in each offspring is copied from the bit at position “I”
in one of the two parents. The choice which parent contributes bit “I” is determined by an
additional string, called cross-over mask.
In the crossover operator, new strings are created by exchanging information among strings
of the mating pool.
The primary objective of the recombination operator is to emphasize the good solutions and
eliminate the bad solutions in a population, while keeping the population size constant.
“Selects The Best, Discards The Rest”. “Recombination” is different from “Reproduction”.
Identify the good solutions in a population. Make multiple copies of the good solutions.
Eliminate bad solutions from the population so that multiple copies of good solutions can
be placed in the population. It is the process in which two chromosomes (strings) combine
their genetic material (bits) to produce a new offspring which possesses both their
characteristics. Two strings are picked from the mating pool at random to cross over. The
method chosen depends on the Encoding Method.
Crossover can be rather complicated and very depends on encoding of the encoding of
chromosome. Specific crossover made for a specific problem can improve performance of
the genetic algorithm.
❒ Steps of crossover :
1. The reproduction operator selects at random a pair of two individual strings for the
mating.
2. A cross site is selected at random along the string length.
3. Finally, the position values are swapped between the two strings following the cross
site.
+ + =
=
11001011 + 11011111 = 11001111
Example :
Parent 1 : XX|XXXXX
Parent 2 : YY|YYYYY
Offspring 1 : X X Y Y Y Y Y
Offspring 2 : Y Y X X X X X
One site crossover is more suitable when string length is small while two site crossover
is suitable for large strings.
Crossover example :
Parent A 011011
Parent B 101100
Mate the parents by splitting each number as shown between the second and third digits
(position is randomly selected)
01*1011 10*1100
Now combine the first digits of A with the last digits of B and the first digits of B with
the last digits of A. This gives you two new offspring.
011100
101011
If these new solutions or offspring, are better solutions than the parent solutions, the
system will keep these as more optimal solutions and they will become parents. This is
repeated until some condition (for example number of populations or improvement of
the best solution) is satisfied.
❒ Matrix Crossover
Some real problems are naturally suitable for two-dimensional representation. If this
kind of problems is to be solved by genetic algorithms, then each possible solution can
very conveniently and naturally be conceptually represented as a two-dimensional table.
Two-dimensional substring crossover generates two offspring chromosomes by
choosing only one of the two crossover strategies (horizontal or vertical).
Alternatively, the two-dimensional crossover operator can be easily modified to
generate four offspring chromosomes from a pair of parents by executing the horizontal
and the vertical crossovers at the same time.
The new offspring chromosomes that result from executing the crossover operation may
become infeasible for some application problems.
Parent 1 Offspring 1
1 3 9 8 1 3 9 8
5 4 7 2 –– 5 4 5 3
6 12 11 10 2 12 7 8
Parent 2 Offspring 2
4 6 11 9 4 6 11 9
10 1 5 3 –– 10 1 7 2
2 12 7 8 6 12 11 10
Fig. 3.2.2 : Horizontal substring crossover
Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D
Soft Computing Genetic Algorithms
Parent 1 Offspring 1
1 3 9 8 1 3 11 9
5 4 7 2 –– 5 4 5 3
6 12 11 10 6 12 6 8
Parent 2 Offspring 2
4 7 11 9 4 7 9 8
10 1 5 3 –– 10 1 7 2
2 12 6 8 2 12 11 10
Fig. 3.2.3 : Vertical substring crossover
➥ 3.3.1 Inversion
String is selected from the population. The bits between two random sites are inverted.
Fig. 4.3.1 shows inversion.
Mutation may cause the chromosomes of individuals to be different from those of their
parent individuals.
If crossover is supposed to exploit the current solution to find better ones, mutation is
supposed to help for exploration of the whole search space. Mutation in a way is the
process of randomly disturbing genetic information. They operate at the bit level; when the
bits are being copied from the current string to the new string, there is probability that each
bit may become mutated.
The need for mutation is to create a point in the neighborhood of the current point, thereby
achieving a local search around the current solution. The mutation is also used to maintain
diversity in the population. For example, the following population having four eight bit
strings may be considered :
01101011
00111101
00010110
01111100
It can be noticed that all four strings have a 0 in the left most bit position. If the true
optimum solution requires in that position, then neither reproduction nor crossover operator
described above will be able to create 1 in that position.
❒ Example of Mutation
For chromosomes using Binary Encoding, randomly selected bits are inverted.
Offspring 1101 1 00100 1 1 0110
Mutated Offspring 1101 0 00100 1 0 0110
Note : The number of bits to be inverted depends on the Mutation Probability.
Exchange mutation : The interchange of two randomly chosen elements of the
permutation.
Shift mutation : The movement of a randomly chosen element a random number of places
to the left or right.
Scramble sublist mutation : Choose two points on the string in random and randomly
permuting the elements between these two positions.
Flipping of a bit involves changing 0 to 1 and 1 to 0 based on a mutation chromosome
generated.
Parent 1011 0101
Mutation chromosome 1000 1001
Child 0011 1100
Reserving : A random position is chosen and the bits next to that position are reversed and
child chromosome is produced.
Parent 10110101
Child 10110110
Example : Suppose a Genetic Algorithm uses chromosomes of the form x = abcdefgh with
a fixed length of eight genes. Each gene can be any digit between 0 and 9. Let the fitness of
individual x be calculated as :
f(x) = (a + b) – (c + d) + (e + f) – (g + h)
And let the initial population consist of four individuals x1, ... , x4 with the following
chromosomes :
X1 = 6 5 4 1 3 5 3 2
f(x1) = (6 + 5) – (4 + 1) + (3 + 5) – (3 + 2) = 9
X2 = 8 7 1 2 6 6 0 1
f(x2) = (8 + 7) – (1 + 2) + (6 + 6) – (0 + 1) = 23
X3 = 2 3 9 2 1 2 8 5
f(x3) = (2 + 3) – (9 + 2) + (1 + 2) – (8 + 5) = – 16
X4 = 4 1 8 5 2 0 9 4
f(x4) = (4 + 1) – (8 + 5) + (2 + 0) – (9 + 4) = – 19
The arrangement is (assume maximization)
X2 x1 x3 x4
(the fittest individual) (least fit individual)
Put the calculations in table for simplicity
Individuals String representation Fitness Arrangement assume maximization
X1 65413532 9 X2(fittest individual)
X2 87126601 23 X1(second fittest individual)
X3 23921285 – 16 X3 (third fittest individual)
X4 41852094 – 19 X4 (least fit individual)
So Average fitness : – 0.75 Best : 23 Worst : – 19
Average fitness= (9 + 23 + – 16 + – 19)/ 4 = – 0.75
X2 = 8 7 1 2 6 6 0 1
Offspring 1 = 8 7 1 2 3 5 3 2
Offspring 2 = 6 5 4 1 6 6 0 1
X1 = 6 5 4 1 3 5 3 2
X3 = 2 3 9 2 1 2 8 5
Offspring 3 = 6 5 9 2 1 2 3 2
Offspring 4 = 2 3 4 1 3 5 8 5
X2 = 8 7 1 2 6 6 0 1
X3 = 2 3 9 2 1 2 8 5
Offspring 5 = 8 3 1 2 6 6 8 1
Offspring 6 = 2 7 1 2 6 2 8 1
Offspring 1 = 8 7 1 2 3 5 3 2
F (Offspring 1) = (8 + 7) – (1 + 2) + (3 + 5) – (3 + 2) = 15
Offspring 2 = 6 5 4 1 6 6 0 1
F (offspring 2) = (6 + 5) – (4 + 1) + (6 + 6) – (0 + 1) = 17
Offspring 3 = 6 5 9 2 1 2 3 2
F (offspring 3) = (6 + 5) – (9 + 2) + (1 + 2) – (3 + 2) = – 2
Offspring 4 = 2 3 4 1 3 5 8 5
F (offspring 4) = (2 + 3) – (4 + 1) + (3 + 5) – (8 + 5) = – 5
Offspring 5 = 8 3 1 2 6 6 8 2
F (offspring 5) = (8 + 3) – (1 + 2) + (6 + 6) – (8 + 1) = 11
Offspring 6 = 2 7 1 2 6 2 8 1
F (offspring 6) = (2 + 7) – (1 + 2) + (6 + 2) – (8 + 1) = 5
Put the calculation in table for simplicity
Individuals String representation Fitness
Offspring 1 87123532 15
Offspring 2 65416601 17
Offspring 3 65921232 –2
Offspring 4 23413585 –5
Offspring 5 87921201 11
Offspring 6 23926601 5
Chromosome A Chromosome B
➠ 3.7 Convergence of GA
The convergence of a genetic algorithm arises when the genes of some high rated
individuals quickly attain to dominate the population, constraining it to converge to a local
optimum. In this case, the genetic operators cannot produce any more descendents better
that the parents; the algorithm ability to continue the search for better solutions is therefore
substantially reduced.
The advantages of genetic algorithms first become apparent when a population of strings is
observed.
Let f be the function x x2 which is to be maximized, in the interval [0, 1]. A population
of N numbers in the interval [0, 1] is generated in 10-bit fixed-point coding.
The function f is evaluated for each of the numbers x1, x2, , xN, and the strings are then
listed in descending order of their function values. Two strings from this list are always
selected to generate a new member of a new population, whereby the probability of
selection decreases monotonically in accordance with the ascending position in the sorted
list.
The computed list contains N strings which, for a sufficiently large N, should look like
this :
1 0.1 *************
1 0.1 *************
...
...
1 0.0 *************
The first positions in the list are occupied by strings in which the first bit after the point is a
1. The last positions are occupied by strings in which the first bit after the decimal point is a
0. The asterisk stands for any bit value from 0 to 1 and the zero in front of the point does
not need to be coded in the strings.
The upper strings are more likely to be selected for a recombination, so that the offspring is
more likely to contain a 1 in the first bit than a 0. The new population is evaluated and a
new fitness list is drawn up.
Also the strings with a 0 in the first bit are placed at the end of the list and are less likely to
Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D
Soft Computing Genetic Algorithms
be selected than the strings which begin with a 1. After several generations no more strings
with a 0 in the first bit after the decimal point are contained in the population.
The same process is repeated for the strings with a zero in the second bit. They are also
pushed towards extinction. Gradually the whole population converges to the optimal string
0.1111111111.
With this quadratic function the search operation is carried out within a very well-ordered
framework. New points are defined at each crossover, but steps in the direction x = 1 are
more likely than steps in the opposite direction. The step length is also reduced in each
reproduction step in which the 0 bits are eliminated from a position.
John Holland suggested the notion of schemata for the convergence analysis of genetic
algorithms. Schemata are bit patterns which function as representatives of a set of binary
strings. We already used such bit patterns in the example above : the bit patterns can
contain each of the three symbols 0, 1 or *. The schema **00**, for example, is a
representative of all strings of length 6 with two zeros in the central positions, such as :
100000, 110011, 010010, etc.
Some authors have argued in favor of the building block hypothesis to explain why GAs do
well in some circumstances. According to this hypothesis a GA finds building blocks which
are then combined through the generations in order to reach the optimal solution. But the
correlations between the optimization parameters sometimes preclude altogether the
formation of these building blocks.
Fig. 4.7.1 shows genetic algorithm cycle. Building blocks are combined together due to
combined action of generic operators to form bigger and better building blocks and finally
converge to the optimal solution.
Below are the steps to be followed to solve any optimization problem with the help of GA.
Now we’ll see an example of a simple optimization problem and try to solve it with the
Question
Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D
Soft Computing Genetic Algorithms
Answer
Step 1-
Step 2-
Step 3-
Step 4-
We see that if the Roulette wheel is spun four times, we’ll get 24 twice and 13 and 19 once.
Step 5-
Step 6-
We can see that the maximum f(x) value has increased from 576 to 729.
Step 7-
Now we’ll take these four offsprings as parents and repeat the process until our termination