Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Best Optimal Route for traveling salesmen to explore

cities using Genetic Algorithm with Back Propagation


Artificial Neural Network :A Deep Learning
Approach

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].

Figure 1 Genetic Algorithm cycle

1.3 Components of Genetic Algorithm:


1. Initialization (Population Representation)
2. fitness function( for finding the fittest candidate)
3. Selection ( Parent)
4. Variation(Crossover, Mutation, Recombination)
5. Evaluate the Fittest solution or Survival selection [2]
1.4 Structure of Genetic Algorithm:

Reprresentation(Initialization
of Population)

Evalutate the fitness by


function

Select the fittest parent from


the population

Perfrom variation operation


(Crossovere, Mutation)

Producre new fittest offspring


for next generation(Suervival
fittest slection)

1.5 Genetic Algorithm Advantages:


GAs offers several advantages that have helped them become extremely popular.
These include: Does not necessitate the use of unauthorized data, when compared to traditional
procedures, it is faster and more efficient, it has a lot of parallel processing power, it Optimizes
multi-objective problems as well as continuous and discrete functions, and it provides a list of
"excellent" solutions rather than simply one [3].

1.6 Limitations of Genetic Algorithm:


All problems cannot be solved by the Genetic Algorithm it has some limitations like the Size
of the Sample. Repeated calculation of fitness causes expenses because the solution is
stochastic, there are no guarantees about its optimality or quality. It may not touch on the best
solution if it is not implemented correctly.

1.7 Applications of Genetic Algorithm:


Genetic Algorithm has so many applications but here few are given beneath:
A. Machine Learning Robot behavior
B. Protein/ DNA Molecular Structure
C. Vehicle’s design process
D. Circuit design
E. Network Design
2. Literature Review:
According to G and H. Pillars, the Genetic Algorithm is a search-based optimization algorithm.
It is used to find the robustness, it is classified into two types
A . Heuristic Search techniques
B. Global Search [4].
I. Signal and P. Magazine, said that the Genetic Algorithm is the best optimization technique
to find the fittest candidate for novel creation for the next generation. several obstacles must
be addressed. It is impossible to estimate the performance of the Genetic Algorithm due to its
randomness and robustness, which is not usable for solving real-time problems. Sometimes it
can’t reach the appropriate solution [5].
The calculus-based technique and the enumerative technique are the two main types of
optimization algorithms that have been employed in the past. The gradient-directed searching
mechanism is used in calculus-based optimization strategies to solve the error surface or
differentiable surface of an objective function [6].
According to S. Katoch et al. proposed research on the organized perspective on hereditary
calculations. GA and its distinctions have been examined with the application. Application
explicit hereditary administrators are examined. A few hereditary administrators are intended
for portrayal. Notwithstanding, they are not material to explore areas. Interactive media and
remote network applications were the fundamental consideration of this paper. The difficulties
and issues referenced in this paper will assist the experts with completing their examination.
There are quite a large number of benefits of involving GAs in other exploration areas and
metaheuristic calculations. The aim of this paper isn't just to give the wellspring of ongoing
examination in GAs, yet additionally to give the data about every part of GA. It will urge the
analysts to comprehend the essentials of GA and utilize the information in their exploration
issues [7].
Jhon Holland proposed a new component named inversion for the implementation of Genetic
Algorithms. It is also said to mimic Darwin’s theory. It is helpful to design artificial agents by
using machine learning techniques [7].
In this paper, the Chess game is used as an example of Machine learning by using a Genetic
Algorithm. It proposed a new method of Genetic Algorithm. The proposed work focused on
the randomness of the Genetic Algorithm. It has the ability to a variety of populations meet
near the desired end by calculating its fitness function. It is based on the neural network concept
[8].
A genetic algorithm is a problem-solving optimization algorithm, it is an evolution-based
process and is focused to find the optimum solution for several kinds of problems. It can be
applied in artificial intelligence approaches such as robotics, machine learning, and deep
learning [9]
This research paper elaborated the new approach to the TSP problem by using GA, it is based
on hybrid mutation knowledge TSP, which is a type of mutation technique that helps to
improve the optimal solution due to hybrid mutation( IRGIBNNM) chances have been
increased for best solution [10].

