Professional Documents
Culture Documents
GA Assignment Shazia Samoon
GA Assignment Shazia Samoon
Shazia Samoon
Ph.D. Scholar, shazia.samoon@sindh.edu.pk 2k21/P-CS/14
Table of Contents
1.1 History: ............................................................................................................................................ 2
1.2 Introduction: ................................................................................................................................... 2
1.3 Components of Genetic Algorithm:............................................................................................... 3
1.4 Structure of Genetic Algorithm: .................................................................................................... 4
1.5 Genetic Algorithm Advantages: .................................................................................................... 4
1.6 Limitations of Genetic Algorithm: ................................................................................................ 4
1.7 Applications of Genetic Algorithm:............................................................................................... 4
2. Literature Review: ............................................................................................................................ 5
3. Traveling salesmen problem (TSP): ................................................................................................ 6
3.1 Backpropagation Deep Learning Approach............................................................................. 6
3.2 Methodology: ............................................................................................................................... 7
3.2.1 Sigmoid Function ................................................................................................................. 7
3.2.2 Hidden Layer and loss function/Gradient descent function........................................... 7
3.2.3 Back Propagation Neural Network .................................................................................... 8
3.3.4 The library installed for the implementation of TSP in python: ..................................... 9
3.3.5 TSP – Algorithm Designed: ................................................................................................ 9
4. Result and Discussion ....................................................................................................................... 9
4.1 Best Optimal Route for traveling salesmen to explore cities using Deep Learning approach
implementation in Python .................................................................................................................... 9
5. Conclusion ....................................................................................................................................... 14
References:........................................................................................................................................... 15
Best Optimal Route for traveling salesmen to
explore cities using Genetic Algorithm with
BackPropagation Artificial Neural Network: A Deep
Learning Approach
1.1 History:
In 1954, the concept of the Genetic Algorithm was proposed by M. Ibn Moussa, furthermore,
the University of Michigan developed a Genetic algorithm in the center of Engineering and
Practice in 1975. John Holland and his colleagues worked and explored its features that how it
inspired and implemented the field of computing.
1.2 Introduction:
A genetic algorithm is a set of methods that are inspired by the process of biological
development and inheritances. From the last few eras, genetic algorithms have been
efficaciously useful and provided the best solution for many problems. Such as in the field of
medicine, engineering, and science. But nowadays, Genetic Algorithm plays a very important
role in the field of Operation Research and Computational Optimization. It is also known as a
metaheuristic evolutionary algorithm. Consequently, this algorithm aims to produce the fittest
new population, It provides the optimized solution to any problem such as traveling salesman
[1].
Traveling salesman (TSP) is a combinatorial optimization NP-Hard problem, it is used to find
the shortest path or distance between the cities and the main constraint of this problem is that
each city is visited exactly once.
There are two types of TSP
1. Symmetric TSP – having the same cost and time between cities traversing
2. Asymmetric TSP – having different costs and time executed during traversing
As we go through with symmetric TSP to visit the route exactly once and find the best route.
It works with the population and can make decisions from the entire sample. Initially, the
Population is randomly initialized and then performs the operations, selection, replacement,
crossover, and mutation to get the solution to produce the offspring for the next generation(
survival of the fitness) [2].
Reprresentation(Initialization
of Population)
3.2 Methodology:
TSP has a set of cities to explore, the distance between cities, a person has to visit exactly once
and come back to the origin of the city that he started from. I used various GA mutation,
crossover methods to implement the TSP for a better solution, I import the DEAP (Distributed
Evolutionary Algorithm in Python) library to implement TSP, partial crossover, and for
mutation used mutShuffleIndexes with different mutation rate, then sklearn for 2D data
classification, after that I import seaborn library for the dynamic graph generation.
3.2.1 Sigmoid Function
I created some user-defined functions, I created a Sigmoid activation function to activate the
hidden layers.
def sigmoid(x):
return(1/(1 + np.exp(-x)))
As we know that genetic algorithm is used to get optimized solutions to any problem. Detail of
the components is summarized in table (1)
Representation
For the initialization of the population (number of cities), we use the integer type
representation.
Euclidian function formula
Euclidean distance formula is used to calculate the distance between line segments. Consider
two points, as (x1, y1) and (x2, y2) these represented two-dimensional coordinate level.
Accordingly, the Euclidean distance formula can be written numerically as
d =√[(x2 – x1)2 + (y2 – y1)2] Where, “d” represents the Euclidean distance, (x1, y1) is the first
point coordinate, (x2, y2) is the second point coordinate [13].
There is five-step to the elaborate procedure of the best optimal route for the TSP Genetic
Algorithm. It has been implemented in python language. The main objective of this approach
is to get the optimal route. So, route optimization needs to explore a set of cities we select 8
cities, then calculated distance between cities, and the person who has to visit exactly once and
come back to the origin of the city that he started from.
To get the best optimal route for traveling men, several experiments have been performed.
Experiment 1:
In the 8-experiment set 0.1 mutation rate with mutShuffleIndexes function, cxPartialyMatched
method with 0.4% probability, 10 generations were set,100 population and 8 number of cities
were visited with the deep learning approach.
Result:
Following the route is the Best Route for Traveling salesmen
Before Variation : [7, 0, 1, 4, 5, 6, 3, 2]
total time: 3293266375.1928916 s
After Genetic variation : [7, 0, 1, 4, 5, 6, 3, 2, 7] is best route
fitness evaluated : [array(237.26433488)]
Best fittest individual [[7 0 1]
[4 5 6]
[3 2 7]]
[[-0.33445153 -0.08655303 -1.24324752 0.50896063 -1.51083673]]
Experiment:2
In the 2-experiment set 0.6 mutation rate, partial crossover method with 0.5% probability, 100
generations were set, 100 population and 10 number of cities were visited.
Result:
Generation: 0 | Fitness: inf
Generation: 5 | Fitness: 280.25
Generation: 10 | Fitness: 235.58
Generation: 15 | Fitness: 235.58
Generation: 20 | Fitness: 235.58
Generation: 25 | Fitness: 235.58
Generation: 30 | Fitness: 235.58
Generation: 35 | Fitness: 235.58
Generation: 40 | Fitness: 235.58
Generation: 45 | Fitness: 235.58
Generation: 50 | Fitness: 235.58
Generation: 55 | Fitness: 235.58
Generation: 60 | Fitness: 235.58
Generation: 65 | Fitness: 235.58
Generation: 70 | Fitness: 235.58
Generation: 75 | Fitness: 235.58
Generation: 80 | Fitness: 235.58
Generation: 85 | Fitness: 235.58
Generation: 90 | Fitness: 235.58
Generation: 95 | Fitness: 235.58
Figure 5 Experiment 2
Experiment 3:
In the 3-experiment set 0.25 mutation rate, partial crossover method with 0.5% probability,
100 generations were set, 100 population and 10 number of cities were visited.
Result:
Following the route is the Best Route for Traveling salesmen
Before Variation : [2, 4, 3, 1, 6, 8, 9, 5, 7, 0]
total time: 3290869809.2432976 s
After Genetic variation : [2, 4, 3, 1, 6, 8, 9, 5, 7, 0, 2] is best route
Figure 6 Experiment 3
Experiment 4:
In the 3-experiment set 0.1 mutation rate, partial crossover method with 0.5% probability, 100
generations were set, 100 population and10 number of cities were visited.
Result:
Following the route is the Best Route for Traveling salesmen
Before Variation : [3, 1, 0, 7, 6, 8, 9, 5, 2, 4]
total time: 3290870282.9133873 s
After Genetic variation : [3, 1, 0, 7, 6, 8, 9, 5, 2, 4, 3] is best route
Figure 7 Experiment 4
Experiment 5:
In the 5-experiment set 0.25 mutation rate, partial crossover method with 0.5% probability,
100 generations were set, 100 population and, 4 number of cities were visited.
Result
Following the route is the Best Route for Traveling salesmen
Before Variation : [2, 1, 0, 3]
total time: 3291190764.1772532 s
After Genetic variation : [2, 1, 0, 3, 2] is best route
Figure 8 Experiment 5
5. Conclusion
Traveling salesman (TSP) is a combinatorial optimization NP-Hard problem, it is used to find
the shortest path or distance between the cities and the main constraint of this problem is that
each city is visited exactly once. TSP has a set of cities to explore, the distance between cities,
a person has to visit exactly once and come back to the origin of the city that he started from. I
used various GA mutation, crossover methods to implement the TSP for a best optimal route,
I import the DEAP (Distributed Evolutionary Algorithm in Python) library to implement TSP,
partial crossover, and for mutation used mutShuffleIndexes with different mutation rate,
Furthermore, I used Deep Learning approach backward propagation neural network to find
accuracy of best route.
References :
[1] O. Kramer, “Genetic algorithms,” Stud. Comput. Intell., vol. 679, no. 2010007, pp. 11–
19, 2017, doi: 10.1007/978-3-319-52156-5_2.
[2] R. Ouch, K. W. Reese, and R. V. Yampolskiy, “Hybrid Genetic Algorithm for the
Maximum Clique Problem combining Sharing and migration,” CEUR Workshop
Proc., vol. 1348, pp. 79–84, 2013.
[3] networking for dummies (10th E. D. Lowe, “Genetic Algorithms Tutorial,” Organ.
Behav., pp. 1–305, 2017, [Online]. Available:
https://www.tutorialspoint.com/asp.net/asp.net_tutorial.pdf.
[4] G. National and H. Pillars, “Genetic Algorithm.”
[5] I. Signal and P. Magazine, “What are Genetic Algorithms ? Optimization Algorithms,”
IEEE Signal Process. Mag., no. November, pp. 22–37, 1996.
[6] G. L. Viviani, Practical Optimization, vol. PER-5, no. 7. 1985.
[7] S. Katoch, S. S. Chauhan, and V. Kumar, A review on genetic algorithm: past, present,
and future, vol. 80, no. 5. Multimedia Tools and Applications, 2021.
[8] H. Bhasin and S. Bhatia, “Application of Genetic Algorithms in Machine learning,”
Int. J. Comput. Sci. Inf. Technol., vol. 2, no. 5, pp. 2412–2415, 2011, [Online].
Available: http://www.ijcsit.com/docs/Volume 2/vol2issue5/ijcsit20110205121.pdf.
[9] M. Kumar, M. Husain, N. Upreti, and D. Gupta, “Genetic Algorithm: Review and
Application,” SSRN Electron. J., vol. 2, no. 2, pp. 451–454, 2020, doi:
10.2139/ssrn.3529843.
[10] E. Alkafaween and A. B. A. Hassanat, “Improving tsp solutions using ga with a new
hybrid mutation based on knowledge and randomness,” Commun. - Sci. Lett. Univ.
Zilina, vol. 22, no. 3, pp. 128–139, 2020, doi: 10.26552/com.C.2020.3.128-139.
[11] G. E. Hinton, S. Osindero, and Y. W. Teh, “A fast learning algorithm for deep belief
nets,” Neural Comput., vol. 18, no. 7, pp. 1527–1554, 2006.
[12] W. Resource, “Supervised Deep Learning Algorithms : Types and Applications,”
WEBIST 2018 - Proceedings of the 14th International Conference on Web Information
Systems and Technologies.
https://www.analyticsvidhya.com/blog/2021/05/introduction-to-supervised-deep-
learning-algorithms/ (accessed Apr. 12, 2022).
[13] W. Source, “Euclidean Distance - Definition, Formula, Derivation & Examples.”
https://byjus.com/maths/euclidean-distance/#what-is-euclidean-distance (accessed Apr.
27, 2022).