100% found this document useful (1 vote)
461 views

Unit 3 Genetic Algorithm Final

3rd Year IT Subject CCS 364 SOFT COMPUTING Dr.Kalaivazhi Vijayaragavan AAMEC

Uploaded by

Dr.Kalaivazhi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
461 views

Unit 3 Genetic Algorithm Final

3rd Year IT Subject CCS 364 SOFT COMPUTING Dr.Kalaivazhi Vijayaragavan AAMEC

Uploaded by

Dr.Kalaivazhi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Soft Computing Genetic Algorithms

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

➠ 3 .1 Genetic Algorithm Concept


 As early as 1962, John Holland's work on adaptive systems laid the foundation for later
developments. By the 1975, the publication of the book Adaptation in Natural and Artificial
Systems, by Holland and his students and colleagues.
 Early to mid-1980s, genetic algorithms were being applied to a broad range of subjects. In
1992 John Koza has used genetic algorithm to evolve programs to perform certain tasks. He
called his method genetic programming.
 Genetic Algorithm (GA) is a search technique used in computing to find true or
approximate solutions to optimization and search problems. Genetic algorithms are
categorized as global search heuristics.
 Genetic algorithms are a particular class of evolutionary algorithms that use techniques
inspired by evolutionary biology such as inheritance, mutation, selection and
recombination.
 GA tries to perform an intelligent search for a solution from a nearly infinite number of
possible solutions. It works with coding variables. Genetic algorithm and their variants are
sometimes referred to as methods of population based optimization.
 Genetic algorithms are also categorized as global search heuristics. Actually they are a
particular class of evolutionary algorithms which uses techniques inspired by evolutionary
biology such as inheritance, mutation, selection, and crossover.
 A typical genetic algorithm requires two things to be defined :
1. Genetic representation of the solution domain.

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms
2. Fitness functions to evaluate the solution domain.

❒ Components of Genetic Algorithm


 Genetic algorithm consists of encoding schemes, fitness evaluations, parent selection,
crossover operators, and mutation operators.
 After an initial population is randomly generated, the algorithm evolves the through three
operators:
1. Selection which equates to survival of the fittest;
2. Crossover which represents mating between individuals;
3. Mutation which introduces random modifications.
 The Genetic algorithm starts off with an initial population P(0) and it is followed by
Selection, Crossover and Mutation processes. These processes are shown in Fig. 3.1.1.

Fig. 3.1.1 : One generation of GA process

❒ Psuedocode of Genetics Algorithm


1. Choose the initial population of individuals
2. Evaluate the fitness of each individual in population
3. Repeat until termination condition satisfied :
3a. Selection : Select the individuals with greater fitness for reproduction
3b. Crossover : Breed new individuals through crossover
3c. Mutation : Apply probabilistic mutation on new individuals

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms
3d. Form a new population with these offsprings.
4. Terminate

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.2 Outline of Basic Genetic Algorithm


1. [Start] Generate random population of n chromosomes (suitable solutions for the problem).
2. [Fitness] Evaluate the fitness f(x) of each chromosome x in the population.
3. [New population] Create a new population by repeating following steps until the new
population is complete.
a. [Selection] Select two parent chromosomes from a population according to their fitness
(the better fitness, the bigger chance to be selected).
b. [Crossover] with a crossover probability cross over the parents to form a new offspring
Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D
Soft Computing Genetic Algorithms
(children). If no crossover was performed, offspring is an exact copy of parents.
c. [Mutation] with a mutation probability mutate new offspring at each locus (position in
chromosome).
d. [Accepting] Place new offspring in a new population.
4. [Replace] Use new generated population for a further run of algorithm.
5. [Test] If the end condition is satisfied, stop and return the best solution in current
population.
6. [Loop] Go to step 2.
❒ GA Steps
Step 1 : Set population size and probability
Step 2 : Define fitness function
Step 3 : Generate initial population
Step 4 : Calculate fitness for each chromosome
Step 5 : Mating of chromosomes
Step 6 : Create offspring-crossover and mutation
Step 7 : Offspring in new population
Step 8 : Repeat Step 5 until new = initial population
Step 9 : Replace initial population with new

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms
Step 10 : To Step 4 and repeat until criteria achieved