3. Traveling salesmen problem (TSP):


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. There are several research has been
conducted to find the best optimal route for TSP, here we proposed a new approach that TSP
can be solved by using a backpropagation neural network deep learning approach.

3.1 Backpropagation Deep Learning Approach


As we know Deep Learning is a subfield of Machine Learning and it mimics the structure and
function of the human brain, therefore, it is an Artificial Neural Network (ANN), apart from
that, implementation took place by using Back-propagation Neural Network (BPNN), BNN is
a simple deep learning approach, where a set of neurons is used as input and has some layers
and target output, here I simulate this approach to solve the TSP problem [11].
ANN is a type of supervised Deep Learning, ANN is a basic building that mimic human brain,
another type of deep learning approaches are Convolutional Neural networks (CNN) and
Recurrent Neural networks (RNN) [12].
Backpropagation has two phases to make prediction of the model.
1. First is obtain output prediction from given inputs through Forward Propagation Neural
Network (FPNN).
2. Second phase the gradient decedent loss function has been computed at last layer of the
network model by recursively updating its weights where actual output is minus from predicted
target output ( actual -predicted target output).
Figure 2 Back Propagation Neural Network, Source: https://www.guru99.com/backpropogation-neural-
network.html

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)))

3.2.2 Hidden Layer and loss function/Gradient descent function


I created Hidden layer function, Generate function to generate the weight of path, loss function,
is used here to check the error rate between the actual output and target output, backpropagation
function is used to reverse the forward propagation, here I used it in TSP to return the origin
of the city by using the transpose of the best-fit route, and train function to train the data to get
the accuracy of the route.
3.2.3 Back Propagation Neural Network
3.3.4 The library installed for the implementation of TSP in python:

Numpy,seaborn3, sklearn, matplotlib, and DEAP (Distributed evolutionary Algorithm for


python)

3.3.5 TSP – Algorithm Designed:


1. find the best optimal route.
2. Random initialize set of cities
3. Find the distance between the cities by using Euclidian function
4. repeat step 5 until best route found
5. Perform GA operations:
Select a best-fit route for variation
Perform Partial Crossover
Perform Mutation with 0
Evaluate the best route for cities, by Back- propagation Neural Network BPNN
6. Stop it, if best route found

4. Result and Discussion


4.1 Best Optimal Route for traveling salesmen to explore cities
using Deep Learning approach implementation in Python
4.1 Experiments and Result of TSP

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].

Table 1 Representation detail

Components Sample Size


Representation (Initialization of Population) (Integer) Random population 10-1000
Fitness Function Euclidian function
Selection Tournament
Variations Crossover, Mutation M-rate (0.6)
Survival fitness Produce the Best Optimal
Route

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]]

[[-0.66531144 -0.41475429 0.67180935]


[ 1.55031953 0.48136784 -0.45501854]
[ 0.83113345 0.14474465 0.79633509]
[-0.09509178 -0.11296479 -2.18403984]
[ 0.0552861 0.73816689 -0.50078059]]
epochs: 1 ======== acc: 15.9939590890258
epochs: 2 ======== acc: 14.569297979533
epochs: 3 ======== acc: 14.4434951431301
epochs: 4 ======== acc: 13.2880583115812
epochs: 5 ======== acc: 13.3813944863077
epochs: 6 ======== acc: 13.2759317265816
epochs: 7 ======== acc: 13.2442845026774
epochs: 8 ======== acc: 13.7724435699015
epochs: 9 ======== acc: 13.3254095094417
epochs: 10 ======== acc: 13.0121119551272
Figure 3 best Optimal Route

Figure 4 Show loss, error rate in the target output

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

Following the route is the Best Route for Traveling salesmen


Before Variation : [1, 3, 4, 2, 5, 9, 8, 6, 7, 0]
total time: 3290869066.9548187 s
After Genetic variation : [1, 3, 4, 2, 5, 9, 8, 6, 7, 0, 1] is best route

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).

You might also like