0% found this document useful (0 votes)
14 views65 pages

Unit - 5 (Genetic Algoritm)

Uploaded by

robingurung3333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views65 pages

Unit - 5 (Genetic Algoritm)

Uploaded by

robingurung3333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 65

UNIT – V

Genetic Algorithm (GA)


Genetic Algorithm (GA)
GAs are adaptive heuristic search algorithms based on the
evolutionary ideas of natural selection and genetics. As such
they represent an intelligent exploitation of a random search
used to solve optimization problems. Although randomized, GAs
are by no means random; instead they exploit historical
information to direct the search into the region of better
performance within the search space. The basic techniques of
the GAs are designed to simulate processes in natural systems
necessary for evolution, especially those that follow the
principles first laid down by Charles Darwin, "survival of the
fittest," because in nature, competition among individuals for
scanty resources results in the fittest individuals dominating over
the weaker ones.
Biological Background
The science that deals with the mechanisms responsible for
similarities and differences in a species is called Genetics. The
word "genetics" is derived from the Greek word "genesis"
meaning "to grow" or "to become.” The science of generics
helps us to differentiate between heredity and variations and
accounts for the resemblances and differences during the
process of evolution. The concepts of GAs are directly derived
from natural evolution and heredity.

Cell:- Every animal/human cell is a complex of many "small"


factories that work together. The center of all this is the cell
nucleus.
Chromosomes:- All the genetic information gets stored in the
chromosomes. Each chromosome is build of deoxyribonucleic acid
(DNA). In humans, chromosomes exist in pairs (23 pairs found).

The chromosomes are divided into several parts called genes. Genes
code the properties of species, i.e., the characteristics of an individual.

The possibilities of combination of the genes for one property are called
alleles, and a gene can take different alleles. For example, there is a
gene for eye color, and all the different possible alleles are black,
brown, blue and green(since no one has red or violet eyes!).

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 size of the gene pool helps in determining the diversity of the
individuals in the population. The set of all the genes of a specific
species is called genome. Each and every gene has a unique
position on the genome called locus.
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. One interesting point of evolution is
that selection is always done on the phenotype whereas the reproduction
recombines genotype. Thus, morphogenesis plays a key role between
selection and reproduction. In higher life forms, chromosomes contain
two sets of genes. These are known as diploids. In the case of conflicts
between two values of the same pair of genes, the dominant one will
determine the phenotype whereas the other one, called recessive, will still
be present and can be passed onto the offspring.
Comparison of Natural Evolution
and Genetic Algorithm Terminology
Basic Terminologies in GA
The two distinct elements in the GA are individuals and
populations. An individual is a single solution while the
population is the set of individuals currently involved in the
search process.

1. Individuals:- An individual is a single solution. An individual


groups together two forms of solutions as given below:
• The chromosome which is the raw "genetic" information
(genotype) that the GA deals.
• The phenotype which is the expressive of the chromosome in
the terms of the model.
• A chromosome is subdivided into genes. A gene is the GA's representation of a
single factor for a control factor. Each factor in the solution set corresponds to a
gene in the chromosome.
• A chromosome should in some way contain information about the solution that it
represents. The morphogenesis

function associates each genotype with its phenotype. It


simply means that each chromosome must define one unique solution, but it
does not mean that each solution is encoded by exactly one chromosome.
2. Genes:- Genes are the basic "instructions" for building a GA. A
chromosome is a sequence of genes. Genes may describe a
possible solution to a problem, without actually being the
solution. A gene is a bit string of arbitrary lengths. The bit string
is a binary representation of number of intervals from a lower
bound. A gene is the GA’s representation of a single factor value
for a control factor, where control factor must have an upper
bound and a lower bound. This range can be divided into the
number of intervals that can be expressed by the gene's bit
string. A bit string of length "n" can represent (2n - 1) intervals.
The size of the interval would be (range)/(2n - 1).
3. Fitness:- The fitness of an individual in a GA is the value of
an objective function for its phenotype. For calculating
fitness, the chromosome has to be first decoded and the
objective function has to be evaluated. The fitness not only
indicates how good the solution is, but also corresponds to
how dose the chromosome is to the optimal one.

4. Populations:- A population is a collection of individuals. A


population consists of a number of individuals being tested,
the phenotype parameters defining the individuals and some
information about the search space. The two important
aspects of population used in GAs are:

1. The initial population generation.

2. The population size.


For each and every problem, the population size will depend
on the complexity of the problem. It is often a random
initialization of population. In the case of a binary coded
chromosome this means chat each bit is initialized to a
random 0 or 1. However, there may be instances where the
initialization of population is carried out with some known
good solutions.
Genetic Algorithm vs. Traditional
Algorithms
GA differs from conventional optimization techniques in following
ways:

