GA Examples 1-7 Updated (2018)
GA Examples 1-7 Updated (2018)
Examples
Crossover operator
0 1 1 1 0 1 0 1 1 0
1 1 0 1 1 0 0 1 0 1
0 1 1 1 0 1 0 1 0 1
1 1 0 1 1 0 0 1 1 0
Types of crossover(cont…)
0 1 1 1 0 1 0 1 1 0
1 1 0 1 1 0 0 1 0 1
0 1 1 1 1 0 0 1 1 0
1 1 0 1 0 1 0 1 0 1
Types of crossover(cont…)
Uniform crossover
Assign 'heads' to one parent, 'tails' to the other
Flip a coin for each gene of the first child
Make an inverse copy of the gene for the second child
Inheritance is independent of position
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Parents
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
00 1 0
0 0 1 0 1 1 0 00 0
0 1 0
0 1 1 0 0 1
Children
1 00 1 1 00 1 0 0 1 1 1 00 1 00 00 1 1 00
Reproduction(cont…)
Types of crossover
Arithmetic crossover
a b c d e f
A B C D E F
GA Approach
Representation : binary code eg: 01101 13
Population size:4 x2+1
1200
1-point crossover 1000
800
Roulette wheel Selection 600
Random Optimization
400
200
0
0 5 10 15 20 25 30 35
Cond…
Range – {0 to 31} -> {00000 to 11111} [ 11111 : 1*24 + 1*23 + 1*22 + 1*21 + 1*20 = 31 ]
x2+1
1. 01101 13 1200
1000
2. 11000 24 800
3. 01000 8 600
400
4. 10010 18 200
0
0 5 10 15 20 25 30 35
(X2+1) Example Selection
Sum
f i 1137 1.00 1 2 3 4
01101 1 01101
11000 2 11000
01000 0 11000
10010 1 10010
• Randomly select cross over point between 1-4 for string 1 & 2: 4
• Randomly select cross over point between 1-4 for string 3 & 4: 2
X Value Fitness
F(x)=x2+1
12 145
25 626 677
26 677
16 257
Maximize sin( x ),
Subject to, 0 x .
In this problem 5 bit string is needed to represent the variable with one
decimal place of accuracy.
Assume the population size = 4
String (00000) represent the x= 0 solution and String (11111) represents the
x= π solution.
To get x from decoded value we use
01001 0 2 4 1 23 0 2 2 0 21 1 2 0 9
String value
l 0
x xmin (( xmax xmin ) / (2 1)) DV 0 9 5 0.912
2 1
Function value DV Decoded value
f ( x) sin(0.912) 0.791 AC Actual count
fi 0.791
1.39
f avg 0.569
The proportionate reproduction scheme assigns a number of
copies according to a string’s fitness .
The expected number of copies for each string is calculated.
For example string (10100), the expected number of copies is
equal to 2 and for string(00001), the expected number of
copies is zero because the fitness of the string is very small as
compared to the average fitness of the population and it is
eliminated.
The second string is good one and made two copies in the
mating pool.
Example-3
Simple problem max (x)1/2
Subject to
1<x<16
G A approach:
-Representation: binary Code, e.g. 100101 37
-Population size :6
-1-point Crossover, bitwise mutation
-Roulette wheel selection
-Random Initialization
We show one generation done by hand:
Example (x)1/2 selection
Avg=0.166
sum=17.57
Average f=2.92
3.13/ 17.57 = 0.18 maximum f=3.85
From Roulette Wheel select the strings into mating pool for cross over. These are least values and they
got rejected by Roulette Wheel
For string 100101
100101 = 1*25+0*24+0*23+1*22+0*21+1*20 = 37
The value of x 1 37
16 1
9.81
26 1
Fitness value = (9.81) (1/2) = 3.13
Total fitness = 3.13+2.68+2.50+3.85+3.39+2.02 = 17.57
Avg fitness = 17.57/6 = 2.92
Maximum fitness = 3.85
Probability = 3.13/ 17.57 = 0.18
Avg probability = (.18+.15+.14+.22+.19+.12)/6 = .166
Example-Contd..
From the calculation, it is clear that string 3 and 6 are not considered for next step
because they have lesser probability as compared to avg fitness probability.
There are two new copies formed by string 4 and 5 for cross over.
Roulette wheel selection and crossover and mutation
42 11.00 3.32
53 13.62 3.69
28 7.67 2.77
40 10.52 3.24
60 15.28 3.91
42 11.00 3.32
Sum f =20.25
Average f=3.37
Maximum f=3.91
From the table it is clear that the average fitness is greater than the previous population.
Example-4
A supply chain of a computer manufacturing industry.
Demand of each customer zone is satisfied exactly by one production plant
Each production plant supplies to exactly one customer zone
i j k l Ch2 d b c a
Pr2
Initial Population
String
1) 1 2 3 4
2) 2 4 1 3
3) 3 1 4 2
4) 4 3 2 1
For string 4
D = 8 +15 +19+22 = 64
fitness (f) = (100-64) = 100 -64 = 36
String Objective function Fitness Expected
value (D) value(f) count
1 1 2 3 4 59 41 1.21≈ 1
2 2 4 1 3 86 14 0.41≈ 0
3 3 1 4 2 56 44 1.30≈2
4 4 3 2 1 64 36 1.07≈ 1
ftotal= 135
favg= 33.75
Cont……
Mating Pool
String
1) 1 2 3 4
2) 3 1 4 2
3) 3 1 4 2
4) 4 3 2 1
Crossover:- Between string 3 & 4
3) 3 1 4 2 Ch1 1 3 2 4
4) 4 3 2 1 Ch2 2 1 4 3
After Crossover
String
1) 1 2 3 4
2) 3 1 4 2
3) 1 3 2 4
4) 2 1 4 3
Cont……
Iteration 2-
Objective function & fitness value calculation
For string 1
D = 20 + 9 +23 +7 = 59
fitness (f) = (100-D)= 100-59 = 41
For string 2
D = 13 +25+12+6 = 56
fitness (f) = (100-D)= 100 – 56 = 44
For string 3
D = 20 +15 +19+7 = 61
fitness (f) = (100-D) = 100 -61 = 39
For string 4
D = 14 +25 +12+30 = 81
fitness (f) = (100-D) = 100 -81 = 19
Cont……
2) 3 1 4 2 Ch2 4 2 3 1
Cont……
After Crossover
String
1) 2 1 4 3
2) 4 2 3 1
3) 3 1 4 2
4) 1 3 2 4
Objective function and fitness value
For string 1
D = 14 + 25 +12 +30 = 81
fitness (f) = (100-D)= 100-81 = 19
For string 2
D = 8 +9+23+22 = 62
fitness (f) = (100-D)= 100 – 62 = 38
For string 3
D = 13 +25 +12+6 = 56
fitness (f) = (100-D) = 100 -56 = 44
For string 4
D = 20 +15 +19+7 = 61
fitness (f) = (100-D) = 100 – 61= 39
Cont……
2
Maximize cos ( x ),
0 x .
Subject to, 2
Min value for x is 0Max
and value
this will
for x is /2 and this will
correspond to 00000 correspond
in binary string
to 11111 in binary string
In this problem we use 5 bit string to represent the variable x.
Assume initial population size = 4 and of each is 5 bit long
To get x from decoded value we use
x xmin DV ( xmax xmin ) / (2l 1)
EXAMPLE-CONTD..
First Iteration: 0*24+ 1*23+ 0*22+ 0*21+ 20= 9
x xmin DV ( xmax xmin ) / (2l 1)
Cos2(0.46) f=i/f0.806
avg= 0.806/0.506=1.59
5
Initial Population x 0 9 ( 0) / (2 1)
2
x 0.46
String DV x f(x) fi/f avg AC Mating Pool
01001 9 0.46 0.806 1.59 1 01001
10100 20 1.01 0.280 0.55 1 10100
00101 5 Max
0.25= 0.937 1.85 2 00101
11110 30 1.52 0.003 0.01 0 11110
00101
favg= 0.506
DV Decoded value Chromosome corresponding to it will be
AC Actual count of strings in the population replaced by better chromosome from the
gene pool
EXAMPLE-CONTD..
Crossover after gene 2
Crossover Operation:
Crossover after gene 3
Second Iteration:
New Gene Pool
Offspring 00001 is giving us a near optimal value for Max: cos2 (x) ,
which is 0.997
Offspring after crossover & Mutation
NEXT EXAMPLE:
EXAMPLE 6
Solving the following problem with GA
Maximize x2
3x
10
Subject to, 0 x 31.
Min value for x is 0 and
Maxthis willfor x is 31 and this will
value
correspond to 00000 incorrespond
binary string
to 11111 in binary string
In this problem we use 5 bit string to represent the variable x.
Take population size = 4 and of each is 5 bit long
To get x from decoded value we use
x xmin DV ( xmax xmin ) / (2l 1)
EXAMPLE-CONTD..
First Iteration:
x xmin DV ( xmax xmin ) / (2l 1)
(-x2/10)+3x= 18.9
Initial Population x 0 9 (31 0) / (25 1)
x9
String DV x f(x) fi/f avg AC Mating Pool
01001 9 9.00 18.900 1.47 1 01001
10100 20 Max
20.00= 20.000 1.56 2 10100
00101 5 5.00 12.500 0.97 1 00101
11110 30 30.00 0.000 0.00 0 11110
10100
favg= 12.85
DV Decoded value Chromosome corresponding to it will be
AC Actual count of strings in the population replaced by better chromosome from the
gene pool
EXAMPLE-CONTD..
Crossover after gene 2
Crossover Operation: one point crossover, selection at random
Crossover after gene 3
Second Iteration:
New Gene Pool
For m1
(12.1-(-3)) x 10,000 = 1,51,000
So m1 = 18 and
Similarly m2 = 15
Example(cont…)
0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 0
Example
Example(cont…)
Example(cont…)
Example(cont…)
v4 v4 v8
0.301451 0.322062 0.766505
See corresponding cumulative
v9 0.881893 0.350871 v4 0.583392 v7 probability.
0.177618 0.343242 v4 0.032685
v2 v1
0.197577
v2
For 0.301451 we select chromosome 4 because it’s cumulative probability lies in this
range.
Example(cont…)
Example(cont…)
Example(cont…)
Example(cont…)
105 4 6 0.009857
164 5 32 0.003113
199 7 1 0.000946
329 10 32 0.001282
Example(cont…)
Example(cont…)
Corresponding decimal values of variables are
f(6.159951,4.109598) = 29.406122
f(6.159951,4.109598) = 29.406122 Example- for chromosome 1
here
f(-0.330256,4.694977)=19.763190
f(11.907206,4.694977)=5.702781
f(8.024130,4.170248) = 19.91025
f(9.342067,5.121702)= 17.958717
f(6.159951,4.109598)= 29.406122
f(6.159951,4.109598)= 29.406122
f(-2.687969,5.361653)=19.805119
f(0.474101,4.170248)= 17.370896
Example(cont…)
Thank You