0% found this document useful (0 votes)
21 views6 pages

GA Example - 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views6 pages

GA Example - 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 07 Issue: 05 | May 2020 www.irjet.net p-ISSN: 2395-0072

GENETIC ALGORITHM FOR SOLVING SIMPLE MATHEMATICAL


EQUALITY PROBLEM
Himani Panwar 1, Pragya2, Dharamveer Singh 3, Abha Singh 4
1Student, Department of IT, IMS Engineering College, Ghaziabad, India
2Assistant Professor, Department of IT, IMS Engineering College, Ghaziabad, India
3Student, Department of IT, IMS Engineering College, Ghaziabad, India
4Student, Department of IT, IMS Engineering College, Ghaziabad, India

---------------------------------------------------------------------***---------------------------------------------------------------------
Abstract - This paper explain genetic algorithm in brief used to solve the complex problems in the field of
with the help of flowchart and solve the simple searching and optimization problems. The process of
natural selection starts with the evolution selection is very
mathematical equality problem with the help of genetic
important step in this it selects the fittest individuals from
algorithm. Genetic algorithms are used to generate high a population and they produce offspring which inherit the
quality solutions for optimizations problems and search characteristics of the parents and will be added to the next
problems. Genetic Algorithm is a popular optimization tool generation the process is repeated till we found the
in the field of natural science, finance and economics, optimal answer to the problem. If parents have better
mathematics , earth science, industry, management , fitness, their offspring will be better than parents and have
a better chance at surviving, the whole genetic algorithm
biological science, earth science and computer science.
revolve around this only the fittest one will have more
Genetic Algorithms are based on the ideas of natural chance of surviving. This process keeps on repeating and at
selection and genetics. Genetic algorithms follow the process the end, a generation with the fittest individuals will be
of evolution and natural selection which means those found. This notion can be applied for a search problem and
species who can adapt to changes in their environment are also for optimization problem.
able to survive and reproduce and go to next generation and
those who are not able to adapt changes they will be 2. PHASES
discarded.
There are 5 phases in genetic algorithm which are as
Key Words: Genetic Algorithm, selection, population, follows:
fitness function.
1. Initial population
2. Fitness function
1. INTRODUCTION 3. Selection
4. Crossover
Genetic algorithm became famous because of the work of 5. Mutation
John Holland in the early 1970s, and with the help of his
book "Adaptation in Natural and Artificial Systems (1975)".
He was the founder of genetic algorithm. A genetic 2.1 Initial Population
algorithm is a search heuristic and optimization algorithm
which is inspired by Charles Darwin’s theory of natural This process starts with a set of individuals which is called
evolution. Darwin's concept of evolution is then applied to a Population. An individual have it’s own characteristics
computer science to solve computational problems which and theses individuals are known as Genes. Genes are
takes a lot of time if solved manually .This algorithm shows combined into a string to form a Chromosome.
the process of natural selection from the generation where
the fittest individuals are selected from the generation for 2.2 Fitness Function
the reproduction in order to produce offspring of the next
generation, the fittest ones will survive in the next The fitness function determines how fit an individual is it
generation. Genetic algorithms imitate the process of will survive in next generation or not. The fitness function
natural selection. In simple words, they choose the plays a vital role in genetic algorithm. The fitness function
individuals from the generation and then find their gives score to each individual. The probability that an
objective function and follow rest of the steps to find out individual will be selected for next generation is based on
the best solution. Genetic algorithms are based on an its fitness score. The fittest ones will survive in next
analogy with genetic structure and behaviour of generation.
chromosome of the population. Genetic algorithms are

© 2020, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 7622
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 07 Issue: 05 | May 2020 www.irjet.net p-ISSN: 2395-0072

2.3 Selection 3.1 Flowchart

The idea of selection phase is to select the fittest individuals Flowchart of genetic algorithm is as follows:
from the population and give approval to them for the next
generation. Individuals are selected based on their fitness
scores. Individuals with high fitness score have more chance
to be selected for reproduction.

2.4 Crossover

Crossover is the most important phase in a genetic


algorithm. A crossover point is randomly selected from the
generation and Offspring are created by exchanging the
genes of parents among themselves until the crossover
point is reached. The new offspring are added to the
population and new population will be generated.

2.5 Mutation

This process is used to maintain the diversity in the