1.GAs operate with coded versions of the problem parameters


rather than parameters themselves.

2. Almost all conventional optimization techniques search from a


single point, but GAs always operate on a whole population of
points (strings).

3. GA uses fitness function for evaluation rather than derivatives.

4. GAs use probabilistic transition operates while conventional


methods for continuous optimization apply deterministic transition
operates.
Simple GA
GA handles a population of possible solutions. Each solution
is represented through a chromosome, which is just an
abstract representation. Coding all the possible solutions into
a chromosome is the first part, but certainly not the most
straightforward one of a GA. A set of reproduction operators
has to be determined, too. Reproduction operators are
applied directly on the chromosomes, and are used to perform
mutations and recombinations over solutions of the problem.
Appropriate representation and reproduction operators are the
determining factors, as the behavior of the GA is extremely
dependent on it.
The simple form of GA is given by the following.

1. Start with a randomly generated population.

2. Calculate the fitness of each chromosome in the population.

3. Repeat the following steps until n offsprings have been created:


 Select a pair of parent chromosomes from the current
population.

 With probability pc crossover the pair at a randomly chosen point

to form two offsprings.

 Mutate the two offsprings at each locus with probability pm

4. Replace the current population with the new population.

5. Go to seep 2.
GA consists of the following steps:-

1. Selection:- The first step consists in selecting individuals for


reproduction. This selection is done randomly with a
probability depending on the relative fitness of the individuals
so that best ones are often chosen for reproduction rather
than the poor ones.

2. Reproduction:- In the second step, offspring are bred by


selected individuals. For generating new chromosomes, the
algorithm can use both recombination and mutation.

3. Evaluation:- Then the fitness of the new chromosomes is


evaluated.

4. Replacement:- During the last step, individuals from the old


