SlideShare a Scribd company logo
1 of 17
GENETIC ALGORITHM
FOR
FINDING THE SHORTEST PATH
Dr. Baljit Singh Khehra
Professor, CSE Department
BBSB Engineering College, Fatehgarh Sahib
Introduction of Genetic Algorithms
• GA is a computer algorithm that searches for good
solutions to a problem among a large number of possible
solutions.
• GAs are based on the mechanism of natural genetics and
natural selection.
• In GAs, maintain a population of some feasible solutions
for given problem.This population undergoes evolution in
a form of natural selection. In each generation relatively
good solutions reproduce and relatively bad solutions die,
to be replaced by the offspring of the good.
Problem Description
•In TSP, to find shortest Hamiltonian cycle in
complete graph.
Permutation Problem.
NP-Hard Problem.
Fitness Measure
Step 1: Traverse the cities according to the sequence in a
tour
Step 2: Calculate d(ci, ci+1) using equation
d(ci, ci+1) = (x-s)2 + (y-t)2
and find the total distance in the tour
n
Total distance = S d (ci, ci+1) + d (cn,c1)
i=1
Step3: Calculate the fitness of the chromosome in the
population using the equation fit (tk) = 1/Total
distance
Selection Method
• Steady-state selection mechanism is used in this
algorithm.
• In steady-state selection, two chromosomes
from population are selected for crossover.
• The offspring so obtained replace the least fit
chromosome in the existing population.
Partially Mapped crossover
Step 1:Two chromosomes as parent P1 and P2 are
aligned, and two crossover sites are picked
uniformly at random along the chromosomes.
Step 2:Each element between the two crossover
points in the alternate parent is mapped to
the position held by this element in the
first parent.
Step3:The remaining elements are inherited from
the parent without any conflict.
Partially Mapped crossover
Step 4:If conflict occurs, then for the first child:
(a) Find the position of the element,where
conflict occurs, in the second parent.
Pick the element from that position in
the first parent and place it that position
where conflict occur in the first child.
(b) For the second child, parent roles
reversed.
Swap Mutation Operator
Step 1: Randomly choose one tour and randomly
select two mutation points.
Step 2: Interchange the cities at these two
points.
Overall Procedure of GA to Solve TSP
Step 1: Setting the parameter
Set the parameter: number of cities n, population
size pop_size, crossover probability pc, mutation
probability pm, and maximum generation maxgen.
Let generation gen = 0, maxeval = 0
Step 2: Initialization
Generate pop_size chromosomes (tours) randomly.
Overall Procedure of GA to Solve TSP
Step 3: Evaluate
Step 3.1: Calculate the fitness value of each chromosome .
Step 3.2: if maxeval < max{fit(tk)}
Then
bestsol = findbest {fit(tk)}
and maxeval = max {fit (tk)}
Overall Procedure of GA to Solve TSP
Step 4: Crossover
Perform the crossover PMX on
chromosomes selected with probability pc.
Step 5: Mutation
Perform the swap mutation on
chromosomes selected with probability pm.
Overall Procedure of GA to Solve TSP
Step 6: Selection
Select pop_size chromosomes from the parents
and offspring for the next generation by steady
state selection method.
Step 7: Stop testing
If gen = maxgen , then output bestsol and stop
Else
gen = gen + 1 and return to step 3
Experimental Results
The best tour after 2600 iterations
Problem Size GA
10
20
30
BEST AVG
56.47
58.81
64.15
45.36
52.89
55.91
Experimental Results
Performance of the Experiment
Performance of the experiment when n=20:
The size of the solution space:
20! / (20*2) = 60822550204416000
The number of the particles:18
The number of the iterations of the algorithm:2600
The size of the search space: 46800
Search space/solution space: 7.6945E-11%
Thanks

More Related Content

Similar to Ga for shortest_path

Genetic algorithms
Genetic algorithmsGenetic algorithms
Genetic algorithms
guest9938738
 
An Implementational approach to genetic algorithms for TSP
An Implementational approach to genetic algorithms for TSPAn Implementational approach to genetic algorithms for TSP
An Implementational approach to genetic algorithms for TSP
Sougata Das
 
Particle Swarm Optimization
Particle Swarm OptimizationParticle Swarm Optimization
Particle Swarm Optimization
Stelios Petrakis
 