generation and it prevents premature convergence. In
mutation genes are randomly replaced on a position with
a new value.

2.6 Termination

The algorithm terminates if the population has converged.


On termination algorithm provides the optimal answer.

3. GENETIC ALGORITHM

Process of genetic algorithm is as follows:


STEP 1: Determine the number of chromosomes,
4. Linear equality problem
generation, and mutation rate and crossover rate value for
the population. So here is the example of applications of genetic algorithm
to solve the simple mathematical linear equality problem.
STEP 2: Generate chromosomes and initialization of
Suppose there is equality a + 2b + 3c + 4d+5e = 20, genetic
values to the chromosomes.
algorithm will be used to find the value of a, b, c, d and e
STEP 3: Repeat steps 4-7 until the number of generations that satisfy the above equation for this problem the
is met. objective is minimizing the value of function f(x) where
f(x) = ((a + 2b + 3c + 4d+5e) - 20). Since there are five
STEP 4: Calculation of fitness values of chromosomes by variables in the equation, namely a, b, c, d and e we can
calculating the objective function. compose the chromosome as follow: To speed up the
computation, we can restrict that the values of variables a,
STEP 5: Chromosomes selection b, c, and d are integers between 0 and 20.
STEP 6: Crossover
4.1 Initialization
STEP 7: Mutation
For example we define the number of chromosomes in
STEP 8: Solution (Best Chromosomes) population are 6, then we generate random value of gene
a, b, c ,d and e for 6 chromosomes

© 2020, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 7623
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 07 Issue: 05 | May 2020 www.irjet.net p-ISSN: 2395-0072

Chromosome[1] = [a;b;c;d;e] = [11;05;04;00;08] The probability for each chromosomes is formulated by


this formula:
Chromosome[2] = [a;b;c;d;e] = [09;15;03;01;03]
P[i] = Fitness[i] / Total
Chromosome[3] = [a;b;c;d;e] = [04;00;01;08;02]
P[1] = 0.0185 / 0.1108= 0.167
Chromosome[4] = [a;b;c;d;e] = [01;05;13;04;06]
P[2] = 0.0208 / 0.1108 = 0.188
Chromosome[5] = [a;b;c;d;e] = [02;09;12;09;02]
P[3] = 0.0333 / 0.1108 = 0.301
Chromosome[6] = [a;b;c;d;e] = [08;14;05;11;00]
P[4] = 0.013 / 0.1108= 0.1173
4.2 Evaluation
P[5] = 0.0120 / 0.1108 = 0.1083
We calculate the objective function value for each
chromosome produced in the initialization step: P[6] = 0.0132 / 0.1108 =0.1191

F_obj[1] = Abs(( 11 + 2*5 + 3*4 + 4*0 + 5*8 ) - 20) =53 From the probabilities above we find out that the
Chromosome 3 has the highest fitness, so Chromosome 3
F_obj[2] = Abs((9 + 2*15 + 3*3 + 4*1 + 5*3) - 20) = 47 has the highest probability to be selected for the next
generation. For the selection process we use roulette
F_obj[3] = Abs((4 + 2*0 + 3*1 + 4*8 + 5*2) - 20) = 29
wheel method, for that we should compute the cumulative
F_obj[4] = Abs((1 + 2*5 + 3*13 + 4*4 + 5*6) - 20) = 76 probability values and their sum should be equal to 1 if
their sum is not equal to 1 then there is some error in
F_obj[5] = Abs((2 + 2*9 + 3*12 + 4*9 + 5*2) - 20) = 82 above computations:

F_obj[6] = Abs((8 + 2*14 + 3*5 + 4*11 +5*0) – 20) = 75 C[1]=0.0167

4.3 Selection C[2]= 0.0167 + 0.188=0.2606