population are killed and replaced by the new ones.
BEGIN /* genetic algorithm"/
Generate initial population;
Compute fitness of each individual;
WHILE NOT finished DO LOOP
BEGIN
Select individuals from old generations
For mating;
Create offspring by applying
recombination and/or mutation
to the selected individuals;
Compute fitness of the new individuals;
Kill old individuals to make room for
new chromosomes and insert
offspring in the new generalization;
IF Population has converged
THEN finishes: =TRUE;
END
END
General Genetic Algorithm
Step 1: Create a random initial state: An initial population is
created from a random selection of solutions (which are
analogous to chromosomes). This is unlike the situation for
symbolic AI systems, where the initial state in a problem is
already given.

Step 2: Evaluate fitness: A value for fitness is assigned to each


solution (chromosome) depending on how close it actually is
to solving the problem (thus arriving to the answer of the
desired problem). (These "solutions" are not to be confused
with "answers" to the problem; think of them as possible
characteristics that the system would employ in order to reach
the answer.)
Step 3: Reproduce (and children mutate): Those
chromosomes with a higher fitness value are more likely to
reproduce offspring (which can mutate after reproduction).
The offspring is a product of the father and mother, whose
composition consists of a combination of genes from the two
(this process is known as "crossingover").

Step 4: Next generation: If the new generation contains a


solution that produces an output that is close enough or equal
to the desired answer then the problem has been solved. If
this is not the case, then the new generation will go through
the same process as their parents did. This will continue until
a solution is reached.
Operations in Genetic Algorithm
• Encoding:- Encoding is a process of representing individual
genes. The process can be performed using bits, numbers,
trees, arrays, lists or any other objects. The encoding
depends mainly on solving the problem. For example, one
can encode directly real or integer numbers.

1. Binary Encoding:- Each chromosome encodes a binary (bit)


string. Each bit in the string can represent some
characteristics of the solution. Every bit string therefore is a
solution but not necessarily the best solution.
Binary encoding gives many possible chromosomes with a
smaller number of alleles. On the other hand, this encoding is
not natural for many problems and sometimes corrections
must be made after genetic operation is completed. Binary
coded strings with 1s and 0s are mostly used. The length of
the string depends on the accuracy. In such coding

1. Integers are represented exactly.

2. Finite number of real numbers can be represented.

3. Number of real numbers represented increases with string


length.
2. Octal Encoding:- This encoding uses string made up of
octal numbers (0-7).

3. Hexadecimal Encoding:- This encoding uses string made


up of hexadecimal numbers (0-9, A-F).

4. Permutation Encoding(Real Number Coding):- In


permutation encoding, every chromosome is a string of
integer/real values, which represents number in a sequence.
Permutation encoding is only useful for ordering problems.
5. Value Encoding:- In value encoding , every chromosome is
a string of some values. Values can be anything connected
to problem, form numbers, real numbers or characters to
some complicated objects. On the other hand, for this
encoding it is often necessary to develop some new
crossover and mutation specific for the problem.
6. Tree Encoding:- This encoding is mainly used for evolving
program expressions for genetic programming. Every
chromosome is a tree of some objects such as functions and
commands of a programming language.
• Selection (Reproduction):- Selection is the process of
choosing two parents from the population for crossing. After
deciding on an encoding, the next step is to decide how to
perform selection, i.e., how to choose individuals in the
population that will create offspring for the next generation
and how many offspring each will create. The purpose of
selection is to emphasize fitter individuals in the population in
hopes that their offspring have higher fitness. Chromosomes
are selected from the initial population to be parents for
reproduction. The problem is how to select these
chromosomes. According to Darwin’s theory of evolution the
best ones survive to create new offspring.
Selection is a method that randomly picks chromosomes out
of the population according to their evaluation function. The
higher the fitness function, the better chance that an individual
will be selected. The selection pressure is defined as the
degree to which the better individuals are favored. The higher
the selection pressured, the more the better individuals are
favored. This selection pressure drives the GA to improve the
population fitness over successive generations.
There are two types of selection scheme
• Proportionate-based selection picks out individuals based
upon their fitness values relative to the fitness of the other
individuals in the population.
• Ordinal-based selection schemes select individuals not
upon their raw fitness, but upon their rank within the
population. This requires that the selection pressure is
independent of the fitness distribution of the population, and is
solely based upon the relative ordering (ranking) of the
population.
1. Random Selection:- This technique randomly selects a
parent from the population. In terms of disruption of generic
codes, random selection is a little more disruptive, on
average, than Roulette wheel selection.

2. Rank Selection:- Rank Selection ranks the population and


every chromosome receives fitness from the ranking. The
worst has fitness 1 and the best has fitness N. It results in
slow convergence bur prevents too quick convergence. It
also keeps up selection pressure when the fitness variance
is low. It preserves diversity and hence leads to a successful
search. In effect, potential parents are selected and a
tournament is held to decide which of the individuals will be
the parent.
There are many ways this can be achieved and two
suggestions are:

1. Select a pair of individuals at random. Generate a random


number R between 0 and 1. If R < r use the first individual as
a parent. If the R ≥ r then use the second individual as the
parent. This is repeated to select the second parent. The
value of r is a parameter to this method.

2. Select two individuals at random. The individual with the


highest evaluation becomes the parent. Repeat to find a
second parent.
3. Tournament Selection:- Unlike, the Roulette wheel
selection, the tournament selection strategy provides
selective pressure by holding a tournament competition
among Nu individuals. The best individual from the
tournament is the one with the highest fitness, who is the
winner of Nu. Tournament competitions and the winner are
then inserted into the mating pool. The tournament
competition is repeated until the mating pool for generating
new offspring is filled. The mating pool comprising the
tournament winner has higher average population fitness.
The fitness difference provides the selection pressure, which
drives GA to improve the fitness of the succeeding genes.
4. Roulette Wheel Selection:-
Roulette selection is one of the traditional GA selection
techniques. The commonly used reproduction operator is the
proportionate reproductive operator where a string is selected
from the mating pool with a probability proportional to the
fitness. The principle of Roulette selection is a linear search
through a Roulette wheel with the sums in the wheel weighted
in proportion to the individual's fitness values. A target value
is set, which is a random proportion of the sum of the fit
nesses in the population. The population is stepped through
until the target value is reached. This is only a moderately
strong selection technique, since fit individuals are not
guaranteed to be selected for, bur somewhat have a greater
chance.
A fit individual will contribute more to the target value, but if it
does not exceed it, the next chromosome in line has a
chance, and it may be weak. It is essential that the population
not be sorted by fitness, since this would dramatically bias the
selection. The Roulette process can also be explained as
follows: The expected value of an individual is individual's
fitness divided by the actual fitness of the population. Each
individual is assigned a slice of the Roulette wheel, the size of
the slice being proportional to the individual's fitness. The
wheel is spun N times, where N is the number of individuals in
the population. On each spin, the individual under the wheel's
marker is selected to be in the pool of parents for the next
generation.
This method is implemented as follows:

1. Sum the total expected value of the individuals in the


population. Let it be T.

2. Repeat N times:

i. Choose a random integer "r" between 0 and T.

ii. Loop through the individuals in the population,


summing the expected values, until the sum is greater
than or equal to "r." The individual whose expected value
puts the sum over this limit is the one selected.
.
• Crossover (Recombination):- Crossover is the process of taking
two parent solutions and producing from them a child. After the
selection (reproduction) process, the population is enriched with
better individuals. Reproduction makes clones of good strings but
does not create new ones. Crossover operator is applied to the
mating pool with the hope that it creates a better offspring.

Crossover is a recombination operator that proceeds in three


steps:

1. The reproduction operator selects at random a pair of two


individual strings for the mating.

2. A cross site or crossover point is selected at random along the


string length.
3. Finally, the position values are swapped between the two
strings following the cross site or crossover point.

That is the simplest way how to do that is to choose randomly


some crossover point and copy everything before this point
from the first parent and then copy everything after the
crossover point from the other parent.

1. Single-Point Crossover:- The traditional genetic algorithm


uses single-point crossover, where the two mating
chromosomes are cut once at corresponding points and the
sections after the cuts exchanged. Here, a cross site or
crossover point is selected randomly along the length of the
mated strings and bits next to the cross sites are exchanged.
2. Two-Point Crossover:- In two-point crossover, two
crossover points are chosen and the contents between
these points are exchanged between two mated parents.
The dotted lines indicate the crossover points.
3. Multipoint Crossover (N-Point Crossover Or Alternate
Swapping):- Multi point crossover is a generalization of the
one-point crossover wherein alternating segments are
swapped to get new off-springs.

There are two ways in this crossover. One is even number of


cross sites and the other odd number of cross sites. In the
case of even number of cross sires, the cross sites are
selected randomly around a circle and information is
exchanged. In the case of odd number of cross sites, a
different cross point is always assumed at the string
beginning.
4. Uniform Crossover:- Each gene in the offspring is created by
copying the corresponding gene from one or the other parent
chosen according to a random generated binary crossover
mask of the same length as the chromosomes. Where there is
a 1 in the crossover mask, the gene is copied from the first
parent, and where there is a 0 in the mask the gene is copied
from the second parent. A new crossover mask is randomly
generated for each pair of parents.
In Figure, new children are produced using uniform crossover
approach. It can be noticed that while producing child 1, when
there is a 1 in the mask, the gene is copied from parent 1 else
it is copied from parent 2. On producing child 2, when there is
a 1 in the mask, the gene is copied from parent 2, and when
there is a 0 in the mask, the gene is copied from the parent 1.
5. Three–Parent Crossover:- In this crossover technique,
three parents are randomly chosen. Each bit of the first
parent is compared with the bit of the second parent. If both
are the same, the bit is taken for the offspring, otherwise the
bit from the third parent is taken for the offspring.
6. Precedence Preservative Crossover (PPX):-

The operator passes on precedence relations of operations


given in two parental permutations to one offspring at the
same rate, while no new precedence relations are
introduced. PPX is illustrated below for a problem consisting
of six operations A-F. The operator works as follows:

1. A vector of length Sigma, sub i = 1 to mi, representing the


number of operations involved in the problem, is randomly
filled with elements of the set {1, 2}.
2. This vector defines the order in which the operations are
successively drawn from parent 1 and parent 2.

3. We can also consider the parent and offspring


permutations as lists, for which the operations "append” and
"delete'' are defined.

4. First we start by initializing an empty offspring.

5. The leftmost operation in one of the two parents is selected


in accordance with the order of parents given in the vector.

6. After an operation is selected, it is deleted in both parents.

7. Finally the selected operation is appended to the offspring.

8. Step 7 is repeated until both parents are empty and the


offspring contains all operations involved.
7. Ordered Crossover:-

Given two parent chromosomes, two random crossover


points are selected partitioning them into a left, middle and
right portions. The ordered two-point crossover behaves in
the following way:

child 1 inherits its left and right section from parent 1, and its
middle section is determined by the genes in the middle
section of parent 1 in the order in which the values appear in
parent 2. A similar process is applied to determine child 2.
8. Partially Matched Crossover(PMX):- PMX proceeds as
follows:

1. The two chromosomes are aligned.

2. Two crossing sites are selected uniformly at random along


the strings, defining a matching section.

3. The matching section is used to effect a cross through


position-by-position exchange operation.

4. Alleles are moved to their new positions in the offspring


Consider the two strings, where the dots mark the selected
cross points. The matching section defines the position-wise
exchanges that must take place in both parents to produce
the offspring. The exchanges are read from the matching
section of one chromosome to that of the other. In the
example, We numbers that exchange places are 5 and 2, 6
and 3, and 7 and 10. The resulting offspring are as shown in
Figure.
9. Shuffle Crossover:-
• Mutation:- Mutation plays the role of recovering the lost
genetic materials as well as for randomly distributing genetic
information. It is an insurance policy against the irreversible
loss of genetic material. Mutation has been traditionally
considered as a simple search operator.

If crossover is supposed to exploit the current solution


to find better ones, mutation is supposed to help for the
exploration of the whole search space. Mutation is viewed as
a background operator to maintain genetic diversity in the
population. For binary representation, a simple mutation can
consist in inverting the value of each gene with a small
probability. The probability is usually taken about 1/ L, where
L is the length of the chromosome.
1. Flipping:- Flipping of a bit involves changing 0 to 1 and 1 to
0 based on a mutation chromosome generated. A parent is
considered and a mutation chromosome is randomly
generated.

For a 1 in mutation chromosome, the corresponding bit in


parent chromosome is flipped (0 to 1 and 1 to 0) and child
chromosome is produced.
2. Interchanging:- Two random positions of the string are
chosen and the bits corresponding to those positions are
interchanged.

3. Reversing:- A random position is chosen and the bits next


to that position are reversed and child chromosome is
produced.
Generational Cycle
A Genetic Algorithm operates through a simple cycle of
stages:

i) Creation of a “population" of strings,

ii) Evaluation of each string,

iii) Selection of best strings and

iv) Genetic manipulation to create new population of strings.

Each cycle in Genetic Algorithms produces a new generation


of possible solution for a given problem. In the first phase, an
initial population, describing representatives of the potential
solution, is created to initiate the search process.

The elements of the population are encoded into bit-string,


called chromosomes.
The performance of the string, often called fitness, is then
evaluated with the help of some function, representing the
constraints of the problem. Depending on the fitness of the
chromosomes, they are selected for a subsequent genetic
manipulation process. The selection process is mainly
responsible for assuring survival of the best-fit individuals.
After selection of the population string is over. The genetic
manipulation process consisting of two steps as carried out.

In the first step, the crossover operation that recombines the


bits(genes) of each two selected strings(chromosomes) is
executed. Various types of crossover operation are found in
the literature. The single point and two points crossover
operation are illustrated.
The crossover points of any two chromosomes are selected
randomly. The second step in the genetic manipulation
process is termed mutation, where the bits at one or more
randomly selected position of the chromosomes are altered.
The mutation process helps to overcome trapping at local
maxima. The offstrings produced by the genetic manipulation
process are the next population to be evaluated.
Advantages of Genetic Algorithm

The advantages of GA are as follows:

1. Parallelism

2. Liability

3. Solution space is wider

4. The fitness landscape is complex

5. Easy to discover global optimum

6. The problem has multiobjective function


Limitations of Genetic Algorithm
The limitations of GA are as follows:

1. The problem of identifying fitness function.

2. Definition of representation for the problem.

3. Premature convergence occurs.

4. The problem of choosing various parameters such as the


size of the population, mutation rate, crossover rate, the
selection method and its strength.
Genetic Algorithms - Application Areas
Genetic Algorithms are primarily used in optimization
problems of various kinds, but they are frequently used in
other application areas as well. In this section, we list some of
the areas in which Genetic Algorithms are frequently used.
These are −
• Optimization − Genetic Algorithms are most commonly used
in optimization problems wherein we have to maximize or
minimize a given objective function value under a given set of
constraints. The approach to solve Optimization problems has
been highlighted throughout the tutorial.
• Economics − GAs are also used to characterize various
economic models like the cobweb model, game theory
equilibrium resolution, asset pricing, etc.
• Neural Networks − GAs are also used to train neural
networks, particularly recurrent neural networks.
• Parallelization − GAs also have very good parallel
capabilities, and prove to be very effective means in solving
certain problems, and also provide a good area for research.
• Image Processing − GAs are used for various digital image
processing (DIP) tasks as well like dense pixel matching.
• Vehicle routing problems − With multiple soft time windows,
multiple depots and a heterogeneous fleet.
• Scheduling applications − GAs are used to solve various
scheduling problems as well, particularly the time tabling
problem.
• Machine Learning − as already discussed, genetics based
machine learning (GBML) is a niche area in machine learning.
• Robot Trajectory Generation − GAs have been used to plan
the path which a robot arm takes by moving from one point to
another.
• Parametric Design of Aircraft − GAs have been used to
design aircrafts by varying the parameters and evolving better
solutions.
• DNA Analysis − GAs have been used to determine the
structure of DNA using spectrometric data about the sample.
• Multimodal Optimization − GAs are obviously very good
approaches for multimodal optimization in which we have to
find multiple optimum solutions.
• Traveling salesman problem and its applications − GAs
have been used to solve the TSP, which is a well-known
combinatorial problem using novel crossover and packing
strategies.

You might also like