Fig. 3.1.3 : Flow diagram of the genetic algorithm process

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms

➥ 3.1.3 Advantages of Genetic Algorithms


 Genetic Algorithm is a stochastic algorithm.
 Randomness as an essential role in both selection and reproduction phases.
 Genetic algorithms always consider a population of solutions. A population base algorithm
is also very amenable for parallelization.
 There is no particular requirement on the problem before using genetic algorithms, so it can
be applied to resolve any problem (optimization).
 GAs are a new field and parts of the theory have still to be properly established. We can
find almost as many opinions on GAs as there are researchers in this field.

➥ 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.

➥ 3.1.5 Differences between GAs and Traditional Methods


1. Genetic algorithms a coded form of the function values i.e. parameter set, rather than with
the actual values themselves. For example, if we want to find the minimum of the function
f(x) = x3 + x2 + 5, the GA would not deal directly with x or y values, but with strings that
encode these values. For this case, strings representing the binary x values should be used.
2. Genetic algorithms use a set or population of points to conduct a search, not just a single
point on the problem space. This gives GAs the power to search noisy spaces littered with
local optimum points. Instead of relying on a single point to search through the space, the
GAs looks at many different areas of the problem space at once, and uses all of this
information to guide it.
3. Genetic algorithms use only payoff information to guide themselves through the problem
space. Many search techniques need a variety of information to guide themselves. Hill
climbing methods require derivatives, for example. The only information a GA needs is
some measure of fitness about a point in the space. Once the GA knows the current measure
of “goodness” about a point, it can use this to continue searching for the optimum.
4. GAs are probabilistic in nature, not deterministic. This is a direct result of the
randomization techniques used by GAs.
5. GA is inherently parallel. Here lies one of the most powerful features of genetic algorithms.
GA's, by their nature, are very parallel, dealing with a large number of points
simultaneously.

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms

Parameters Genetic Algorithms Traditional Methods


Work with Coding of parameter set Parameters directly
Use information Payoff i.e. objective function Payoff plus derivatives etc.
Rules Probabilistic Fully deterministic
Search A population of points A population of points a single point

➠ 3.2. Basic Operators


 Generation of successors is determined by a set of operators that recombine and mutate
selected members of the current population. Operators correspond to idealized versions of
the genetic operations found in biological evolution.

Fig. 3.2.1
 Genetic operator is the operator for generating new gene based on fitness of each
individual.

➥ 3.2.1 Selection Operator


 Key idea : give preference to better individuals, allowing them to pass on their genes to the
next generation.
 It determines which parents participate in producing offspring for the next generation. The
goodness of each individual depends on its fitness.
 Fitness may be determined by an objective function or by a subjective judgement.
 Selection replicates the most successful solutions found in a population at a rate
proportional to their relative quality.
 A common selection method in genetic algorithm is fitness proportionate selection, in
which the number of times an individual is expected to reproduce is equal to its fitness
divided by the average of fitness in the population.
 Common selection methods used in GAs are
a. Fitness Proportionate Selection
b. Rank Selection
c. Tournament Selection

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms

➥ 3.2.2 Crossover Operator


 A binary variation operator is called recombination or crossover. A method of mixing good
solutions to produce better ones is called crossover.

 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.

➥ 3.2.2.1 Crossover Types


1. Single-point crossover,
2. Two-point crossover,
3. Uniform crossover

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms
❒ 1. One point crossover
 One point crossover is the most basic crossover operator. Crossover point on the genetic
code is selected at random and two parent chromosomes are interchanged at this point.
Binary string from beginning of chromosome to the crossover point is copied from one
parent, the rest is copied from the second parent.
Parent 1 Parent 2 Offspring

