Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Statement Assume that you are given the responsibility to supply food, water, medicines and other amenities to the flooded areas in the city of

Problem Statement
Assume that you are given the responsibility to supply food, water, medicines and other amenities to the flooded areas in the city of Chennai. It is your responsibility to supply the needs to all the areas affected by flood where people are suffering. You are provided with a map of the city with flooded land-marks marked (vertices). You are provided with an autonomous battery-operated micro aquatic boat that detects the flooded areas and responds to people who wave to it for help. The autonomous battery-operated micro aquatic boat works on a battery and hence it has to take a path such that all the roads (edges in the graph) are covered, but no road is repeated more than once. After getting the details, the boat agent reports to you, the taken path and the locations where people are requesting for help.
The problem here is to find the shortest route that travels through all the lanes in the area. The places can be visited more than once. The shortest path includes all the roads travelled only once. Help your autonomous battery-operated micro aquatic boat in finding such a path given a starting point and the map.
Here the area map is represented as a graph. The algorithm takes the starting point and the graph as the input and produces the shortest path covering all the edges only once.
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)
}
For the heuristic, Consider the Manhattan distance heuristic. This heuristic calculates the distance between two points on a grid-like path by summing the absolute differences of their coordinates. In our case, each vertex represents a location in a grid-like environment, and the distance between them can be approximated by the Manhattan distance.
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')
Goal Test: The goal test is satisfied when the agent reaches the starting point after visiting all nodes in the graph, covering each edge only once.
Answer the Following:
1. Write working python code using 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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Climate And Environmental Database Systems

Authors: Michael Lautenschlager ,Manfred Reinke

1st Edition

1461368332, 978-1461368335

More Books

Students also viewed these Databases questions