Name: Zayan Kashif
Roll number: L1S20BSCS0094
Task 2
Solve the TSP using GA and determine the third generation and assign any distance cost to
different routes of your choice.
Step-by-Step Solution:
1. Evaluate the fitness of each individual, showing all your workings, and arrange
them in order with the fittest first and the least fit last.
Let's assume we have the following routes and their distances:
Route Distance
Route A (1) 150
Route B (2) 170
Route C (3) 180
Route D (4) 200
Route E (5) 220
Route F (6) 240
Fitness Function: Fitness is the inverse of distance. So, fitness = 1 / distance.
Route Distance Fitness
Route A (1) 150 1 / 150 = 0.00667
Route B (2) 170 1 / 170 = 0.00588
Route C (3) 180 1 / 180 = 0.00556
Route D (4) 200 1 / 200 = 0.005
Route E (5) 220 1 / 220 = 0.00455
Route F (6) 240 1 / 240 = 0.00417
Arranged in order from fittest to least fit:
1. Route A (0.00667)
2. Route B (0.00588)
3. Route C (0.00556)
4. Route D (0.005)
5. Route E (0.00455)
6. Route F (0.00417)
Perform the following crossover operations:
a. One-point crossover at the middle point between the fittest two individuals.
Parents: Route A (1) and Route B (2)
Assume Route A: [A, B, C, D, E] Assume Route B: [E, D, C, B, A]
One-point crossover at the middle point:
Offspring O1: [A, B, C, B, A] Offspring O2: [E, D, C, D, E]
b. Two-point crossover between second and third fittest individuals.
Parents: Route B (2) and Route C (3)
Assume Route C: [C, D, E, A, B]
Two-point crossover:
Offspring O3: [E, D, E, A, B] Offspring O4: [C, D, C, B, A]
c. Uniform crossover between first and third fittest individuals.
Parents: Route A (1) and Route C (3)
Uniform crossover (randomly selecting genes from each parent):
Offspring O5: [A, D, E, D, E] Offspring O6: [C, B, C, A, B]
2. Suppose the new population consists of the six offspring individuals received by the
crossover operations in the above question. Evaluate the fitness of the new population,
showing all your workings. Has the overall fitness improved?
Offspring Route Distance (Assumed) Fitness
O1 [A, B, C, B, A] 160 1 / 160 = 0.00625
O2 [E, D, C, D, E] 190 1 / 190 = 0.00526
O3 [E, D, E, A, B] 210 1 / 210 = 0.00476
O4 [C, D, C, B, A] 170 1 / 170 = 0.00588
O5 [A, D, E, D, E] 180 1 / 180 = 0.00556
O6 [C, B, C, A, B] 200 1 / 200 = 0.005
Overall Fitness Improvement: Compare the average fitness of the original population with the
new population.
Original Population Average Fitness: (0.00667 + 0.00588 + 0.00556 + 0.005 + 0.00455 +
0.00417) / 6 = 0.005305
New Population Average Fitness: (0.00625 + 0.00526 + 0.00476 + 0.00588 + 0.00556 + 0.005)
/ 6 = 0.005452
The overall fitness has improved slightly from 0.005305 to 0.005452.
3. Find the chromosome representing the optimal solution and the value of the maximum
fitness.
By looking at the fitness function and considering that genes can only be digits between 0 and 9,
find the chromosome with the highest fitness.
From the new population:
The chromosome with the highest fitness is O1: [A, B, C, B, A] with a fitness of 0.00625.
Therefore, the optimal solution is [A, B, C, B, A] and the maximum fitness is 0.00625.