+ + =
=
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 Point Crossover


In this one-point crossover, a random crossover point is selected and the tails of its two
parents are swapped to get new off-springs.

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms

❒ 2. Two Point Crossover


 Two-point crossover is very similar to single-point crossover except that two cut-points
are randomly generated instead of one.
 Two point crossover : Two crossover points are selected and the part of the chromosome
string between these two points is then swapped to generate two children. binary string
from beginning of chromosome to the first crossover point is copied from one parent,
the part from the first to the second crossover point is copied from the second parent and
the rest is copied from the first parent.
Parent 1 Parent 2 Offspring

+ =

11001011+ 11011111 = 11011111


 Example :
Parent 1 : XX|XXX|XX
Parent 2 : YY|YYY|YY
Offspring 1 : X X Y Y Y X X
Offspring 2 : Y Y X X X Y Y
❒ 3. Uniform Crossover
 In uniform crossover, a value of the first parent’s gene is assigned to the first offspring
and the value of the second parent’s gene is to the second offspring with a probability
value pc.
 With probability pc the value of the first parent’s gene is assigned to the second
offspring and the value of the second parent’s gene is assigned to the first offspring.
 Example :
Parent 1 : XXXXXXX
Parent 2 : Y Y Y Y Y Y Y
Offspring 1 : X Y X Y Y X Y
Offspring 2 : Y X Y X X Y X
 Crossover between 2 good solutions MAY NOT ALWAYS yield a better or as good a
solution. Since parents are good, probability of the child being good is high. If offspring
is not good (poor solution), it will be removed in the next iteration during “Selection”.

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms

 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.2.3 Effects of Genetic Operators


 Using selection alone will tend to fill the population with copies of the best individual from
the population
 Using selection and crossover operators will tend to cause the algorithms to converge on a
good but sub-optimal solution
 Using mutation alone induces a random walk through the search space.
 Using selection and mutation creates a parallel, noise-tolerant, hill climbing algorithm
 Only crossover can combine information from two parents
 Only mutation can introduce new information (alleles)
 Crossover does not change the allele frequencies of the population.
➠ 3.3 Inversion and Deletion

➥ 3.3.1 Inversion
 String is selected from the population. The bits between two random sites are inverted.
Fig. 4.3.1 shows inversion.

Fig. 3.3.1 : Inversion


 Two points are selected along the length of the chromosome, the chromosome is cut at
those points and the end of the selection cut, gets reversed. After inversion new
chromosome is generated and is added to the existing population.
Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D
Soft Computing Genetic Algorithms

 In continuous inversion, inversion was applied with specified inversion probability Pr to


each new individual when it is created.
 Linear+ End inversion operator is minimizes the property of linear inversion to disrupt the
alleles present near the center of the string disproportionately to those of alleles present
near the ends.
 The gene is to be used in fitness function the same as before inversion and it remains same
as after inversion operation also.
➥ 3.3.2 Deletion and Duplication
 These are the low level operator pair.
 Any two or more bits at random in order are selected and the previous bits are duplicated.
 Example :
Before duplication : 0 0 10 0 1 0
Deletion : 0 0 10 _ _ 0
Duplication : 0 0 10 1 0 0

➠ 3.4 Mutation Operator


 The mutation operator introduces new genetic structures in the population by randomly
changing some of its building blocks, helping the algorithm escape local minima traps.
 This operator randomly flips some of the bits in a chromosome. For example, the string
00000100 might be mutated in its second position to yield 01000100. Mutation can occur at
each bit position in a string with some probability, usually very small.
 It helps to increase searching power. In the Mutation process, each element in an individual
is changed with a small probability of pm. With some low probability, a portion of the new
individuals will have some of their bits flipped.
 Main purpose is to maintain diversity within the population and inhibit premature
convergence. Mutation alone induces a random walk through the search space.
 The mutation rate is usually kept low so good chromosomes obtained from crossover are
