You are on page 1of 27

GA FOR OPTIMIZATION

Genetics based mechanism to problem solving is first conceived by Professor


John Holland of University of Michigan, Ann Arbor in 1965. The popularity for genetic
algorithms in various search and optimization problems is its global perspective, wide
spread applicability, and inherent parallelism. Simulating the natural evolutionary process
of human beings results in stochastic optimization techniques called evolutionary
algorithms, which can often outperform conventional optimization techniques when
applied to difficult real-world problems.

What is Genetic Algorithms?


The genetic algorithm (GA) is defined by randomized search and optimization
technique guided by the principle of natural genetic systems. Recently, there has been a
great deal of interest in promising GA and its application to various engineering fields.
GA is also being applied to a wide range of optimization and learning problems in many
domains. GA lends themselves well to power system optimization problems since they
are known to exhibit robustness, require to auxiliary information, and can offer
significant advantages in solution methodology and optimization performance.
GAs differ from other optimization and search procedures in many ways:
1. Many real life problems cannot be solved in polynomial amount of time
using deterministic algorithm
2. Sometimes near optimal solutions that can be generated quickly are more
desirable than optimal solutions which require huge amount of time
3. Problems can be modeled as an optimization one.
4. GA work with a coding of the parameter set, not the parameters
themselves. Therefore GA can easily handle the integer or discrete
variables.
5. GA search from a population of points, not a single point. Therefore GA
can provide a globally optimal solution.
6. GA use only objective function information, not derivatives or other
auxiliary knowledge. Therefore GA can deal with the non-smooth, non-
continuous and non-differentiable functions which are actually existed in a
practical optimization problem.
7. GA use probabilistic transition rules, not deterministic rules

Step by Step Procedures of Genetic Algorithms


A genetic algorithm (as any evolution program)for a particular problem must have
the following five components and Figure 1.1 shows the flow chart of GA.

Start

Production of the initial


chromosome calculation of the
fitness

Calculation of the fitness and affinity


of individuals

Production of the
individuals

Selection

Crossover and
Mutation

Change old population with new


population

No
Gen ≤ Max.Gen

Yes
End

Figure 1.1
1. A genetic representation for potential solutions to the problem.
2. A way to create an initial population of potential solutions,
3. An evaluation function that plays the role of the environment, rating solutions in
terms of their “fitness”.
4. Genetic operators that alter the composition of children.
5. Values for various parameters that the genetic algorithm uses (population size,
probabilities of applying genetic operators, etc.).

Let us understand the working of genetic algorithms with the following examples;
Case 1

In this section we discuss the basic features of a genetic algorithm for


optimization of a simple function of one variable. The function is defined as below and
shown in Figure 1.2

f(x) =x. sin (10π.x) + 1.0 (1)

Figure 1.2 Plot of the function f(x) =x. sin (10π.x) + 1.0
Representation
In this case a binary vector (chromosome) has been considered to represent real
values of the variable x. The length of the vector depends on the required precision,
which, in this example, is six places after the decimal point.
The domain of the variable x has length 3; the precision requirement implies that
the range [-1...2] should be divided into at least 3.1000000 equal size ranges. This means
that 22 bits are required as a binary vector (chromosome):
2097152 = 221 <3000000 ≤ 222 =4194304.
The mapping from a binary string (b21 b20….. b0) into a real number x from the
range [-1 ...2] is straightforward and is completed in two steps:
• convert the binary string (b21 b20….. b0) from the base 2 to base 10 and equal to x’,
• find a corresponding real number:
x = -1.0 + x’. (3/222-1), (5)
where -1.0 is the left boundary of the domain and 3 is the length of the domain.
For example, a chromosome
(1000101110110101000111)
represent the number 0.637197, since
x’= (1000101110110101000111)2 = 2288967
and
x = -1.0 + 2288967. (3/4194303) = 0.637197.
Of course, the chromosomes (0000000000000000000000) and
(1111111111111111111111) represent boundaries of the domain, -1.0 and 2.0,
respectively.

Initial population
The initialization process is very simple: we create a population of
chromosomes, where each chromosome is binary vector of 22 bits. All 22 bits for each
chromosome are initialized randomly.

Evaluation function
Evaluation function eval for binary vectors v is equivalent to the function f:
eval (v) = f(x) (6)
where the chromosome ‘v’ represents the real value x.

