Skip to main content

GENETIC WAY TO SOLVE A PROBLEM

 
We grow as an adult; complete our studies; find a good carrier; then select a suitable spouse; get married.  Offsprings get portions of our genes.  They grow as adults….
The story continues generation after generation.  The point here is; the fittest get married and produce off-springs.
This principle can be used to solve a maths problem.
 
f(x) = 3.x-x^2/6.62
The above function yields different results for different values of X.  I want to find a particular value of X for which the function yields maximum.  That is, I want to maximize the function.  Let us assume that X can only take values from 0 to 31.  In a binary system, the range is 00000 to 11111(for the explanation of binary number see note 1)
Let us randomly select six x values in the range 0 to 31 and evaluate the function.


X- decimal
X- binary
f(x) = 3.x-x^2/6.62
selected?
2
00010
5.395
yes
8
01000
14.33
yes
12
01100
14.24
yes
18
10010
5.057
no
22
10110
-7.111
no
28
11100
-34.42
no
Here x values 2, 8, and 12 which yields maximum results are selected.  The corresponding 3 binary values are taken as genes of X.  We are going to mate them and produce six off-springs.  The function will again be evaluated with the off-springs for maximum yield.  
Here mating means, portions of the binary digits are swapped to produce next-generation X as given below.    


I  generation x      II generation x
8    01000             01010   10         
2    00010             00000   0
       Binary or genes, here, colored portions are swapped


I gen. x
Binary or genes
offsprings
II gen. x
f(x)
8
01000
01100
12
14.24
12
01100
01000
8
14.33
8
01000
01010
10
14.82, best
2
00010
00000
0
0
12
01100
01010
10
14.82, best
2
00010
00100
4
9.583


 From the table, we understand X = 10 gives the maximum value of the function 14.82.  Few more runs of this procedure will confirm the result X = 10.  
    
    This method is known as a genetic algorithm in computer parlance.  For complicated problems, the computer will run the algorithm for hundreds of generations and the best result will be taken.  


Note 1: In a binary system, all numbers are represented using only 0 s and 1 s as follows.  (If required, leading zeros can always be added).




2. The following graph of the function proves the result.