Travelling Salesman
Problem using Genetic
Algorithm
SHIKHA GUPTA
ASSISTANT PROFESSOR
ADVANCED EDUCATIONAL INSTITUTE
www.advanced.edu.in
Flow of lesson
1. Travelling Salesman problem
2. Problem
3. Genetic Algorithm
4. Solution of TSP Using Genetic Algorithm
5. Algorithm
6. Genetic Coding
7. Fitness Function
8. Selection Process
www.advanced.edu.in
9. Crossover Operator
10. Result
11. Conclusion
www.advanced.edu.in
Travelling Salesman problem (TSP)
It is an NP Complete Problem.
◦ Problems that can not be solved in polynomial time.
Given a list of cities and their pair wise distances, the mission is to find the shortest possible tour
that visits each city exactly once still keeping the new cost minimum.
www.advanced.edu.in
Problem
 Number of solutions is extremely large for even moderately large n.
 An exhaustive search is impracticable.
www.advanced.edu.in
Genetic Algorithm
• Search technique used to find approximate solutions to combinatorial optimization problems.
• Based on natural evolution.
• Include the survival of the fittest idea algorithm.
www.advanced.edu.in
The genetic algorithm process consists of
the following
Encoding: It is found for the solution to our problem so that each possible solution has unique
encoding in some form of a string.
Evaluation: The initial population is selected, at random. The fitness of each individual in the
population is then computed that is, how well the individual fits the problem.
Fitness: Used to find the individual’s probability of crossover.
Crossover: The two individuals are recombined to create new individuals which are copied into
the new generation.
www.advanced.edu.in
Mutation: Some individuals are chosen randomly to be mutated and then a mutation point is
randomly chosen to prevent all tours in the population from looking identical.
Decoding: A new generation has been formed and the process is repeated until some stopping
criteria has been reached. At this point the individuals which is closest to the optimum is
decoded and the process is complete.
www.advanced.edu.in
SOLUTION OF TSP USING
GENETIC ALGORITHM
•Create a group of many random tours in what is called a population.
• For initial population give preference to linking cities that are close to each other.
• Pick 2 of the better (shorter) tours parents in the population and combine them to make 2 new
child tours.
• The new child tours are inserted into the population replacing two of the longer tours. The size
of the population remains the same.
www.advanced.edu.in
STEPS OF ALGORITHMS
Step-1:Randomly create the initial population of individual string of the given TSP problem and
create a matrix representation of the cost of the path.
Step-2:Assign the fitness to each chromosome in the population using fitness criteria measure.
F(x) = 1/x
where,x represents the total cost of the string.
www.advanced.edu.in
Step-3: Create new off-spring population from two existing chromosomes in the parent
population by applying crossover operator.
Step-4:Mutate the resultant off-springs if required.
Step-5:Repeat step 3 and 4 until we get an optimal solution to the problem.
www.advanced.edu.in
Genetic coding
 Solution is represented by chromosome of length as the number of nodes in the problem.
 No node can appear twice in the same chromosome.
 There are mainly two representation methods for representing tour of the TSP –
 adjacency representation
 path representation.
www.advanced.edu.in
 We consider the path representation for a tour, which simply lists the label of nodes.
For example, let {1, 2, 3, 4, 5} be the labels of nodes in a 5 node instance, then a tour {1 3 4 2 5 1}
may be represented as (1, 3,4, 2, 5).
www.advanced.edu.in
Fitness function
 GAs are used for maximization problem.
 For the maximization problem the fitness function is same as the objective function. But, for
minimization problem, one way of defining a ‘fitness function’
F ( x ) = 1/ f ( x )
where f (x) is the objective function.
Since, TSP is a minimization problem; we consider this fitness function, where f(x) calculates cost
(or value) of the tour represented by a chromosome.
www.advanced.edu.in
Selection Process
 Chromosomes are copied into next generation with a probability associated with their fitness
value.
 Mimics the Darwin Theory survival-of-the-fittest in the natural world.
www.advanced.edu.in
Crossover Operator
 The search of the solution space is done by creating new chromosomes from old ones. The