As noted earlier, the evaluation function plays the role of the environment, rating
potential solutions in terms of their fitness. For example, three chromosomes:
v1= (1000101110110101000111),
v2= (0000001110000000010000),
v3= (1110000000111111000101),
Correspond to values x1 = 0.637197, x2 = -0.958973, and x3 = 1.627888,
respectively. Consequently, the evaluation function would rate them as follows:
eval (v1) = f(x1) = 1.586345,
eval (v2) = f(x2) = 0.078878,
eval (v3) = f(x3) = 2.250650.
Clearly, the chromosome v3 is the best of the three chromosomes, since its
evaluation returns the highest value.

Genetic operators

During the alteration phase of the genetic algorithm we would use two classical
genetic operators: mutation and crossover.
As mentioned earlier, mutation alters one or more genes (positions in a
chromosome) with a probability equal to the mutation rate. Assume that the fifth gene
from the v3 chromosome was selected for a mutation. Since the fifth gene in this
chromosome is 0, it would be flipped into 1. So the chromosome v3 after this mutation
would be
v3’ = (1110100000111111000101).
This chromosome represents the value x’3 = 1.721638 and f (x’3) = -0.082257.
This means that this particular mutation resulted in a significant decrease of the value of
the chromosome v3. then
v3” = (1110000001111111000101).
The corresponding value x”3 = 1.630818 and f (x”3) = 2.343555, an improvement
over the original value of f(x3) =2.250650.
Let us illustrate the crossover operator on chromosome v2 and v3. Assume that the
crossover point was (randomly) selected after the 5th gene:
v2= (0000001110000000010000),
v3= (1110000000111111000101).
The two resulting offspring are
v2’= (0000000000111111000101),
v3’= (1110001110000000010000).
These offspring evaluate to
f(v2’) = f(-0.998113) = 0.940865,
f(v3’) = f(1.666028) = 2.459245.
Note that the second offspring has a better evaluation than both of its parents.

Parameters
For this particular problem we have used the following parameters: population
size pop_size = 50, probability of crossover pc = 0.25, probability of mutation pm = 0.01.
The following section presents some experimental results for such a genetic system.
Results: Table 1.1

Generation
Evaluation function
number

1 1.441942
6 2.250003
8 2.250283
9 2.250284
10 2.250363
12 2.328077
39 2.344251
40 2.345087
51 2.738930
99 2.849246
137 2.850217
145 2.850227
Experimental results
We provide the generation number for which we noted an improvement in the
evaluation function, together with the value of the function. The best chromosome after
150 generations was
vmax = (1111001101000100000101),
which corresponds to value x max = 1.850773.
As expected, x max = 1.85 +ε, and f(x max) is slightly larger than 2.85.

Case 2
Assume that the population size pop-size = 20, and the probabilities of genetic
operators are pc = 0.25 and pm = 0.01.

Let us assume also that we maximize the following function (shown in figure
9.5):
f(x1,x2) = 21.5 + x1 . sin (4Πx1) +x2 . sin(20Πx2). (9.39)
where -3.0 ≤ x1 ≤ 12.1 and 4.1 ≤ x2 ≤ 5.8.
Figure 9.41 Plot of the function f(x1,x2) = 21.5 + x1 . sin (4Πx1) +x2 . sin(20Πx2).

Assume that after the initialization process we get the following population:
v1 = (100110100000001111111010011011111)
v2 = (111000100100110111001010100011010)
v3 = (000010000011001000001010111011101)
v4 = (100011000101101001111000001110010)
v5 = (000111011001010011010111111000101)
v6 = (000101000010010101001010111111011)
v7 = (001000100000110101111011011111011)
v8 = (100001100001110100010110101100111)
v9 = (010000000101100010110000001111100)
v10 = (000001111000110000011010000111011)
v11 = (011001111110110101100001101111000)
v12 = (110100010111101101000101010000000)
v13 = (111011111010001000110000001000110)
v14 = (010010011000001010100111100101001)
v15 = (111011101101110000100011111011110)
v16 = (110011110000011111100001101001011)
v17 = (011010111111001111010001101111101)
v18 = (011101000000001110100111110101101)
v19 = (000101010011111111110000110001100)
v20 = (101110010110011110011000101111110)
During the evaluation phase we denote each chromosome and calculate the fitness
function values from (x1,x2) values just decoded. We get:

eval(v1) = f ( 6.084492,5.652242) = 26.019600


eval(v2) = f ( 10.348434,4.380264) = 7.580015
eval(v3) = f ( -2.5166003,4.390381) = 19.526329
eval(v4) = f ( 5.278638,5.593460) = 17.406725
eval(v5) = f ( -1.255173,4.734458) = 25.341160
eval(v6) = f ( -1.811725,4.391937) = 18.100417
eval(v7) = f ( -0.991471,5.680258) = 16.020812
eval(v8) = f ( 4.910618,4.703018) = 17.959701
eval(v9) = f ( 0.795406,5.381472) = 16.127799
eval(v10) = f ( -2.554851,4.793707) = 21.278435
eval(v11) = f ( 3.130078,4.996079) = 23.410669
eval(v12) = f ( 9.356179,4.239457) = 15.011619
eval(v13) = f ( 11.134646,5.378671) = 27.316702
eval(v14) = f ( 1.335944,5.151378) = 19.876294
eval(v15) = f ( 11.089025,5.054515) = 30.060205
eval(v16) = f ( 9.211598,4.993762) = 23.867227
eval(v17) = f ( 3.367514,4.571343) = 13.696165
eval(v18) = f ( 3.843020,5.158226) = 15.414128
eval(v19) = f ( -1.746635,5.395584) = 20.095903
eval(v20) = f ( 7.935998,4.757338) = 13.666916
It is clear, that the chromosome v15 is the strongest one, and the chromosome v2 is
the weakest.

Now the system constructs a roulette wheel for the selection process. The total
fitness of the population is

F = 387.776822.

The probability of selection pi for each chromosome vi (i=1,….., 20) is:

P 1 = eval (v1) / F = 0.067099


P2 = eval (v2) / F = 0.019540
P3 = eval (v3) / F = 0.050355
P4 = eval (v4) / F = 0.044889
P5 = eval (v5) / F = 0.065350
P6 = eval (v6) / F = 0.046677
P7 = eval (v7) / F = 0.041315
P8 = eval (v8) / F = 0.046315
P9 = eval (v9) / F = 0.041590
P10 = eval (v10) / F = 0.054873
P11 = eval (v11) / F = 0.060372
P12 = eval (v12) / F = 0.038712
P13 = eval (v13) / F = 0.070444
P14 = eval (v14) / F = 0.051257
P15 = eval (v15) / F = 0.077519
P16 = eval (v16) / F = 0.061549
P17 = eval (v17) / F = 0.035320
P18 = eval (v18) / F = 0.039750
P19 = eval (v19) / F = 0.051823
P20 = eval (v20) / F = 0.035244
The cumulative probabilities qi for each chromosome vi (i=1,…..,20) are:

q1=0.067099
q2=0.086647
q3=0.137001
q4=0.181890
q5=0.247240
q6=0.293917
q7=0.335232
q8=0.381546
q9=0.423137
q10=0.478009
q11=0.538381
q12=0.577093
q13=0.647537
q14=0.698794
q15=0.776314
q16=0.837863
q17=0.837182
q18=0.912932
q19=0.964756
q20=1.000000

Now we are ready to spin the roulette wheel 20 times; each time we select a single
chromosome for a new population. Let us assume that a (random) sequence of 20
numbers from the range [0…1] is :

0.513870 0.175741 0.308652 0.534534 0.947628


0.171736 0.702231 0.226431 0.494773 0.424720
0.703899 0.389647 0.277226 0.368071 0.983437
0.005398 0.765682 0.646473 0.767139 0.780237
The first number r = 0.513870 is greater than q10 and smaller than q11, meaning
the chromosome v11 is selected for the new population; the second number r = 0.175741
is greater than q3 and smaller than q4, meaning the chromosome v4 is selected for the new
population, etc.

Finally, the new population consists of the following chromosomes:

v11 = (011001111110110101100001101111000) (v11)


