Assignment4
Assignment4
Instructions:
1. The assignment should be completed and uploaded by the deadline.
2. Please make a detailed report in PDF format for the assignment.
3. Markings will be based on the correctness and soundness of the outputs. Marks
will be deducted in case of plagiarism.
4. Proper indentation and appropriate comments are mandatory.
5. You should zip all the required files and name the zip file as:
roll_no_of_all_group_members.zip , eg. 2301cs11_2301cs03_2321cs05.zip.
6. Upload your assignment (the zip file) in the following link:
https://tinyurl.com/3mezt74k
For any queries regarding this assignment, you can contact:
Utsav Kumar ([email protected])
—------------------------------------------------------------------------------------------------------------------
Code Red: A Race Against Time
Scenario Overview
The year is 2042. In the city of NeoMetropolis, emergency medical services have deployed a
fleet of autonomous drones to deliver life-saving medicines and equipment to patients. These
drones navigate a network of city buildings and roads, represented as a graph, to find the optimal
delivery route.
Your task is to guide a medical drone from a hospital to a patient while minimizing travel time
and considering energy constraints.
City Map Representation
● Each node represents a location (e.g., a hospital, a patient’s house, or a relay station).
● Each edge represents a road connecting two locations.
● Each edge has:
○ Travel time (T) (in minutes)
○ Energy cost (E) (in battery units)
The drone starts from the hospital (H) and must reach the patient’s location (P) while minimizing
travel time and ensuring energy efficiency.
The city is represented as an adjacency matrix, where each row/column represents a location (H
denotes Hospital and P denotes Patient), and values represent travel time (T) and energy cost (E).
If T or E is -1 then you can’t directly reach there.
Your first mission is to implement Uniform Cost Search (UCS) to find the shortest path (least
time) from the hospital (H) to the patient’s location (P).
Input: First, take the number of locations N, then take N name of each location. Provide city
map representation in the N x N adjacency matrix.
Output:
● Print no. of explored cell and no of cell visited
● Track the drone at each time step.
○ Print drone location. print time elapsed and energy used till so far.
● If a path exists, output the fastest path from H to P..
○ "Path exists, Fastest path:"(e.g., [H → Location_1 → Location_2 → P]).
○ Print total time
○ Print total energy used
● If no path exists within the energy limit, return a failure message.
○ “Medical drone can’t reach you in time"
Sample Input:
N=5,
locations = ['H,' 'A,' 'B,' 'C,' 'P']
city_map = [
[(0, 0), (5, 10), (7, 12), (-1, -1), (-1, -1)], # H
[(5, 10), (0, 0), (8, 15), (5, 20), (11, 25)], # A
[(7, 12), (8, 15), (0, 0), (-1, -1), (10, 18)], # B
[(-1, -1), (5, 20), (-1, -1), (0, 0), (5, 8)], # C
[(-1, -1), (11, 25), (10, 18), (5, 8), (0, 0)] # P
]
Sample Output:
No of explored cells 5
No. of visited cells 4
****************************
Drone tracking:
Drone at H (Time: 0 mins, Energy: 0)
Drone at A (Time: 5 mins, Energy: 10)
Drone at C (Time: 10 mins, Energy: 30)
Drone at P (Time: 15 mins, Energy: 38)
*********************************
Path exists, Fastest path : H -> A -> C -> P
Total Travel Time: 15 minutes
Total Energy Used: 38 units
Input: First, take the number of locations N, then take N name of each location. Provide city
map representation in the N x N adjacency matrix.
Output:
● Print no. of explored cell and no of cell visited
● Track the drone at each time step.
○ Print drone location. print time elapsed and energy used till so far.
● If a path exists, output the fastest path from H to P..
○ "Path exists, Fastest path:"(e.g., [H → Location_1 → Location_2 → P]).
○ Print total time
○ Print total energy used
● If no path exists within the energy limit, return a failure message.
○ “Medical drone can’t reach you in time"
Sample Input:
N=5,
locations = ['H,' 'A,' 'B,' 'C,' 'P']
city_map = [
[(0, 0), (5, 10), (7, 12), (-1, -1), (-1, -1)], # H
[(5, 10), (0, 0), (8, 15), (5, 20), (11, 25)], # A
[(7, 12), (8, 15), (0, 0), (-1, -1), (10, 18)], # B
[(-1, -1), (5, 20), (-1, -1), (0, 0), (5, 8)], # C
[(-1, -1), (11, 25), (10, 18), (5, 8), (0, 0)] # P
]
Sample Output:
No of explored cells 5
No. of visited cells 3
****************************
Drone tracking:
Drone at H (Time: 0 mins, Energy: 0)
Drone at B (Time: 7 mins, Energy: 12)
Drone at P (Time: 17 mins, Energy: 30)
*********************************
Path exists, Fastest path : H -> B-> P
Total Travel Time: 17 minutes
Total Energy Used: 30 units
Input: First, take the number of locations N and battery capacity B, then take N name of each
location. Provide city map representation in the N x N adjacency matrix.
Output:
● Print no. of explored cell and no of cell visited
● Track the drone at each time step.
○ Print location. print time elapsed and energy used till so far.
● If a path exists, output the fastest path from H to P..
○ "Path exists, Fastest path:"(e.g., [H → Location_1 → Location_2 → P]).
○ Print total time
○ Print total energy used
● If no path exists within the energy limit, return a failure message.
○ “Medical drone can’t reach you in time"
Sample Input:
N=5, B = 36
locations = ['H,' 'A,' 'B,' 'C,' 'P']
city_map = [
[(0, 0), (5, 10), (7, 12), (-1, -1), (-1, -1)], # H
[(5, 10), (0, 0), (8, 15), (5, 20), (11, 25)], # A
[(7, 12), (8, 15), (0, 0), (-1, -1), (10, 18)], # B
[(-1, -1), (5, 20), (-1, -1), (0, 0), (5, 8)], # C
[(-1, -1), (11, 25), (10, 18), (5, 8), (0, 0)] # P
]
Sample Output:
No of explored cells 5
No. of visited cells 3
****************************
Drone tracking:
Drone at H (Time: 0 mins, Energy: 0)
Drone at A (Time: 5 mins, Energy: 10)
Drone at P (Time: 16 mins, Energy: 35)
*********************************
Path exists, Fastest path : H -> A-> P
Total Travel Time: 16 minutes
Total Energy Used: 35 units
● This part utilizes Part A and Part C. (we are looking for the shortest route, not for least
energy used path)
● Bad weather (rain, storms, strong winds) can increase travel time T and energy E uses on
certain paths. You need to write a function for weather change.
● Simulate random weather changes that affect some edges at each time step. Every edge
has a probability (PB) to be affected by weather change. There is severity_T and
severity_E. If the edge is affected by weather, then updated travel time T and energy use
E will be random value in range [T-severity_T , T+severity_T ] and
[E-severity_E,E+severity_E], respectively.
● Your algorithm should adapt dynamically to find the best alternative route.
● Finally, drone has to return to the Hospital.
Input: First, take the number of locations N and battery capacity B, probability (PB), severity_T
severity_E, then take N name of each location. Provide city map representation in the N x N
adjacency matrix.
Output:
● Print no. of explored cell and no of cell visited
● Track the drone at each time step.
○ Print adjacency matrix (city map) to visualize weather affect.
○ Print drone location. print time elapsed and energy used till so far.
● If a path exists, output the fastest path from H to P..
○ "Path exists, Fastest path:"(e.g., [H → Location_1 → Location_2 → P]).
○ Print total time
○ Print total energy used
● If no path exists within the energy limit, return a failure message.
○ “Medical drone can’t reach you in time. Drone reached at location: Location_1"
Sample Input:
N=5, B = 100, PB = 0.3, severity_T = 5, severity_E = 5
locations = ['H,' 'A,' 'B,' 'C,' 'P']
city_map = [
[(0, 0), (5, 10), (7, 12), (-1, -1), (-1, -1)], # H
[(5, 10), (0, 0), (8, 15), (5, 20), (11, 25)], # A
[(7, 12), (8, 15), (0, 0), (-1, -1), (10, 18)], # B
[(-1, -1), (5, 20), (-1, -1), (0, 0), (5, 8)], # C
[(-1, -1), (11, 25), (10, 18), (5, 8), (0, 0)] # P
]
Sample Output:
Output Format will be as previous part. Additionally you have to print adjacency matrix at each
time step and final drone location. Based on weather change function output will be
different for each run.
Question:
● First, solve part A and part B.(will be evaluated in today’s lab session).
● Solve parts C and D. (will be evaluated next week)
● Check the effect of factors(no of location, no of edges adjacency matrix, battery capacity,
weather change probability, severity_T , severity_TB). (show it by plotting graphs for
each case)
● (Bonus): Modify part D to such that it will provide you with the shortest path and least
energy-used path. (instead of Part A and Part C, you need to utilize Part A and Part B).