The chromosomes which higher fitness will have more C[3]= 0.0167 + 0.188 + 0.301=0.3518
probability to be selected for the next generation. To
C[4]= 0.0167 + 0.188 + 0.301+0.1173 =0.7167
calculate fitness probability we have to calculate the
fitness of each chromosome. To avoid the divide by zero C[5]= 0.0167 + 0.188 + 0.301+0.1173 + 0.1083 =0.7811
problem, the value of F_obj is added by 1 so that fitness
will be calculated. C[6]= 00.0167 + 0.188 + 0.301+0.1173 + 0.1083 +
0.1191=1.00
Fitness[1] = 1 / (1+F_obj[1]) = 1/(1+53) = 0.0185
This process is used to generate random number R in the
Fitness[2] = 1 / (1+F_obj[2]) = 1/(1+47) = 0.0208 range 0-1 as follows.
Fitness[3] = 1 / (1+F_obj[3]) = 1/(1+29)= 0.0333 R[1] = 0.209
Fitness[4] = 1 / (1+F_obj[4]) = 1/(1+76) = 0.013 R[2] = 0.482
Fitness[5] = 1 / (1+F_obj[5]) = 1/(1+82) = 0.0120 R[3] = 0.111
Fitness[6] = 1 / (1+F_obj[6]) = 1/(1+75) = 0.0132 R[4] = 0.842
Total=0.0185 + 0.0208 + 0.0333 + 0.013 + 0.0120+ R[5] = 0.589
0.0132
R[6] = 0.801
=0.1108
So here we do the comparison and on the basis of that new
chromosomes will be formed. If random number R[1] is
© 2020, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 7624
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 07 Issue: 05 | May 2020 www.irjet.net p-ISSN: 2395-0072

greater than C[1] and smaller than C[2] then select end;
Chromosome[2] as a chromosome in the new population
for next generation[1][2]: end;s

NewChromosome[1] = Chromosome[2] Chromosome k will be selected as a parent if R[k]. Suppose


we set that the crossover rate is 25%, then Chromosome
NewChromosome[2] = Chromosome[3] number k will be selected for crossover if random
generated value for Chromosome k below 0.25. The
NewChromosome[3] = Chromosome[1] process is as follows: First we generate a random number
R as the number of population.
NewChromosome[4] = Chromosome[6]
R[1] = 0.117
NewChromosome[5] = Chromosome[3]
R[2] = 0.482
NewChromosome[6] = Chromosome[5]
R[3] = 0.185
Chromosomes in the population thus became:
R[4] = 0.199
Chromosome[1] = [09;15;03;01;03]
R[5] = 0.356
Chromosome[2] = [04;00;01;08;02]
R[6] = 0.892
Chromosome[3] = [11;05;04;00;08]
For random number R above, parents are
Chromosome[4] = [08;14;05;11;00]
Chromosome[1], Chromosome[3] and Chromosome[4]
Chromosome[5] = [04;00;01;08;02] will be selected for crossover.

Chromosome[6] = [02;09;12;09;01] Chromosome[1] >< Chromosome[3]

4.4 Crossover Chromosome[3] >< Chromosome[4]

In this example, we use one-cut point, i.e. we randomly Chromosome[4] >< Chromosome[1]
choose a position in the parent chromosome and then
After chromosome selection, the next step is to determine
exchange sub-chromosome till we reach the one cut point.
the position of the crossover point. This is accomplished
Parent chromosome which will mate is randomly choose
by generating random numbers between 1 to length of
and the number of mate Chromosomes is controlled using
Chromosome–1. Position of crossover point = length of
crossover rate (ρc) parameters. Pseudo-code for the
chromosome-1(5-1) = 4.
crossover process is as follows:
In this case, generated random numbers should be
Begin
between 1 and 4. When we get the crossover point,
k← 0; parents Chromosome will be cut at crossover point and
genes will be interchanged. For example we will generate
while(k<population)do 3 random number and we get:

R[k] = random(0-1); C[1] = 2

if(R[k]< ρc) then C[2] = 3

select Chromosome[k] as parent; C[3] = 1

end; Then for first crossover, second crossover and third


crossover, parent’s gens will be cut at gen number 2, gen
k = k + 1; number 3 and gen number 1 respectively, e.g.

© 2020, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 7625
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 07 Issue: 05 | May 2020 www.irjet.net p-ISSN: 2395-0072