v12 = (100011000101101001111000001110010) (v4)
v13 = (001000100000110101111011011111011) (v7)
v14 = (011001111110110101100001101111000) (v11)
v15 = (000101010011111111110000110001100) (v19)
v16 = (100011000101101001111000001110010) (v4)
v17 = (111011101101110000100011111011110)( v15)
v18 = (000111011001010011010111111000101)(v5)
v19 = (011001111110110101100001101111000) (v11)
v110 = (000010000011001000001010111011101)(v10)
v111 = (111011101101110000100011111011110)( v15)
v112 = (010000000101100010110000001111100) (v9)
v113 = (000101000010010101001010111111011) (v6)
v114 = (100001100001110100010110101100111) (v8)
v115 = (101110010110011110011000101111110) (v20)
v116 = (100110100000001111111010011011111) (v1)
v117 = (000001111000110000011010000111011) (v10)
v118 = (111011111010001000110000001000110) (v13)
v119 = (111011101101110000100011111011110)( v15)
v120 = (110011110000011111100001101001011) (v16)

Now we are ready to apply the recombination operator, crossover, to the


individuals in the new population (vector vi1 ). The probability of crossover pc = 0.25, so
we expect that (on average) 25% of chromosomes (i.e., 5 out of 20) undergo crossover.
We proceed in the following way: for each chromosome in the (new) population we
generate a random number r from the range [0…1]; if r < 0.25, we select a given
chromosome for crossover.

Let us assume that the sequence of random number is:

0.822951 0.151932 0.625477 0.314685 0.346901


0.917204 0.519760 0.401154 0.606758 0.785402
0.031523 0.869921 0.166525 0.674520 0.758400
0.581893 0.389248 0.200232 0.355635 0.826927

This means that the chromosomes v12, v111, v113, and v118 were selected for
crossover. Now we mate selected chromosomes randomly: say, the first two (i.e., v12 and
v111) and the next two ( i.e., v113, and v118) are coupled together. For each of these two
pairs, we generate a random integer number pos from the range [1…32] (33 is the total
length – number of bits- in a chromosome). The number pos indicates the position of the
crossing point .The first pairs of chromosomes is

v12 = (100011000 101101001111000001110010)


v111 = (111011101  101110000100011111011110)

And the generated number pos = 9. These chromosomes are cut after the 9th bit
and replaced by a pair of their offspring:

v112 = (100011000  101110000100011111011110)


v1111 = (111011101 101101001111000001110010)

The second pair of chromosome is

v113 = (00010100001001010100  1010111111011)


v118 = (11101111101000100011  0000001000110)
And the generated number pos = 20. These chromosomes are replaced by a pair of
their offspring:

v1113 = (00010100001001010100  0000001000110)


v1118 = (11101111101000100011  0000001000110)

The current version of the population is

v11 = (011001111110110101100001101111000)
v112 = (100011000101110000100011111011110)
v13 = (001000100000110101111011011111011)
v14 = (011001111110110101100001101111000)
v15 = (000101010011111111110000110001100)
v16 = (100011000101101001111000001110010)
v17 = (111011101101110000100011111011110)
v18 = (000111011001010011010111111000101)
v19 = (011001111110110101100001101111000)
v110 = (000010000011001000001010111011101)
v1111 = (111011101101101001111000001110010)
v112 = (010000000101100010110000001111100)
v1113 = (000101000010010101000000001000110)
v114 = (100001100001110100010110101100111)
v115 = (101110010110011110011000101111110)
v116 = (100110100000001111111010011011111)
v117 = (000001111000110000011010000111011)
v1118 = (111011111010001000110000001000110)
v119 = (111011101101110000100011111011110)
v120 = (110011110000011111100001101001011)

The next operator, mutation, is performed on a bit- by –bit basis. The probability
of mutation pm = 0.01, so we expect that (on average) 1% of bits would undergo
mutation. There are m × pop-size = 33 × 20 = 660 bits in the whole population; we expect
(on average) 6.6 mutations per generation. Every bit has an equal chance to be mutated,
so, for every bit in the population, we generate a random number r from the range [0…1];
if r <0.01, we mutate the bit.

This means that we have to generate 660 random numbers. In a sample run, 5 of
these numbers were smaller than 0.01; the bit number and the random number are listed
below:

Bit Position Random number


112 0.000213
349 0.009945
418 0.008809
429 0.005425
602 0.002836

Bit Position Chromosome Number Bit Number With


in Chromosome
112 4 13
349 11 19
418 13 22
429 13 33
602 19 8

This means that the mutation operator affects 4 chromosomes; one of the
chromosomes (the 13th) has two bits changed.

