Optimization Algorithms
Outline of the Basic Genetic Algorithm
1. [Start] Generate random population of n chromosomes (i.e. 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 parents chromosomes from a population according to their
fitness (better the fitness, bigger the chance to be selected)
(b) [Crossover] cross over the parents to form new offspring (children).
(c) [Mutation] mutate new offspring at each locus (position in chromosome).
(d) [Accepting] Place new offspring in the new population
4. [Replace] Use new generated population for a further run of the algorithm
5. [Test] If the end condition is satisfied, stop, and return the best solution in
current population
6. [Loop] Go to step 2
Note : The genetic algorithms performance is largely influenced by two operators
called crossover and mutation. These two operators are the most important parts
of GA.
1
Optimization Algorithms
Flow chart for Genetic Programming
Start
Create initial population
Generation = 0
Evaluate fitness value for each
chromosome
Gen=
Gen+1 Perform selection, crossover and
mutation
No
Gen >max generation
Yes
Stop
2
Optimization Algorithms
Example: Maximize the function f(x) = x2 over the range of integers from 0 to
31 with initial population 01101, 11000, 01000, 10011 with random number
0.08 ,0.24 ,0.53 ,0.87 ,select the crossover point to be after the third digit ?
Solution:
A Binary string of length 5 can represents 32 numbers (0 to 31).
Evaluate the fitness of each member of the population:
The calculated fitness values for each individual are -
(a) Decode the individual into an integer (called phenotypes),
01101 → 13; 11000 → 24; 01000 → 8; 10011 → 19
(b) Evaluate the fitness according to f(x) = x2 ,
13 → 169; 24 → 576; 8 → 64; 19 → 361.
selection:
String No Initial X Fitness Prob. Cumulative Intervals
Population value f(x) = x2 of R N
1 01101 13 169 0.14 0.14 0 to .14
2 11000 24 576 0.49 0.63 .15 to .63
3 01000 8 64 0.06 0.69 .64 to .69
4 10011 19 361 0.31 1 .7 to 1
(sum) 1170 1.00
Average 293 0.25
Max 576 0.49
By generating 4 uniform (0, 1) random values and seeing which bin they fall into
we pick the four strings that will form the basis for the next generation.
Rand No Region Chosen string
0.08 0 to 0.14 01101
0.24 0.15 to 0.63 11000
0.53 0.15 to 0.63 11000
0.87 0. 64 to 1 10011
3
Optimization Algorithms
Crossover:
Within each pair swap parts of the members solutions to create offspring which
are a mixture of the parents:
For the first pair of strings: 0 1 1 0 1, 1 1 0 0 0
Crossing these two strings at that point yields:
0 1 1 0 1 →0 1 1| 0 1 → 0 1 1 0 0
1 1 0 0 0 →1 1 0| 0 0 → 1 1 0 0 1
For the second pair of strings: 1 1 0 0 0 , 1 0 0 1 1
Crossing these two strings at that point yields:
1 1 0 0 0 → 1 1 0| 0 0 →1 1 0 1 1
1 0 0 1 1 → 1 0 0| 1 1 →1 0 0 0 0
New generation:
This would be the first step in generating a new generation of solutions. However
it is also useful in showing the way that a single iteration of the genetic algorithm
has improved this sample.
String No Initial X value Fitness Prob.
Population f(x) = x2
1 01100 12 144 0.082
2 11001 25 645 0.356
3 11011 27 729 0.415
4 10000 16 256 0.145
(sum) 1754 1.00
Average 439 0.25
Max 729 0.415
Observe that :
1. The total fitness has gone from 1170 to 1754 in a single generation.
2. The algorithm has already come up with the string 11011 (i.e. x = 27) as
a possible solution.
4
Optimization Algorithms
Example 2: Maximize the function f(x) = - x2 +2x over the range of real number
from 0 to 2 with initial population 11010 , 00111 , 10110, 00101 , with random
number 0.4 ,0.15 ,0.7 ,0.9 ,select the crossover between the first and fifth digits?
Solution:
Decode the individual into an real number
(2−0) 52
11010 → = 0 + x(26) = = 1.677
(25 −1) 31
(2−0) 14
00111 → = 0 + x(7) = = 0.451
(25 −1) 31
(2−0) 44
10110 → = 0 + x(22) = = 1.419
(25 −1) 31
(2−0) 10
00101 → = 0 + x(5) = = 0.322
(25 −1) 31
(b) Evaluate the fitness according to f(x) = f(x) = - x2 +2x
String No Initial X Fitness Prob. Cumulative Intervals of
Population value f(x) = x2 RN
1 11010 1.677 0.541 0.21 0.21 0 to 0.21
2 00111 0.451 0.699 0.27 0.48 0.22 to 0.48
3 10110 1.419 0.824 0.32 0.8 0.49 to 0.8
4 00101 0.322 0.541 0.2 1 0.81 to 1
(sum) 2.6056
Average 0.6514
Max 0.824
By generating 4 uniform (0, 1) random values and seeing which bin they fall into
we pick the four strings that will form the basis for the next generation.
Rand No Region Chosen string
0.4 0.22 to 0.48 00111
0.15 0 to 0.21 11010
0.7 0.49 to 0.8 10110
0.9 0.81 to 1 00101
Crossover:
5
Optimization Algorithms
Within each pair swap parts of the members solutions to create offspring which
are a mixture of the parents:
For the first pair of strings: 00111 , 11010
Crossing these two strings at that point yields:
00111→0|011|1→ 01011
11010→1|101|0→ 10110
For the second pair of strings: 10110, 00101
Crossing these two strings at that point yields:
10110→ 1|011|0→10100
00101→ 0|010|1→00111
New generation:
This would be the first step in generating a new generation of solutions. However
it is also useful in showing the way that a single iteration of the genetic algorithm
has improved this sample.
String No Initial X value Fitness Prob.
Population f(x) = x2
1 01011 0.709 0.915 0.082
2 10110 1.419 0.824 0.356
3 10100 1.29 0.915 0.415
4 00111 0.451 0.699 0.145
(sum) 3.3548
Average 0.8387
Max 0.915