most important search process is crossover.
 Types of crossover:-
 One Point Crossover
 11001011 + 11011111 = 11001111
 Two Point Crossover
 11001011 + 11011111 = 11011111
 Uniform Crossover
 11101011 + 11011011 = 11011111
 Cut and Splice
 11001011 + 11011111 = 1100011111
www.advanced.edu.in
The algorithm for this crossover technique is as follows:
Step 1.Start from the node p(the first node in parents P1 and P2 .
Step 2.Sequentially search both of the parent chromosomes and consider the first legitimate node
appeared after the node 1 in both P1 and P2 . Suppose the node x and node y are found in P1 and
P2 respectively. Consider the crossover point is selected after 2nd node in both parents P1 and P2 .
www.advanced.edu.in
Step 3..Now if Cpx < Cpy ,select node x ,otherwise node y as the next node and concatenate it to
the partially constructed offspring chromosome.
Step 4.Now if we select node x as the next string in partially constructed offspring chromosome,
copy the rest of the genes from parent P2,otherwise copy it from P1.
Step 5.Suppose a gene has already been copied into the off-spring then replace that gene by
unvisited gene.
www.advanced.edu.in
Result
 Crossover operator is capable of calculating an approximately optimal path for TSP using
genetic algorithm in less time.
 Only a single search for a crossover point and after that the child chromosome is developed
using the single point crossover technique only .
www.advanced.edu.in
Conclusion
 Genetic algorithm appear to find good solutions for the Travelling Salesman Problem.
 It depends very much on the way the problem is encoded and which crossover and mutation
methods are used.
 Better quality of solutions and cost as well as solution times.
www.advanced.edu.in
Shikha Gupta
Assistant Professor
Advanced Educational Institute
Advanced Educational Institutions,
70 km Milestone,
Delhi-Mathura Road, Dist. Palwal, Haryana-121105
+91–1275–398400, 302222
Shikha.0909@gmail.com
www.advance.edu.in
www.advanced.edu.in

Travelling Salesman Problem

  • 1.
    Travelling Salesman Problem usingGenetic Algorithm SHIKHA GUPTA ASSISTANT PROFESSOR ADVANCED EDUCATIONAL INSTITUTE www.advanced.edu.in
  • 2.
    Flow of lesson 1.Travelling Salesman problem 2. Problem 3. Genetic Algorithm 4. Solution of TSP Using Genetic Algorithm 5. Algorithm 6. Genetic Coding 7. Fitness Function 8. Selection Process www.advanced.edu.in
  • 3.
    9. Crossover Operator 10.Result 11. Conclusion www.advanced.edu.in
  • 4.
    Travelling Salesman problem(TSP) It is an NP Complete Problem. ◦ Problems that can not be solved in polynomial time. Given a list of cities and their pair wise distances, the mission is to find the shortest possible tour that visits each city exactly once still keeping the new cost minimum. www.advanced.edu.in
  • 5.
    Problem  Number ofsolutions is extremely large for even moderately large n.  An exhaustive search is impracticable. www.advanced.edu.in
  • 6.
    Genetic Algorithm • Searchtechnique used to find approximate solutions to combinatorial optimization problems. • Based on natural evolution. • Include the survival of the fittest idea algorithm. www.advanced.edu.in
  • 7.
    The genetic algorithmprocess consists of the following Encoding: It is found for the solution to our problem so that each possible solution has unique encoding in some form of a string. Evaluation: The initial population is selected, at random. The fitness of each individual in the population is then computed that is, how well the individual fits the problem. Fitness: Used to find the individual’s probability of crossover. Crossover: The two individuals are recombined to create new individuals which are copied into the new generation. www.advanced.edu.in
  • 8.
    Mutation: Some individualsare chosen randomly to be mutated and then a mutation point is randomly chosen to prevent all tours in the population from looking identical. Decoding: A new generation has been formed and the process is repeated until some stopping criteria has been reached. At this point the individuals which is closest to the optimum is decoded and the process is complete. www.advanced.edu.in
  • 9.
    SOLUTION OF TSPUSING GENETIC ALGORITHM •Create a group of many random tours in what is called a population. • For initial population give preference to linking cities that are close to each other. • Pick 2 of the better (shorter) tours parents in the population and combine them to make 2 new child tours. • The new child tours are inserted into the population replacing two of the longer tours. The size of the population remains the same. www.advanced.edu.in
  • 10.
    STEPS OF ALGORITHMS Step-1:Randomlycreate the initial population of individual string of the given TSP problem and create a matrix representation of the cost of the path. Step-2:Assign the fitness to each chromosome in the population using fitness criteria measure. F(x) = 1/x where,x represents the total cost of the string. www.advanced.edu.in
  • 11.
    Step-3: Create newoff-spring population from two existing chromosomes in the parent population by applying crossover operator. Step-4:Mutate the resultant off-springs if required. Step-5:Repeat step 3 and 4 until we get an optimal solution to the problem. www.advanced.edu.in
  • 12.
    Genetic coding  Solutionis represented by chromosome of length as the number of nodes in the problem.  No node can appear twice in the same chromosome.  There are mainly two representation methods for representing tour of the TSP –  adjacency representation  path representation. www.advanced.edu.in
  • 13.
     We considerthe path representation for a tour, which simply lists the label of nodes. For example, let {1, 2, 3, 4, 5} be the labels of nodes in a 5 node instance, then a tour {1 3 4 2 5 1} may be represented as (1, 3,4, 2, 5). www.advanced.edu.in
  • 14.
    Fitness function  GAsare used for maximization problem.  For the maximization problem the fitness function is same as the objective function. But, for minimization problem, one way of defining a ‘fitness function’ F ( x ) = 1/ f ( x ) where f (x) is the objective function. Since, TSP is a minimization problem; we consider this fitness function, where f(x) calculates cost (or value) of the tour represented by a chromosome. www.advanced.edu.in
  • 15.
    Selection Process  Chromosomesare copied into next generation with a probability associated with their fitness value.  Mimics the Darwin Theory survival-of-the-fittest in the natural world. www.advanced.edu.in
  • 16.
    Crossover Operator  Thesearch of the solution space is done by creating new chromosomes from old ones. The most important search process is crossover.  Types of crossover:-  One Point Crossover  11001011 + 11011111 = 11001111  Two Point Crossover  11001011 + 11011111 = 11011111  Uniform Crossover  11101011 + 11011011 = 11011111  Cut and Splice  11001011 + 11011111 = 1100011111 www.advanced.edu.in
  • 17.
    The algorithm forthis crossover technique is as follows: Step 1.Start from the node p(the first node in parents P1 and P2 . Step 2.Sequentially search both of the parent chromosomes and consider the first legitimate node appeared after the node 1 in both P1 and P2 . Suppose the node x and node y are found in P1 and P2 respectively. Consider the crossover point is selected after 2nd node in both parents P1 and P2 . www.advanced.edu.in
  • 18.
    Step 3..Now ifCpx < Cpy ,select node x ,otherwise node y as the next node and concatenate it to the partially constructed offspring chromosome. Step 4.Now if we select node x as the next string in partially constructed offspring chromosome, copy the rest of the genes from parent P2,otherwise copy it from P1. Step 5.Suppose a gene has already been copied into the off-spring then replace that gene by unvisited gene. www.advanced.edu.in
  • 19.
    Result  Crossover operatoris capable of calculating an approximately optimal path for TSP using genetic algorithm in less time.  Only a single search for a crossover point and after that the child chromosome is developed using the single point crossover technique only . www.advanced.edu.in
  • 20.
    Conclusion  Genetic algorithmappear to find good solutions for the Travelling Salesman Problem.  It depends very much on the way the problem is encoded and which crossover and mutation methods are used.  Better quality of solutions and cost as well as solution times. www.advanced.edu.in
  • 21.
    Shikha Gupta Assistant Professor AdvancedEducational Institute Advanced Educational Institutions, 70 km Milestone, Delhi-Mathura Road, Dist. Palwal, Haryana-121105 +91–1275–398400, 302222 Shikha.0909@gmail.com www.advance.edu.in www.advanced.edu.in