The final population is listed below; the mutated bits are typed in boldface. We
drop primes for modified chromosomes; the population is listed as new vectors vi
v1 = (011001111110110101100001101111000)
v2 = (100011000101110000100011111011110)
v3 = (001000100000110101111011011111011)
v4 = (011001111110110101100001101111000)
v5 = (000101010011111111110000110001100)
v6 = (100011000101101001111000001110010)
v7 = (111011101101110000100011111011110)
v8 = (000111011001010011010111111000101)
v9 = (011001111110110101100001101111000)
v10 = (000010000011001000001010111011101)
v11 = (111011101101101001111000001110010)
v12 = (010000000101100010110000001111100)
v13 = (000101000010010101000000001000110)
v14 = (100001100001110100010110101100111)
v15 = (101110010110011110011000101111110)
v16 = (100110100000001111111010011011111)
v17 = (000001111000110000011010000111011)
v18 = (111011111010001000110000001000110)
v19 = (111011101101110000100011111011110)
v20 = (110011110000011111100001101001011)

We have just completed one iteration (i.e., one generation ) of the while loop in
the genetic procedure. It is interesting to examine the results of the evaluation process of
the new population. During the evaluation phase we decode each chromosome and
calculate the fitness function varies from (x1,x2) values just decoded. We get:

eval(v1) = f ( 3.130078,4.996097) = 23.410669


eval(v2) = f ( 5.279042, 5.054515) = 18.201083
eval(v3) = f ( -0.991471, 5.680258) = 16.020812
eval(v4) = f ( 3.128235, 4.996097) = 23.412613
eval(v5) = f ( -1.746635, 5.395584) = 20.095903
eval(v6) = f ( 5.278638, 5.593460) = 17.406725
eval(v7) = f (11.089025, 5.054515) = 30.060205
eval(v8) = f ( -1.255173, 4.734458) = 25.341160
eval(v9) = f ( 3.130078, 4.996097) = 23.410669
eval(v10) = f ( -2.516603, 4.390381) = 19.526329
eval(v11) = f ( 11.088621, 4.743434) = 33.351874
eval(v12) = f ( 0.795406, 5.381472) = 16.127799
eval(v13) = f ( -1.811725, 4.209937) = 22.692462
eval(v14) = f (4.910618, 4.703018) = 17.959701
eval(v15) = f ( 7.935998, 4.757338) = 13.666916
eval(v16) = f ( 6.084492, 5.652242) = 26.019600
eval(v17) = f (-2.554851, 4.793707) = 21.278435
eval(v18) = f ( 11.134646, 5.666976) = 27.591064
eval(v19) = f ( 11.059532, 5.054515) = 27.608441
eval(v20) = f (9.211598, 4.993762) = 23.867227

Note that the total fitness of the new population f is 447.049688, much higher
than total fitness of the previous population, 387.776822. Also, the best chromosome,
now (v11) has better evaluation (33.351874) than the best chromosome(v15) from the
previous population (30.060205). Now we are ready to run the selection process again
and apply the genetic operators, evaluate the next generation, etc. After 1000 generations
the population is :

v1 = (111011110110011011100101010111011)
v2 = (111001100110000100010101010111000)
v3 = (111011110111011011100101010111011)
v4 = (111001100010000110000101010111001)
v5 = (111011110111011011100101010111011)
v6 = (111001100110000100000100010100001)
v7 = (110101100010010010001100010110000)
v8 = (111101100010001010001101010010001)
v9 = (111001100010010010001100010110001)
v10 = (111011110111011011100101010111011)
v11 = (110101100000010010001100010110000)
v12 = (110101100010010010001100010110001)
v13 = (111011110111011011100101010111011)
v14 = (111001100110000100000101010111011)
v15 = (111001101010111001010100110110001)
v16 = (111001100110000101000100010100001)
v17 = (111001100110000100000101010111011)
v18 = (111001100110000100000101010111001)
v19 = (111101100010001010001110000010001)
v20 = (111001100110000100000101010111001)

The fitness values are ;

eval(v1) = f ( 11.120940, 5.092514) = 30.298543


