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