not lost. Mutation increases diversity in the population and thus allows the algorithm to
search more distinct points.
 The mutation depends on the encoding as well as the crossover. For example when we are
encoding permutations, mutation could be exchanging two genes.
 It is the process by which a string is deliberately changed so as to maintain diversity in the
population set. Mutation probability determines how often the parts of a chromosome will
be mutated.
 Mutation adds new information in a random way to the genetic search process and
ultimately helps to avoid getting trapped at local optima. It is an operator that introduces
diversity in the population whenever the population tends to become homogeneous due to
Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D
Soft Computing Genetic Algorithms
repeated use of reproduction and crossover operators.

 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

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms
 Interchanging : Two random positions of the string are chosen and the bits corresponding
to those positions are interchanged.
Parent 10110101
Child 11110001

 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

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms
X1 = 6 5 4 1 3 5 3 2

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

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms

Offspring 2 65416601 17
Offspring 3 65921232 –2
Offspring 4 23413585 –5
Offspring 5 87921201 11
Offspring 6 23926601 5

Average fitness : 6.833 Best : 17 Worst : – 5


So that, the overall fitness is improved , since the average is better and worst is improved.
Average fitness = (15 + 17 + (– 5) + (– 2) + 11 + 5)/ 6
= 6.8333

➥ 3.4.1 Mutation Rate (Pm)


 When individuals are not subjected to crossover, they remain unmodified. The mutation
operator is used to change some elements in selected individuals with a probability P m,
leading to additional genetic diversity to help the search process escape from local optimal
traps.
 Small Pm values are commonly adopted in genetic algorithms.

➠ 3.5 Bit-wise Operators


 Encoding is the process of representing the solution in the form of a string that conveys the
necessary information. It is a process of representing individual genes. The process can be
performed using bits, numbers, trees, array or any other objects.
 Just as in a chromosome, each gene controls a particular characteristic of the individual;
similarly, each bit in the string represents a characteristic of the solution.
 When choosing an encoding method rely on the following key ideas
1. Use a data structure as close as possible to the natural representation.
2. Write appropriate genetic operators as needed.
3. If possible, ensure that all genotypes correspond to feasible solutions.
4. If possible, ensure that genetic operators preserve feasibility

➥ 3.5.1 Binary Encoding


 Most common method of encoding. Chromosomes are strings of 1s and 0s and each
position in the chromosome represents a particular characteristic of the problem. The length
of the string is usually determined according to the desired solution accuracy.
Chromosome A 110100011010
Chromosome B 011111111100

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms
 Octal encoding : This encoding uses string made up of octal numbers 0 to 7.
Chromosome A 03467216
Chromosome B 15723314
 Hexadecimal encoding : This encoding uses string made up of hexadecimal numbers 0 to
9 and A to F.
Chromosome A 9CE7
Chromosome B 3DBA

➥ 3.5.1.1 Permutation Encoding


 Useful in ordering problems such as the Traveling Salesman Problem (TSP). Example : In
TSP, every chromosome is a string of numbers, each of which represents a city to be
visited.
 Permutation encoding is used in scheduling and ordering problems. Every chromosome is a
string of numbers, which represents numbers in a sequence. The kind of encoding usually
needs to make some corrections after the crossover and mutation operating procedures
because any transformation might create an illegal situation.
Chromosome A 1 5 3 2 6 4 7 9 8
Chromosome B 8 5 6 7 2 3 1 4 9
 Example of problem : Traveling Salesman Problem (TSP).
 The problem : There are cities and given distances between them. Traveling salesman has
to visit all of them, but he does not to travel very much. Find a sequence of cities to
minimize traveled distance. Encoding : Chromosome says order of cities, in which
salesman will visit them.

➥ 3.5.1.2 Value Encoding


 Used in problems where complicated values, such as real numbers, are used and where
binary encoding would not suffice. It is good for some problems, but often necessary to
develop some specific crossover and mutation techniques for these chromosomes.
 Example of problem : Finding weights for neural network.
 The problem : There is some neural network with given architecture. Find weights for