eval(v2) = f ( 10.588756,4.667358) = 26.869724
eval(v3) = f ( 11.124627,5.092514) = 30.316575
eval(v4) = f ( 10.574125,4.242410) = 31.9333120
eval(v5) = f ( 11.124627,5.092514) = 30.316575
eval(v6) = f ( 10.588756,4.214603) = 34.656125
eval(v7) = f (9.631066,4.427881) = 35.458636
eval(v8) = f ( 11.518106,4.452835) = 23.309078
eval(v9) = f ( 10.574816,4.427933) = 34.393820
eval(v10) = f ( 11.124627,5.092514) = 30.316575
eval(v11) = f ( 9.623693,4.427881) = 35.477938
eval(v12) = f ( 9.631033,4.427933) = 35.456066
eval(v13) = f ( 11.124627,5.092514) = 30.316575
eval(v14) = f (10.588756,4.242514) = 32.932098
eval(v15) = f ( 10.606555,4.653714) = 30.746768
eval(v16) = f ( 10.588814,4.214603) = 34.359545
eval(v17) = f (10.588756,4.242514) = 32.932098
eval(v18) = f ( 10.588756,4.242410) = 32.956664
eval(v19) = f ( 11.518106,4.472757) = 19.669670
eval(v20) = f (10.588756,4.242410) = 32.956664

However, if we look carefully at the progress during the run, we may discover
that in earlier generations the fitness values of some chromosomes were better than the
value 35.477938 of the best chromosome after 1000 generations. For example, the best
chromosome in generation 396 had value of 38.827553. This is due to the stochastic
errors of sampling. It is relatively easy to keep track of the best individual in the
evolution process. It is customary (in genetic algorithm implementations ) to store “the
best ever” individual at a separate location; in that way, the algorithm would report the
best value found during the whole process.

Example Problems

Example 1. Solve an unconstrained optimization given below.


b) Minimize F(X) = X sin 2 (10π X) + 1
Subject to
-1 ≤ X ≤ 2
Solution
Assumptions
Number of population =20
Decimal point accuracy (DPA) =6
Probability of crossover =0.2
Probability of mutation =0.01
Number of generations = 1
Lower bound range of the variable=-1
Upper bound range of the variable =2
Domain length (DL) =3(Upper bound-Lower bound)
Steps
a.
Calculate the two extremes of the boundary value
b. Boundary value = DL * (10) DPA
c. Number of bits = (Log (DL) + DPA * Log (10))
Log (2)

• Note: Round the number of bits to the next successive integer value (22)

Relative Actual Objective function


Binary String (Initial population)
value(X) value (X) / Fitness value
1 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 0 1 1 0 1 2582317 0.8470 1.8396
1 1 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 1 1 0 3804894 1.7215 1.6715
0 1 1 1 1 0 1 0 0 0 0 1 1 1 1 0 1 0 0 1 0 0 2000804 0.4311 1.2960
1 1 1 1 1 0 1 1 1 0 1 0 0 0 1 0 1 1 0 1 0 1 4122805 1.9489 2.9464
1 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 1 3014869 1.1564 2.1102
0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1 1866403 0.3350 1.2655
0 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 1 1 0 1 0 0 975860 -0.3020 0.9988
1 1 0 0 0 1 1 0 0 1 0 0 1 1 1 0 0 1 1 1 0 0 3249052 1.3239 1.6164
0 0 0 0 1 0 0 1 1 0 1 0 0 1 0 0 1 1 1 1 0 0 158012 -0.8870 0.8597
1 0 1 1 1 0 0 1 1 1 0 0 1 0 0 0 0 1 1 0 0 0 3043864 1.1771 1.5096
0 1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 0 1 0 1 1 1 1231127 -0.1194 0.9608
1 1 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 0 1 1 1 0 3736974 1.6729 1.9469
1 0 0 1 1 0 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 0 2543582 0.8193 1.2663
0 1 1 0 1 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 1 1762707 0.2608 1.2320
0 1 1 1 0 0 0 0 1 1 1 0 0 1 0 1 1 1 0 0 0 0 1849712 0.3230 1.1414
0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 164418 -0.8824 0.7566
0 1 0 1 0 1 1 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 1422592 0.0175 1.0048
0 0 0 1 0 1 1 1 0 0 0 0 1 0 0 1 1 1 0 0 0 0 377456 -0.7300 0.5217
1 1 1 0 0 0 1 0 0 0 1 0 1 1 1 0 1 1 1 0 1 1 3705787 1.6506 2.6500
1 1 1 0 1 1 1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0 3910824 1.7972 1.0135

d. Initial population selected randomly


