Prafulla S. Kota
Genetic Algorithms are a form of local search
that use methods based on evolution to make
small changes to a population of chromosomes
in an attempt to identify an optimal solution.
• Representations used for genetic algorithm.
• Idea of schemata.
• Genetic operators, crossover and mutations.
• Procedures used to run Genetic algorithms.
Genetic programming can be used to
evolve S-expressions, which can be used
as LISP programs to solve problems.
A string of bits is known as a
Each bit is known as a gene.
Chromosomes can be combined
together to form creatures.
We will see how genetic algorithms can
be used to solve mathematical problems.
1. Generate a random population of
2. If the termination criteria are satisfied, stop.
Else, continue with step 3.
3. Determine the fitness of each chromosome.
4. Apply crossover and mutation to selected
chromosomes from the current generation, to
generate a new population of chromosomes –
the next generation.
5. Return to step 2.
The size of the population should be
determined in advance.
The size of each chromosome must
remain the same for crossover to be
Fittest chromosomes are selected in each
generation to produce offspring which
replace the previous generation.
Each pair of parents produces two
When we use traditional genetic
algorithm, a metric is needed whereby
the fitness of a chromosome can be
When we consider real creatures, fitness
measure is based on the extent to which
the physical form (phenotype)
represented by the genetic information
(genotype) met certain criteria.
The crossover operator is applied to two
chromosomes of the same length as
1. Select a random crossover point.
2. Break each chromosome into two parts,
splitting at the crossover point.
3. Recombine the broken chromosomes by
combining the front of one with the back of the
other, and vice versa, to produce two new
example, consider the following two
A crossover point might be chosen
between the sixth and seventh genes.
110100 | 110001001
010101 | 000111101
Now the chromosome parts are
recombined as follows:
110100 | 000111101 => 110100000111101
010101 | 110001001 => 010101110001001
point crossover is the most
commonly used form, but it is also
possible to apply crossover with two or
more crossover positions.
two point crossover, two points are
chosen that divide the chromosomes into
two sections, with the outer sections
considered to be joined together to turn
the chromosome into a ring. The two
sections are swapped with each other.
100110001 10 1100 001
011100110 01 0110 110
• Here, a probability, p, is used to determine
whether a given bit from parent 1 will be used,
or from parent 2.
• In other words, a child can receive any random
bits from each of its parents.
Parent 1: 100011001
Parent 2: 001101110
100110001 1 1 0 10 0 1 01
011100110 0 0 1 11 0 0 10
Similarto Hill-Climbing, which involves
generating a possible solution to the
problem and moving toward a better
solution than the current one until a
solution is found from which no better
solution can be found.
Mutation is a unary operator (it is applied
to just one argument – a single gene) that
is usually applied with a low probability.
Mutation simply involves reversing the
value of a bit in a chromosome.
For example, with a mutation rate of 0.01, it
might be expected that one gene in a
chromosome of 100 genes might be
There are typically two ways in which a run
of a genetic algorithm is terminated.
Usually, a limit is put on the number of
generations, after which the run is
considered to have finished.
The run can stop when a particular solution
has been reached, or when the highest
fitness level in the population has reached a
In some cases, genetic algorithms are used
to generate interesting pictures.
In these cases, human judgment must be
used to determine when to terminate.
Use of Genetic Algorithm to maximize
value of a mathematic function.
Maximize the function:
over the range of ‘x’ from 1 to 15.
‘x’ is in radians.
Each chromosome represents a possible
value of ‘x’ using four bits.
Wewill use a population size of four
• The first step is to generate a random
population, which is our first generation:
• To calculate the fitness of a chromosome, we
need to first convert it to a decimal integer and
then calculate f(x) for this integer.
• We will assign a fitness numeric value from 0 to
100, where 0 is the least fit and 100 is the most fit.
• f(x) generates real numbers between -1 and 1.
• We will assign a fitness of 100 to f(x)=1 and
fitness of 0 to f(x)= -1.
• Fitness of 50 will be assigned to f(x)=0.
The fitness ratio of a chromosome is that
chromosome’s fitness as a percentage of
the total fitness of the population.
Chromosome Genes Integer F(x) Fitness Fitness
value F’(x) ratio
C1 1001 9 0.41 70.61 46.3%
C2 0011 3 0.14 57.06 37.4%
C3 1010 10 -0.54 22.80 14.9%
C4 0101 5 -0.96 2.05 1.34%
Fitness values of First generation
Nowwe need to run a single step of our
genetic algorithm to produce the next
• First step is to select which chromosomes will
Roulette-wheel selection involves using the
fitness ratio to randomly select chromosomes to
The range of real numbers from 0 to 100 is
divided up between the chromosomes
proportionally to each chromosome’s fitness.
A random number is now generated between 0
to 100. This number will fall in the range of one of
the chromosomes, and this chromosome has
been selected for reproduction.
The next random number is used to select the
Hence, fitter chromosomes will tend to produce
more offspring than less fit chromosomes.
Itis important that this method does not
stop less fit chromosomes from
reproducing at all.
We will now need to generate four
random numbers to find the four parents
that will produce the next generation.
We first choose 56.7, which falls in the
range of c2. So, c2 is parent 1.
Next, 38.2 is chosen, so its mate is c1
We now combine c1 and c2 to produce
Select a random crossover point.
10 | 01
00 | 11
Crossover is applied to produce two
offspring, c5 and c6:
Similarly, we calculate c7 and c8 from
parents c1 and c3:
Observe that c4 did not get a chance to
reproduce. So its genes will be lost.
c1 was the fittest of all chromosomes. So,
it could reproduce twice, thus passing on
its highly fit genes to all members of the
Chromosome Genes Integer F(x) Fitness Fitness
value F’(x) ratio
C5 1011 11 -1 0 0%
C6 0001 1 0.84 92.07 48.1%
C7 1000 8 0.99 99.47 51.9%
C8 1011 11 -1 0 0%
It is possible to explain genetic
algorithms by comparison with natural
evolution: small changes that occur on a
selective basis combined with
reproduction will tend to improve the
fitness of the population over time.
John Holland invented schemata to
provide an explanation for genetic
algorithms that is more rigorous.
of numbers are used to represent
input patterns in classifier systems. In these
patterns, * is used to represent “any value”
or “don’t care”, so that the following string:
matches the following strings:
A schema is a string of bits that represents a
possible chromosome, using * to represent “any
A schema is said to match a chromosome if the
bit string that represents the chromosome
matches the schema in the way shown above.
This matches the following four chromosomes
0110 0111 1110 1111
A schema with n *’s will match a total of
Each chromosome of r bits will match 2^r
TheDefining length of a schema is
defined as the distance between the first
and last defined bits in the schema.
The defining length for all the above
schemata is 4.
of the schema is defined a the
number of defined bits in the schema.
The order of all the above schemata is 4.
We denote the order of schema as O(S).
Order of the schema tells us how specific it
Consider the following population of 10
chromosomes, each of length 32.
Let us consider the following schema:
This schema is matched by three
chromosomes in our population:
We say that schema s0 matches three
chromosomes in generation ‘i’ and write
this as follows:
m(s0,i) = 3
The fitness of a schema, S, in generation ‘i’ is
written as follows:
The fitness of a schema is defined as the average
fitness of the chromosomes in the population that
match the schema.
Hence if we define the fitness of c4, c5, and c10
Hence, thefitness of the schema s0 is
defined as the average of these three
We will now consider factors which affect
the likelihood of a particular schema
surviving from one generation to the
Let us assume that there is a chromosome
that matches a schema, S, in the
population at time i.
The number of occurrences of S in the
population at time i is:
Number of occurrences of S in the
population in the subsequent generation
The fitness of S in generation i is
We will calculate the probability that a given
chromosome, c, which matches the schema S at time
i, will reproduce and thus its genes will be present in
the population at time i+1.
The probability that a chromosome will reproduce is
proportional to its fitness, so the expected number of
offspring of chromosome c is:
Where a(i) is the average fitness of the
chromosomes in the population at time i.
Because chromosome c is an instance of
schema S, we can thus deduce:
where C1 to Cn are the chromosomes in
the population at time i that match
Let us compare this with the definition of
the fitness of schema S, f(S,i), which is
defined as follows:
By combining the above stated formulas,
The more fit a schema is compared with the
average fitness of the current population, the
more likely it is that that schema will appear in a
subsequent population of chromosomes.
There will be fewer occurrences of a given
schema whose fitness is lower than the average
fitness of the population and more occurrences
of a given schema whose fitness is higher than
Both mutation and crossover can destroy
the presence of a schema.
A given schema can be said to have
survived crossover, if the crossover
operation produces a new chromosome
that matches the schema from a parent
that also matches the schema.
For a schema to survive crossover, the
crossover point must be outside the
Hence, the probability that a schema S of
defining length dL(S) and of length L(S)
will survive crossover is
This formula assumes that crossover is
applied to each pair of parents that
Hence, after certain modifications of the
Effect of Mutation:
Probability that mutation will be applied
Hence, a schema will survive mutation if
mutation is not applied to any of the
defined bits. The probability of survival
can be defined as:
Hence, a schema is more likely to survive
mutation if it has lower order
We can combine all the equations we have to
give one equation that defines the likelihood of a
reproduction using crossover and mutation.
That equation represents the schema theorem,
developed by Holland, which can be stated as:
“Short, low order schemata which are fitter than
the average fitness of the population will appear
with exponentially increasing regularity in
The short, low order, high-fitness schemata are
known as building blocks.
Genetic algorithms work well when a small group of
genes that are close together represent a feature that
contributes to the fitness of a chromosome.
Randomly selecting bit to represent particular
features of a solution is not good enough.
Bits should be selected in such a way that they group
naturally together into building blocks, which
genetic algorithm are designed to manipulate.
Genetic Algorithms can be mislead or
deceived by some building blocks into
heading toward sub-optimal solutions.
One way to avoid effects of deception is
to use inversion, which is a unary
operator that reverses the order of a
subset of the bits within a chromosome.
Another way to avoid deception is to use
Messy Genetic Algorithms.
Developed as an alternative to standard
Each bit is labeled with its position.
A chromosome does not have to contain a
value for each position, and, a given
position in a chromosome can have more
than one value.
Each bit in a chromosome is represented by
a pair of numbers: the first number
represents the position within the
chromosome, and the second number is the
mGA’s use the standard mutation
operation. But, instead of crossover, they
use splice and cut operations.
Two chromosomes can be spliced
together by simply joining one to the end
The cut operator splits one chromosome,
into two smaller chromosomes.
Theprocess for running this genetic
algorithm is as follows:
1. Produce a random population of chromosomes. We
will start with 100.
2. Determine a score for each chromosome by
playing its strategy against a number of opponents.
3. Select chromosomes for the population to
4. Replace the previous generation with new
population produced by reproduction.
5. Return to step 2.
Most Combinatorial search problems can
be successfully solved using genetic
Genetic Algorithms can be applied to:
• Travelling Salesman Problem
• The Knight’s tour.
• The CNF- satisfiability problem.
• Robot Navigation.
• Knapsack Problem
• Time Table problem.