inputs of neurons to train the network for wanted output.
 Encoding : Real values in chromosomes represent corresponding weights for inputs.
Chromosome A 1.2324 5.3243 0.4556 2.3293 2.4545
Chromosome B ABDJEIFJDHDIERJFDLDFLFEGT
Chromosome C (back), (back), (right), (forward), (left)

➥ 3.5.1.3 Tree Encoding


Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D
Soft Computing Genetic Algorithms
 In tree encoding every chromosome is a tree of some objects, such as functions or
commands in programming language. It is used in genetic programming.
 Example of problem : Finding a function from given values.
 The problem : Some input and output values are given. Task is to find a function, which
will give the best (closest to wanted) output to all inputs.
 Encoding : Chromosome is functions represented in a tree.

Chromosome A Chromosome B

➠ 3.6 Fitness Function


 Fitness is an important concept in genetic algorithms. The fitness of a chromosome
determines how likely it is that it will reproduce. Fitness is usually measured in terms of
how well the chromosome solves some goal problem.
 Fitness can also be subjective (aesthetic). E.g., if the genetic algorithm is to be used to sort
numbers, then the fitness of a chromosome will be determined by how close to a correct
sorting it produces.
 A fitness function quantifies the optimality of a solution (chromosome) so that particular
solution may be ranked against all the other solutions. A fitness value is assigned to each
solution depending on how close it actually is to solving the problem.
 Ideal fitness function correlates closely to goal plus quickly computable.
 Example : In TSP, f(x) is sum of distances between the cities in solution. The lesser the
value, the fitter the solution is.
 The performance of the individual strings is measured by a fitness function. A fitness
function is a problem specific user defined heuristic. After each iteration, the members are
given a performance measure derived from the fitness function and the “fittest” members of
the population will propagate the next iteration.
Fitness = Fi, Hit = i, Survival = i, Death= i
Fi = 2 i – i +  i
 The fitness function is defined over the genetic representation and measures the quality of
the represented solution. The fitness function is always problem dependent.

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms
 For instance, in the knapsack problem we want to maximize the total value of objects that
we can put in a knapsack of some fixed capacity. A representation of a solution might be an
array of bits, where each bit represents a different object and the value of the bit (0 or 1)
represents whether or not the object is in the knapsack.
 Not every such representation is valid, as the size of objects may exceed the capacity of the
knapsack. The fitness of the solution is the sum of values of all objects in the knapsack if
the representation is valid or 0 otherwise. In some problems, it is hard or even impossible to
define the fitness expression; in these cases, interactive genetic algorithms are used.

➠ 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.

Fig. 3.7.1 : Genetic algorithm cycle


Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D
Soft Computing Genetic Algorithms
GA solved Example

Below are the steps to be followed to solve any optimization problem with the help of GA.

 Step 1- Choose an encoding technique, a selection operator, and a crossover operator

 Step 2- Choose a population size

 Step 3- Randomly choose the initial population

 Step 4- Select parental chromosomes

 Step 5- Perform Crossover (random crossover points)

 Step 6- Evaluation of offsprings

 Step 7- Repeat the process

Now we’ll see an example of a simple optimization problem and try to solve it with the

help of the steps mentioned above.

Question
Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D
Soft Computing Genetic Algorithms

Answer

Step 1-

 Encoding technique- Binary encoding

 Selection operator- Roulette Wheel Selection

 Crossover operator- Single point crossover

Step 2-

Population size (n) = 4

Step 3-

Initial population (x value) = 13, 24, 8, 19

Step 4-

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms

We see that if the Roulette wheel is spun four times, we’ll get 24 twice and 13 and 19 once.

So possible parental combinations are (24,13) and (24,19).

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms

Step 5-

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms

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