Chromosome[1] = Chromosome[1] >< Chromosome[3] of total gen in the population that will be mutated: number
of mutations = 0.1 * 30 = 1.8 ≈ 3 Suppose generation of
= [09;15;03;01;03] >< [11;05;04;00;08] random number yield 2, 14 and 28 then the chromosome
which have mutation are Chromosome number 1 gen
= [09;15;04;00;08]
number 2 , Chromosome 3 gen number 4 and chromosome
Chromosome[3] = Chromosome[3] >< Chromosome[4] number 6 gen number 3. The value of mutated gets at
mutation point is replaced by random number between 0-
= [11;05;04;00;08] >< [08;14;05;11;00] 20. Suppose generated random number are 2 , 0 and 5
then Chromosome composition after mutation are:
= [11;05;04;11;00]
Chromosome[1] = [09;02;04;00;08]
Chromosome[4] = Chromosome[4] >< Chromosome[5]
Chromosome[2] = [04;00;01;08;02]
= [08;14;05;11;00] >< [04;00;01;08;02]
Chromosome[3] = [11;05;04;00;00]
= [08;00;01;08;02]
Chromosome[4] = [08;00;01;08;02]
Thus Chromosome population after experiencing a
crossover process: Chromosome[5] = [04;00;01;08;02]

Chromosome[1] = [09;15;04;00;08] Chromosome[6] = [02;09;05;09;01]

Chromosome[2] = [04;00;01;08;02] After finishing the mutation process then we have one
iteration or one generation of the genetic algorithm. Now,
Chromosome[3] = [11;05;04;11;00] we can evaluate the objective function after one
generation:
Chromosome[4] = [08;00;01;08;02]
Chromosome[1] = [09;02;04;00;08]
Chromosome[5] = [04;00;01;08;02]
F_obj[1] = Abs((9+ 2*2 + 3*4 + 4*0 + 5*8 )-20)
Chromosome[6] = [02;09;12;09;01]
= 45
4.5. Mutation
F_obj[2] = Abs((4+ 2*0 + 3*1 + 4*8 +5*2 )-20)
Mutation_rate parameter determines the number of
chromosomes that have mutations in a population. = 29
Mutation process is done by replacing the generation at
random position with a new value. The process is as F_obj[3] = Abs((11+ 2*5 + 3*4 + 4*0 +5*0 )-20)
follows:
= 13
So, first we have to calculate the total length of generation
in the population. The total length of the generation is F_obj[4] = Abs((8+ 2*0 + 3*1 + 4*8 +5*2 )-20)

total_generation = = 33
number_of_generation_in_Chromosome * number of
F_obj[5] = Abs((4+ 2*0 + 3*1 + 4*8 +5*2 )-20)
population
= 29
= 5 * 6 = 30
F_obj[6] = Abs((2+ 2*9 + 3*5 + 4*9 +5*1 )-20)
Mutation process is done by generating a random integer
between 1 and total gen (1 to 30). . If the generated = 56
random number is smaller than the mutation rate(ρm)
variable then marked the position of gen in chromosomes. So, these new Chromosomes will repeat the same process
Suppose we define ρm 10%, it is expected that 10% (0.1) of genetic algorithm such as evaluation, selection,

© 2020, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 7626
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 07 Issue: 05 | May 2020 www.irjet.net p-ISSN: 2395-0072

crossover and mutation as the previous generation of 6. CONCLUSION


Chromosomes did and at the end a new generation of
Chromosome for the next iteration is produced. This  GA have an objective function which determines
the quality of the solution.
process will be repeated until a predetermined number of
 GA finds the solution near to optimal answer.
generations.
 Outcomes shows that the genetic algorithm have
the ability to find optimal solution for solving
5. EXPERIMENTAL RESULTS linear equation.
 GA is easy to understand and implement.
By executing the simple genetic algorithm code (SGA)  GA can be used for solving the complex problems.
written in Java programming language. The primary work  Most fittest will survive and choose for next
of the SGA is performed in three routines selection, generation.
crossover, and mutation we get the best values of the
variables a, b, c, d and e.
7. REFERNCES
SGA Parameters
[1] Denny Hermawanto, “Genetic Algorithm for
Population size = 10 Solving Simple Mathematical Equality Problem”,
Indonesian Institute of Sciences (LIPI),
Chromosome length = 5 INDONESIA[1]

Maximum of generation = 20 [2] Lubna Zaghlul Bashir, “Solve Simple Linear


Equation using Evolutionary Algorithm”, World
Crossover probability = 0.25 Scientific News 19 (2015) 148-167[2]

Mutation probability = 0.01

Linear equation problem

A value B value C value D value E value

1 1 3 2 0

2 6 4 0 0

1 0 2 2 1

1 1 0 3 1

2 0 1 0 3

6 0 3 0 1

4 4 0 2 0

0 3 2 2 0

3 2 2 0 1

4 4 0 2 0

© 2020, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 7627

You might also like