Genetic Algorithm
Example
Genetic Algorithm- Example
Maximize the function f(X) = , Where X value ranges from 0-31
Steps: Choose population size
1. Select Encoding Type
2. Choose population size
3. Randomly choose population
Let n=4
4. Select parental chromosomes
5. Crossover and Mutation Randomly choose population
6. Evaluation of offspring
7. If stopping criteria not reached, Go to Step 4
Select Encoding Type Let it be 13, 24, 8 and 19
0 Binary Coding 31 Select parental chromosomes
0 0 0 0 0 1 1 1 1 1
Genetic Algorithm- Example
Select parental chromosomes
String No. Initial X f(X) = Probability Expected Actual
Population Count Count Count
1 01101 13 169 0.14
=169/1170 =0.58
=169/293
2 11000 24 576 0.49
=576/1170 =1.97
=576/293
3 01000 8 64 0.06
= 64/1170 = 0.22
= 64/293
=1.23
=361/293
4 10011 19 361 =361/1170
0.31
Total 1170 1 Probability Count
Avg 293
1st Qtr 2nd Qtr 3rd Qtr 4th Qtr
Genetic Algorithm- Example
Select parental chromosomes
String No. Initial X f(X) = Probability Expected Actual
Population Count Count Count
1 01101 13 169 0.14
=169/1170 =0.58 1
2 11000 24 576 0.49
=576/1170 =1.97 2
3 01000 8 64 = 64/1170
0.06 = 0.22 0
=361/1170 =1.23 Need to eliminate,
4 10011 19 361 0.31 1 since it is not selected
for rotation due to its
Total 1170 1 4 least value
Avg 293 Total number of
wheel turns
Genetic Algorithm- Example
Step 5: Cross Over and Mutation
String No. Initial X f(X) = Probability Expected Actual
Population Count Count Count
1 01101 1
2 11000 2
3 01000 0
4 10011 1
String 2 11000 Parental String 2 11000 Parental
Combination 1 Combination 2
String 1 01101 String 4 10011
Genetic Algorithm- Example
Step 5: Cross Over and Mutation
Next Generation
Child Chromosomes
String 2 1100 0
11001
String 1 0110 1 01100
String 2 11 000
11011
String 4 10 011 10000
Genetic Algorithm- Example
String No. Offspring X f(X) =
1 01100 12 144
2 11011 25 625
3 01000 8 64 Solution not improved
4 10000 16 256 Step 6: Mutation
String No. Offspring X f(X) =
Total 1089
1 01101 12 144
2 11001 25 625
3 11000 24 576
4 10000 16 256
Total 1601