Question: Write working python code using local search Genetic Algorithm with following steps a . Population Initialisation, b . Fitness Selection using roulette s wheel, c

Write working python code using local search Genetic Algorithm with following steps
a. Population Initialisation,
b. Fitness Selection using roulettes wheel,
c. Cross over by single split or two split
d. Mutatation
Consider,
def manhattan_distance(point1, point2):
x1, y1= node_coordinates[point1]
x2, y2= node_coordinates[point2]
return abs(x1- x2)+ abs(y1- y2)
def generate_initial_population(graph, population_size):
initial_population =[]
for _ in range(population_size):
path = list(graph.keys())
random.shuffle(path)
initial_population.append(path)
return initial_population
def calculate_fitness(path):
total_distance = sum(manhattan_distance(path[i], path[i+1]) for i in range(len(path)-1))
return 1/ total_distance if total_distance >0 else float('inf')
From diagram, representation of different places using some short forms and graph using dictionary of them as follows:
pu: Purasawalkam
pe: Perumbakkam
v: Velachery
g: Guindy
t: Tambaram
n: Nungambakkam
graph ={
'pu': [('pe',8),('t',9)],
'pe': [('pu',8),('t',11),('v',6),('g',7)],
'v': [('g',14),('pe',6)],
'g': [('pe',7),('t',10),('n',12),('v',14)],
'n': [('g',12),('t',15)],
't': [('n',15),('g',10),('pe',11),('pu',9)]
}
node_coordinates ={
'pu': (0,0),
'pe': (1,1),
't': (2,2),
'v': (3,3),
'g': (4,4),
'n': (5,5)
}
 Write working python code using local search Genetic Algorithm with following

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!