e. Convert the binary string first to corresponding decimal value, then actual value
of the variable ‘X’ is found using the following formula
Actual value=Lower bound+ (Relative value*DL)/ (2^Bit length-1);

• Here the objective function is same as the fitness function

f. Selections of stings are achieved by ranking method.


Strings are sorted in ascending order according to fitness value. Ranking is kept
according to our objective and experience. Here ten ranks are given accordingly.
Percentage of ranked strings copied to total population according to ranks. (1% 3% 5%
7% 9% 11% 13% 15% 17% 19%) =100%. This method helps the weaker strings to take
part in the next generation and there by search for new strings and avoid getting trapped
in the local minimum.

Number of strings
Fitness value sorted Corresponding copied to the next
New Population of strings
in ascending order Binary strings generation

0.5217 0 0 0 1 0 1 1 1 0 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0
0.7566 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 0 0 1 0 0 1 1 1 1 0 0
0.8597 0 0 0 0 1 0 0 1 1 0 1 0 0 1 0 0 1 1 1 1 0 0 1 0 1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 0 1 0 1 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 1 0 0 1 0 0 1 1
1.6715 1 1 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 1
1.8396 1 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 1
1.9469 1 1 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1
2.1102 1 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 1 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1
2.6500 1 1 1 0 0 0 1 0 0 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1
2.9464 1 1 1 1 1 0 1 1 1 0 1 0 0 0 1 0 1 1 0 1 0 1 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1

Generation 1
Best Objective value = 0.5217
X= -0.7300
g. Number of strings participating in crossover = Number of population *
Probability of crossover (1st ,2nd ,4th ,5th )
= 4 i.e., (20*0.20)
Two strings are chosen randomly
two times and single point random crossover is done.
1st & 2nd string crossed
4th & 5th string crossed
h. Number of bits to be mutated = Number of population * Bit length * Probability
of mutation
= 5 i.e., (20*22*0.01)
(Round 4.4 to next nearest integer)
The mutation positions randomly chosen in row/column wise
(16,2)-(3,14)-(15,6)-(2,20)-(1,21)

i.e., after crossover, select 5 random positions of bits and replace "one if zero" or "zero if
one”

Binary strings
after cross over New Population of strings
0 0 0 0 1 0 1 1 1 0 1 0 0 1 0 0 1 1 1 1 0 0 0 0 0 0 1 0 1 1 1 0 1 0 0 1 0 0 1 1 1 1 1 0
0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0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 0 1 1 0 0 1 0 0 1 1 0 1 1 0 1 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 1
0 1 1 0 1 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 1 0 1 1 0 1 1 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 1
0 1 1 0 1 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 1
0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1
0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1
0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1
0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1

i. The same procedure is repeated from (e to h) and the best fitness value so far
obtained and the corresponding value of the variable X is saved. After a
required number of generations the optimum value using GA is obtained. The
results and convergence will vary depending upon GA parameters.

Example 2. The figure shown below gives the mileage of the feasible links connecting
nine offshore natural gas wellheads with an inshore delivery point. Because the location
of well head 1 is the closest to shore; it is equipped with sufficient pumping and storage
capacity to pump the output of the remaining eight wells to the delivery point. Determine
the minimum pipeline network using GA that links the well heads to the delivery point.
(Shortest path problem)
Delivery point
5 1

2
20
6 7 4 14
9
6
10 5 5
3 20 13
15 5
4 8
12 7
3
Solution 7
7
Assumptions
Number of population =6 6
Probability of crossover =0.3
Probability of mutation =0.01
Number of generations = 1

a. Initialize integer population randomly such that the last digit ends with 1 since it
is the delivery point
(Here the well positions are represented by integer value. The problem is represented
by selecting the integer length to 9 with the opinion that the minimum pipe length
need not be represented with more wells. It is not necessary the suggested method is
the only way of representing the chromosomal strings the problem in hand)
Fitness value
If the string generated is not suitable or the pipes are not connected, then a penalty is
added with the objective value (Sum of the distance without interruption) depending
upon the minimum blockage in the network. More the interruption higher the penalty.
Here the penalty factor to be added with the objective value if there is one
interruption between the network sequence is 20 (Maximum distance between any of
the two wells)
Initial Objective value Fitness
Population (Without interruption) value
243765981 - 103
438697521 - 112
964327581 - 100
987564321 53 53
789564321 54 54
785324691 - 193