condition is not satisfied.

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms
3.8 Two Marks Questions with Answers
Q. 1 What is genetic algorithm ?
Ans. : A genetic algorithm is a search technique used in computing to find true or
approximate solutions to optimization and search problems.
Q. 2 What do you mean genetic programming ?
Ans. : Genetic programming is genetic algorithm wherein the population contains programs
rather than bit strings.

Q. 3 How is a population with increasing fitness generated ?


Ans. : If two parents have superior fitness, there is a good chance that a combination of their
genes will produce an offspring with even higher fitness.
Q. 4 Define chromosomes.
Ans. : Each artificial “chromosomes” consists of a number of “genes” and each gene is
represented by 0 or 1.
Q. 5 What is Roulette-Wheel Selection ?
Ans. : The commonly-used reproduction operator is the proportionate reproduction operator
where a string is selected for the mating pool with a probability proportional to its fitness.
Thus, the ith string in the population is selected with a probability proportional to Fi. Since the
population size is usually kept fixed in a simple GA, the sum of the probability of each string
being selected for the mating pools must be one.
Q. 6 List the method of reproduction.
Ans. : There are primary methods : Crossover and Mutation.
Q. 7 What is fitness ratio ?
Ans. : The relation between the average fitness of a schema and the average fitness of the
population.
Q. 8 What is use of crossover operator ?
Ans. : A crossover operator is used to recombine two strings to get a better string. In
crossover operation, recombination process creates different individuals in the successive
generations by combining material from two individuals of the previous generation
Q. 9 State the importance of genetic algorithm.
Ans. : Genetic algorithm is that the problem solving strategy involves using “the strin g’s
fitness to direct the search; therefore they do not require any problem-specific knowledge of
the search space and they can operate well on search spaces that have gaps, jumps or noise”.
As each individual string within a population directs the search, the genetic algorithm searches,
in parallel, numerous points on the problem state space with numerous search directions.
Q. 10 Explain two point crossover.
Ans. : Two crossover points are selected. Binary string from the beginning of the
chromosome to the first crossover point is copied from the first parent, the second crossover
Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D
Soft Computing Genetic Algorithms
point is copied from the other parent. The rest is copied from the first parent again.
Q. 11 State the taxonomy of crossover operator.
Ans. :
1. Single point crossover
2. Two point crossover
3. Uniform crossover

Q. 12 Which are the operator used in genetic algorithm ?


Ans. : Selection, crossover and mutation are the operator used in genetic algorithm.
Q. 13 Define the term encoding.
Ans. : Encoding is the process of representing the solution in the form of a string that conveys
the necessary information. It is a process of representing individual genes. The process can be
performed using bits, numbers, trees, array or any other objects.
Q. 14 Explain use of tree encoding.
Ans. : In tree encoding every chromosome is a tree of some objects, such as functions or
commands in programming language. It is used in genetic programming.
Q. 15 Reproduction is sometime called as selection operator. Why ?
Ans. : Reproduction selects good strings in a population and forms a mating pool. This is one
of the reasons for the reproduction operation to be sometimes known as the selection operator.
Q. 16 What are the various methods of selecting chromosomes for parents to
crossover?
Ans. : Various methods are :
1. Roulette - Wheel selection 2. Boltzmann selection
3. Tournament selection 4. Rank selection
5. Steady state selection
Q. 17 Define an uniform crossover.
Ans. : In Uniform Crossover, a value of the first parent's gene is assigned to the first offspring
and the value of the second parent's gene is to the second offspring with probability 0.5.
Q. 18 Explain the “Darwinian theory of survival”
Ans. : More individuals are produced each generation that can survive. Phenotypic variation
exists among individuals and the variation is heritable. Those individuals with heritable traits
better suited to the environment will survive.

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms

Q. 19 Compare and contract genetic algorithm with traditional algorithm.


Ans. :
Genetic algorithm Traditional algorithm
GA generates a population of points at each It generates a single point at each
iteration. The best point in the population iteration. The sequence of points
approaches an optimal solution. approaches an optimal solution.
Selects the next population by computation Selects the next point in the sequence by
which uses random number generators a deterministic computation.
Convergence in each iteration in problem Improvement in each iteration is problem
independent specific
Rules are probabilistic. Rules are fully deterministic.

