Ga_method Hand Calc
Ga_method Hand Calc
methods
Genetic Algorithms
Nontraditional optimization
methods
Genetic Algorithms
Libyan academy for post graduate Studies
Prof. D. Mostafa Essuri
[email protected]
November - 2022
2
What is Genetic Algorithms
• Genetic Algorithm (GA) is a population-based probabilistic search and
optimization technique.
• works based on the mechanism of natural genetics and Darwin’s principle of
natural selection.
• The GA was introduced by Prof. John Holland of the University of Michigan.
• His book lays the foundation of the GAs.
• It is basically an iterative search technique.
• working based on the concept of probability.
What is Genetic Algorithms
Is an iterative search method that Uses rules of probability
• Several versions of GA are available in the literature, such as:
• Binary-coded GA ,
• real-coded GA ,
• micro-GA ,
• messy-GA , and others.
The working principle of a Simple GA
• A GA starts with a population of initial solutions generated at random.
• The fitness/goodness value (that is, objective function value in case of
a maximization problem) of each solution in the population is
calculated.
• It is important to mention that a GA is generally designed to solve a
maximization problem. Thus, a minimization problem has to be
converted into a corresponding maximization problem as
• discussed below:
The working principle of a Simple GA
How to converted into a corresponding maximization problem
Termination :
• After the reproduction, crossover and mutation are applied to the
whole population of solutions, one generation of a GA is completed.
Minimum 0 0 0 0 0
0 × 24 + 0 × 23 + 0 × 2 2 + 0 × 21 + 0 × 20 = 0.
Minimum 1 1 1 1 1
4 3
1 × 2 +1 ×2 +1 ×2 2 1 0
+ 1 × 2 + 1 × 2 = 31.
The working Example of Simple GA
• For example, if we need a precision level of ε in the values of a variable x1, we will have to assign l bits to
represent it, where l can be determined using the expression given below.
• Where 𝑙 is the length of the substring used to represent the variable, D is the decoded value
• Next➔ Use the values of 𝑥1 and 𝑥2 to calculate functional f(𝑥1 , 𝑥2 ) for each N chromosomes
• Step 2 Fitness evaluation:
linear mapping rule
• To determine the fitness value of each solution (that is, string), the real values of the variables: 𝑥1 and
𝑥2 are to be calculated first.
• If the minimum and maximum limits of a variable (say 𝑥1 ) and decoded value of the binary sub-string
assigned to represent 𝑥1 are known, its real value can be determined using the linear mapping rule
given below.
• Step 3 - Reproduction:
• All the GA-strings contained in the population may not be equally good in terms of their fitness values calculated in
Step 2.
• In this step, an operator named reproduction is used to select the good ones from the population of strings based on
their fitness information. Several reproduction schemes (also called selection schemes) have been developed by
various investigators. Some of these are
𝑓𝑖
𝑝=
σ𝑁
𝑖=1 𝑓𝑖
A Roulette-Wheel used to implement proportionate selection scheme
• Step 3 - Reproduction:
Initial string Individual Probability of
fitness being selected
1000….11111…. 𝒇𝟏 𝒇𝟏
σ𝑵
𝒊=𝟏 𝒇𝒊
000101010…. 𝒇𝟐 𝒇𝟐
σ𝑵
𝒊=𝟏 𝒇𝒊
1010…10010….. 𝒇𝟑 𝒇𝟑
σ𝑵
𝒊=𝟏 𝒇𝒊
…. ….. ….
0011…11111…. 𝒇𝑵 𝒇𝑵
σ𝑵
𝒊=𝟏 𝒇𝒊
In this scheme, a good string may be selected for a number of times.
• Step 3 - Reproduction:
• Arrange the strings in ascending order of their fitness values as f3, f1, f4, f2.
• Let us also assume that their probability values for being selected in the mating
pool are as follows: p1 = 0.15, p2 = 0.6, p3 = 0.05 and p4 = 0.2, according to this
selection scheme.
• Let us consider a random number generator, which generates a number (say r)
in the range of (0.0, 1.0). If r is found to lie in the ranges:
0.0 ≤ r < 0.05, 0.05 ≤ r < 0.2, 0.2 ≤ r < 0.4 and 0.4 ≤ r ≤ 1.0, then the
3ed, 1st, 4th and 2nd string will be selected
for the mating pool, respectively.
• Step 3 - Reproduction:
• II) Ranking method
A GA-search depends on the factors like population diversity and selection
Pressure.
These two factors are inversely related to each other in the sense that if the
selection pressure increases, the population diversity will decrease, and vice-
versa.
% % Rank Ri/sum % %
f1 80 0.8 4 0.4
f1 40 0.4
f2 10 0.1 3 0.3
f2 30 0.3
f3 7 0.07 2 0.2
f3 20 0.2
f4 3 0.03 1 0.1
f4 10 0.1
sum 100 1.0 10 ---
• Step 3 - Reproduction:
• III) Tournament Selection
In this scheme, we select the tournament size n (say 2 or 3 , or 5) at random,
which is a smaller number compared to the population size N (30, 100, or 200).
• We pick n strings from the population, at random and determine the best
one in terms of fitness value. (max. or min)
• The best string is copied into the mating pool and then all n strings are
returned to the population. Thus, in this scheme, only one string is selected
per tournament and N tournaments are to be played to make the size of
mating pool equal to N. Here, there is a chance for a good string to be
copied in the mating pool more than once.
• It is found to be computationally faster than both the fitness-based and
rank-based proportionate selection schemes.
• Step 3 - Reproduction:
• V) Elitism Selection
0101101011|1001101001
0011010010|1110100101
Two children produced due to the single-point crossover are given below.
0101101011|1110100101
0011010010|1001101001
• Step 4 - Crossover:
• Two-point Crossover –
• We select two different crossover sites lying between 1 and L − 1, at random. The parent
strings participating in this crossover are:
101011|10011|010010100
010010|11101|000110011
101011|11101|010010100
010010|10011|000110011
• We may not get change if the string is long , say 100… the last part is small
• Step 4 - Crossover:
• Multi-point Crossover –
• In case of multi-point crossover, a number of crossover points (either an odd number or
an even number greater than two) are selected along the length of the strings, at
random.
• The bits lying between alternate pairs of sites are then interchanged.
• The parent strings are shown below, in which five crossover sites are chosen at random.
101|1000|0111|0011|011|10
011|1011|0001|1000|101|00
101|1011|0111|1000|011|00
011|1000|0001|0011|101|10
• Step 4 - Crossover:
• Uniform Crossover
• 4. - Uniform crossover is a more general version of the multi-point crossover. Let us take
an example of the parent strings shown below to explain the principle of uniform
crossover.
10110000111001101110
01110110001100010100
• In this scheme, at each bit position of the parent strings, we toss a coin (with a probability
of 0.5 for appearing head) to determine whether there will be interchanging of the bits. If
the head appears, there will be a swapping of bits among the parent strings, otherwise
they will remain unaltered. Let us assume that the 2-nd, 4-th, 5-th, 8-th, 9-th, 12-th, 15-
th, 18-th and 20-th bit positions are selected for swapping. Thus, the obtained children
solutions will look as follows:
11110000011101001110
00110110101000110100
• Step 4 - Crossover:
• 4. - Uniform Crossover
• Uniform crossover is a more general version of the multi-point crossover. Let us take an
example of the parent strings shown below to explain the principle of uniform crossover.
10110000111001101110
01110110001100010100
• In another implementation of uniform crossover, a random mask (also known as template) consisting of 1s
and 0s of the same string-length as that of the parents is created. The mask is then searched bit-wise
starting from one side.
• At a particular bit-position, if the mask contains 1, then the corresponding bits of parents 1 and 2 will be
copied in the said position of children 1 and 2, respectively.
• On the other hand, if the mask contains 0 at a specific bit-position, then the corresponding bits of parents 1
and 2 will be selected for the said position of children 2 and 1, respectively. Let us consider a mask of 20
bits as given below.
10011101010110101110
The template
• Step 4 - Crossover:
Step 5 - Mutation : In a GA, the concept of biological mutation is modeled artificially to
bring a local change over the current solution.
In mutation, 1 is converted into 0 and vice-versa.
The role of mutation operator is explained with the help of the following fig. , which shows
the plot of an objective function having one local basin and another global basin. Let us
suppose that all the randomly generated initial solutions
In short, reproduction selects good strings from the population to form a mating pool and in
crossover, there is an exchange of properties between two parent strings and consequently, two
children strings are created. Mutation brings a local change at a particular bit position of the string.
Once the population of strings is modified using the operators, namely reproduction, crossover and
mutation, one generation of a GA is completed.
The GA runs until the termination criterion (that is, maximum number of generations or a desired
precision in the solution) is reached.
• Cross-over Versus Mutation
• It has been pointed out that mutation is more powerful than crossover in terms of its
disruption capability, whereas crossover outperforms mutation in terms of the
construction capability. Due to this reason, Genetic Algorithm (GA) and Genetic
Programming (GP) rely more on the crossover, whereas in Evolution Strategies (ES) and
Evolutionary Programming (EP), a more weightage is given on the mutation.
working principle of a binary-coded GA
Example one variable function
Maximize y = 𝑥 subjected to
subject to 1.0 ≤ 𝑥 ≤ 16.0
1 100101
2 011010
3 010110
4 111010
5 101100
6 001101
ID string Decoded Real value Fitness P selection P Expected
value value
F(x) = 𝒙
1 100101 37 9.81 3.13 0.18 1.07
2 011010 26 7.19 2.68 0.15 0.91
3 010110 22 6.24 2.5 0.14 0.85
4 111010 58 14.81 3.85 0.22 1.31
5 101100 44 11.48 3.39 0.19 1.16
6 001101 13 4.09 2.02 0.12 0.69
Sum 17.57 1
average 2.888
Max 3.85
P expected : How many times is individual string is copied into the next generation.
Real or actual selection may be different than expected because it is random
• Selection is based on Roulette-Wheel selection.
• Single-point crossover (pc = 1.0) i.e all strings will participate in the cross over
• A bit-wise mutation (pm = 0.03) very low
Pm * number of bits = 0.03 * 36 = 1.08
Only one bit will be changes
In real application of random search it
Could be different
Create a mating pool
• Selection is based on Roulette-Wheel selection.
• Single-point crossover (pc = 1.0) i.e all strings will participate in the cross over
• A bit-wise mutation (pm = 0.03) very low
Actual Previous Mating Pool Mating Pair Parents Cross over Children Mutation
selection pool single point
Sum = 20.86
Av = 3.48
Max = 3.91
Notes
• Every iteration the average and maximum will improve
How to fix the GA parameters
Constraints handling
In real problems we have constraints
Objective function
2
where C indicates the user-defined penalty coefficient and 𝜑𝑖𝑘 (𝑋) represents the penalty
term for k-th constraint, corresponding to i-th objective function.