Particle swarm optimization (PSO) ppt presentation
Particle swarm optimization (PSO) ppt presentationParticle swarm optimization (PSO) ppt presentation
Particle swarm optimization (PSO) ppt presentation
LatestShorts
 
Improving the accuracy of k-means algorithm using genetic algorithm
Improving the accuracy of k-means algorithm using genetic algorithmImproving the accuracy of k-means algorithm using genetic algorithm
Improving the accuracy of k-means algorithm using genetic algorithm
Kasun Ranga Wijeweera
 

Similar to Ga for shortest_path (20)

Genetic Algorithm
Genetic AlgorithmGenetic Algorithm
Genetic Algorithm
 
Quantum inspired evolutionary algorithm for solving multiple travelling sales...
Quantum inspired evolutionary algorithm for solving multiple travelling sales...Quantum inspired evolutionary algorithm for solving multiple travelling sales...
Quantum inspired evolutionary algorithm for solving multiple travelling sales...
 
Genetic Algorithm
Genetic AlgorithmGenetic Algorithm
Genetic Algorithm
 
Genetic algorithms
Genetic algorithmsGenetic algorithms
Genetic algorithms
 
An Implementational approach to genetic algorithms for TSP
An Implementational approach to genetic algorithms for TSPAn Implementational approach to genetic algorithms for TSP
An Implementational approach to genetic algorithms for TSP
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithm
 
BGA.pptx
BGA.pptxBGA.pptx
BGA.pptx
 
10.1.1.34.7361
10.1.1.34.736110.1.1.34.7361
10.1.1.34.7361
 
Genetic Algorithms
Genetic AlgorithmsGenetic Algorithms
Genetic Algorithms
 
D0353027043
D0353027043D0353027043
D0353027043
 
Pso notes
Pso notesPso notes
Pso notes
 
53564379-Ant-Colony-Optimization.ppt
53564379-Ant-Colony-Optimization.ppt53564379-Ant-Colony-Optimization.ppt
53564379-Ant-Colony-Optimization.ppt
 
F0422052058
F0422052058F0422052058
F0422052058
 
Optimization Using Evolutionary Computing Techniques
Optimization Using Evolutionary Computing Techniques Optimization Using Evolutionary Computing Techniques
Optimization Using Evolutionary Computing Techniques
 
Muzammil Adulrahman ppt on travelling salesman Problem Based On Mutation Gene...
Muzammil Adulrahman ppt on travelling salesman Problem Based On Mutation Gene...Muzammil Adulrahman ppt on travelling salesman Problem Based On Mutation Gene...
Muzammil Adulrahman ppt on travelling salesman Problem Based On Mutation Gene...
 
Particle Swarm Optimization
Particle Swarm OptimizationParticle Swarm Optimization
Particle Swarm Optimization
 
Advanced Optimization Techniques
Advanced Optimization TechniquesAdvanced Optimization Techniques
Advanced Optimization Techniques
 
Ga
GaGa
Ga
 
Particle swarm optimization (PSO) ppt presentation
Particle swarm optimization (PSO) ppt presentationParticle swarm optimization (PSO) ppt presentation
Particle swarm optimization (PSO) ppt presentation
 
Improving the accuracy of k-means algorithm using genetic algorithm
Improving the accuracy of k-means algorithm using genetic algorithmImproving the accuracy of k-means algorithm using genetic algorithm
Improving the accuracy of k-means algorithm using genetic algorithm
 

More from DrBaljitSinghKhehra (6)

Ann 3
Ann 3Ann 3
Ann 3
 
Deep learning
Deep learningDeep learning
Deep learning
 
Back propagation
Back propagation Back propagation
Back propagation
 
Artificial Neural Networks-Supervised Learning Models
Artificial Neural Networks-Supervised Learning ModelsArtificial Neural Networks-Supervised Learning Models
Artificial Neural Networks-Supervised Learning Models
 
Artificial Neural Networks-Supervised Learning Models
Artificial Neural Networks-Supervised Learning ModelsArtificial Neural Networks-Supervised Learning Models
Artificial Neural Networks-Supervised Learning Models
 