Q. 20 What two requirements should a problem satisfy it by a genetic algorithm?


Ans. : GA can only be applied to problems that satisfy the following requirements:
i. The fitness function can be well defined.
ii. Solutions should be decomposable into steps (building blocks) which could be then
encoded as chromosomes
Q. 21 List the basic components used in all genetic algorithms.
Ans. : The basic components common to almost all genetic algorithms are:
 Fitness function for optimization
 A population of chromosomes
 Selection of which chromosomes will reproduce
 Crossover to produce next generation of chromosomes
 Random mutation of chromosomes in new generation
Q. 22 What is role of fitness function in GA?
Ans. :
 A fitness function is a type of objective functions which summarizes the goodness of a
solution with a single figure of merit.
 A fitness function quantifies the optimality of a solution (chromosome) so that particular
solution may be ranked against all the other solutions. A fitness value is assigned to each
solution depending on how close it actually is to solving the problem.
Q. 23 Define the term encoding
Ans. : Encoding is the process of representing the solution in the form of a string that conveys
the necessary information. It is a process of representing individual genes. The process can be
performed using bits, numbers, trees, array or any other objects
Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D
Soft Computing Genetic Algorithms
Q. 24 Explain use of tree encoding.
Ans. : In tree encoding every chromosome is a tree of some objects, such as functions or
commands in programming language. It is used in genetic programming.
Q. 25 Reproduction is sometime called as selection operator. Why?
Ans. : Reproduction selects good strings in a population and forms a mating pool. This is one
of the reasons for the reproduction operation to be sometimes known as the selection operator.

➠ 3.9 Multiple Choice Questions with Answers


Q. 1 Genetic Algorithm are a part of _.
(a) evolutionary Computing
(b) inspired by Darwin's theory about evolution - “survival of the fittest”
(c) are adaptive heuristic search algorithm based on the evolutionary ideas of natural
selection and genetics
(d) all of the above
Ans. : (d) all of the above

Q. 2 Which GA operation is computationally most expensive?


(a) Initial population creation.
(b) Selection of sub - population for mating.
(c) Reproduction to produce next generation.
(d) Convergence testing.
Ans. : (c) Reproduction to produce next generation
Q. 3 Which of the following is not true for Genetic algorithms?
(a) It is a probabilistic search algorithm.
(b) It is guaranteed to give global optimum solutions.
(c) If an optimization problem has more than one solution, then it will return all the
solutions.
(d) It is an iterative process suitable for parallel programming.
Ans. : (b) It is guaranteed to give global optimum solutions
Q. 4 The purpose of the fitness evaluation operation is
(a) To check whether all individual satisfies the constraints given in the problem.
(b) To decide the termination point.
(c) To select the best individuals.
(d) To identify the individual with worst cost function.
Ans. : (c) To select the best individuals
Q. 5 Roulette wheel selection scheme is preferable when
(a) Fitness values are uniformly distributed.
(b) Fitness values are non - uniformly distributed.

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D


Soft Computing Genetic Algorithms
(c) Needs low selection pressure.
(d) Needs high population diversity
Ans. : (a) Fitness values are uniformly distributed
Q. 6 Tournament Selection has
(a) Low population diversity and moderate selection pressure
(b) High population diversity and Moderate selection pressure
(c) Moderate population diversity and high selection pressure
(d) High population diversity and low selection pressure
Ans. : (c) Moderate population diversity and high selection pressure
Q. 7 The purpose of the fitness evaluation operation is
(a) To check whether all individual satisfies the constraints given in the problem.
(b) To decide the termination point.
(c) To select the best individuals.
(d) To identify the individual with worst cost function
Ans. : (c) To select the best individuals

Dr. V.Kalaivazhi B.E.,M.Tech.,Ph.D

You might also like