b. Select the minimum sequence i.e., (9 8 7 5 6 4 3 2 1)


Generation 1
Best fitness value = 53
Sequence = 9 8 7 5 6 4 3 2 1
c. Number of strings participating in crossover = Number of population *
Probability of crossover i.e., (6*0.3)
= 2 (Round 1.8 to
next nearest integer)

Two strings are chosen randomly one time and position – based crossover is done

2th & 4th string crossed (Note: Four random selected positions chosen, except the last
node)

4 3 8 6 9 7 5 2 1 Parent 1

9 8 7 5 6 4 3 2 1 Parent 2

9 3 8 6 7 4 5 2 1 Child 1
9 4 7 8 6 5 3 2 1 Child 2

d. Number of bits to be mutated = Number of population * Bit length * Probability


of mutation

= 1 (Round (6*8*0.01) to next


nearest integer)

Inversion mutation is done once by selecting a random sub-string.

Chromosomal Chromosomal strings Objective value Fitness


Strings after crossover after mutation (Without value
interruption)
243765981 243765981 - 103
938674521 938674521 - 124
964327581 967234581 - 128
947865321 947865321 - 83
789564321 789564321 54 54
785324691 785324691 - 103

e. The same procedure is repeated from (b to d) and the best fitness value so far
obtained and the corresponding network pipe sequence is saved. After a required
number of generations the optimum value using GA is obtained. The results and
convergence will vary depending upon GA parameters.

Example 3. Find the shortest highway route using any GA model between two cities. The
network in the figure below provides the possible routes between the starting city at node 1
and the destination city at node 8. The routes pass through intermediate cities designated by
nodes 2 to 5. (Shortest path problem).

12
2
11 5 11
7 7
8 9 8
8 14 6
1 3
9
5 6
10 10 7

13
4
Solution

Assumptions
Number of population =6
Probability of crossover =0.3
Probability of mutation =0.01
Number of generations = 1

a. The first and the last city position are always fixed as 1 & 8 for evaluation of
objective function. Only 2 city positions are possible between nodes 2 and 5. So the
binary population is initialized randomly representing 2 and 5. The problem is
represented by selecting the 6 binary bit lengths. (It is not necessary that the
suggested method is the only way of representing the chromosomal strings for the
problem in hand)

Fitness value
If the string generated is not suitable or the city nodes are not connected, then a
penalty is added with the objective value (Sum of the distance without interruption)
depending upon the minimum blockage in the transport network. More the
interruption higher the penalty. Here the penalty factor to be added with the objective
value if there is one interruption between the network sequence is 14 (Maximum
distance between any of the two city nodes)

Initial Objective value Fitness


Population (Without interruption) value
1 010 101 8 30 30
1 010 110 8 27 27
1 110 010 8 - 42
1 011 101 8 33 33
1 100 110 8 24 24
1 111 011 8 - 42

b. Select the minimum sequence i.e., (1 4 6 8)

Generation 1

Best fitness value = 24


Sequence = 1 100 110 8

c. Number of strings participating in crossover = Number of population * Probability of


crossover i.e., (6*0.3)
= 2 (Round 1.8 to
next nearest integer
value)
Two strings are chosen randomly one time and single point random crossover is done
1st & 3rd string crossed

d. Number of bits to be mutated = Number of population * Bit length * Probability of


mutation

= 1 (Round (6*6*0.01) to
next integer value)
The mutation position randomly chosen in row/column wise is (4, 6)

Chromosomal Chromosomal strings Objective value Fitness


Strings after crossover after mutation (Without value
interruption)
1 01-0010 8 1 01-0010 8 - 35
1 010 110 8 1 010 110 8 27 27
1 11-0101 8 1 11-0101 8 - 39
1 011 101 8 1 011 100 8 - 36
1 100 110 8 1 100 110 8 54 54
1 111 011 8 1 111 011 8 - 103

e. The same procedure is repeated from (b to d) and the best fitness value so far
obtained and the corresponding city node sequence is saved. After a required number
of generations the optimum value using GA is obtained. The results and convergence
will vary depending upon GA parameters.

REFERENCE
[1] “Artificial Intelligence and Intelligent Systems” N.P.Padhy “Oxford University Press”
First Edition 2005

You might also like