Artificial Neural Networks-Supervised Learning Models
Artificial Neural Networks-Supervised Learning ModelsArtificial Neural Networks-Supervised Learning Models
Artificial Neural Networks-Supervised Learning Models
 

Recently uploaded

Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
amilabibi1
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
David Celestin
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
Kayode Fayemi
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Hung Le
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
ZurliaSoop
 

Recently uploaded (17)

Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
 
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait Cityin kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
 
Zone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptxZone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptx
 
Introduction to Artificial intelligence.
Introduction to Artificial intelligence.Introduction to Artificial intelligence.
Introduction to Artificial intelligence.
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of Drupal
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 

Ga for shortest_path

  • 1. GENETIC ALGORITHM FOR FINDING THE SHORTEST PATH Dr. Baljit Singh Khehra Professor, CSE Department BBSB Engineering College, Fatehgarh Sahib
  • 2. Introduction of Genetic Algorithms • GA is a computer algorithm that searches for good solutions to a problem among a large number of possible solutions. • GAs are based on the mechanism of natural genetics and natural selection. • In GAs, maintain a population of some feasible solutions for given problem.This population undergoes evolution in a form of natural selection. In each generation relatively good solutions reproduce and relatively bad solutions die, to be replaced by the offspring of the good.
  • 3. Problem Description •In TSP, to find shortest Hamiltonian cycle in complete graph. Permutation Problem. NP-Hard Problem.
  • 4. Fitness Measure Step 1: Traverse the cities according to the sequence in a tour Step 2: Calculate d(ci, ci+1) using equation d(ci, ci+1) = (x-s)2 + (y-t)2 and find the total distance in the tour n Total distance = S d (ci, ci+1) + d (cn,c1) i=1 Step3: Calculate the fitness of the chromosome in the population using the equation fit (tk) = 1/Total distance
  • 5. Selection Method • Steady-state selection mechanism is used in this algorithm. • In steady-state selection, two chromosomes from population are selected for crossover. • The offspring so obtained replace the least fit chromosome in the existing population.
  • 6. Partially Mapped crossover Step 1:Two chromosomes as parent P1 and P2 are aligned, and two crossover sites are picked uniformly at random along the chromosomes. Step 2:Each element between the two crossover points in the alternate parent is mapped to the position held by this element in the first parent. Step3:The remaining elements are inherited from the parent without any conflict.
  • 7. Partially Mapped crossover Step 4:If conflict occurs, then for the first child: (a) Find the position of the element,where conflict occurs, in the second parent. Pick the element from that position in the first parent and place it that position where conflict occur in the first child. (b) For the second child, parent roles reversed.
  • 8. Swap Mutation Operator Step 1: Randomly choose one tour and randomly select two mutation points. Step 2: Interchange the cities at these two points.
  • 9. Overall Procedure of GA to Solve TSP Step 1: Setting the parameter Set the parameter: number of cities n, population size pop_size, crossover probability pc, mutation probability pm, and maximum generation maxgen. Let generation gen = 0, maxeval = 0 Step 2: Initialization Generate pop_size chromosomes (tours) randomly.
  • 10. Overall Procedure of GA to Solve TSP Step 3: Evaluate Step 3.1: Calculate the fitness value of each chromosome . Step 3.2: if maxeval < max{fit(tk)} Then bestsol = findbest {fit(tk)} and maxeval = max {fit (tk)}
  • 11. Overall Procedure of GA to Solve TSP Step 4: Crossover Perform the crossover PMX on chromosomes selected with probability pc. Step 5: Mutation Perform the swap mutation on chromosomes selected with probability pm.
  • 12. Overall Procedure of GA to Solve TSP Step 6: Selection Select pop_size chromosomes from the parents and offspring for the next generation by steady state selection method. Step 7: Stop testing If gen = maxgen , then output bestsol and stop Else gen = gen + 1 and return to step 3
  • 14. The best tour after 2600 iterations
  • 15. Problem Size GA 10 20 30 BEST AVG 56.47 58.81 64.15 45.36 52.89 55.91 Experimental Results
  • 16. Performance of the Experiment Performance of the experiment when n=20: The size of the solution space: 20! / (20*2) = 60822550204416000 The number of the particles:18 The number of the iterations of the algorithm:2600 The size of the search space: 46800 Search space/solution space: 7.6945E-11%