Question: Dijkstra's Algorithm to compute shortest path-- I can't figure out why my code doesn't work. Please help! This is my last assignment for this course.
Dijkstra's Algorithm to compute shortest path-- I can't figure out why my code doesn't work. Please help! This is my last assignment for this course. Please and Thank you!


![course. Please and Thank you!# your code here***q = PriorityQueue()source = graph.get_vertex_from_coords(source_coordinates[0],](https://dsd5zvtm8ll6.cloudfront.net/questions/2024/08/66b307ed336aa_1723009002720.jpg)
![source_coordinates[1])d = graph.get_vertex_from_coords(dest_coordinates[0], dest_coordinates[1])source.d = 0q.insert(source)while not q.is_empty():u = q.get_and_delete_min()u.processed = Trueif](https://dsd5zvtm8ll6.cloudfront.net/questions/2024/08/66b307ed3a41d_1723009002846.jpg)

![= graph.get_list_of_neighbors(u)[k][0]w = graph.get_list_of_neighbors(u)[k][1]if v.processed == False and v.d > (u.d +](https://dsd5zvtm8ll6.cloudfront.net/questions/2024/08/66b307ecb8165_1723009002029.jpg)

![d.y)]nextnode = dwhile nextnode != source:path.insert(0,(nextnode.pi.x, nextnode.pi.y))nextnode = nextnode.pireturn path, shortest_path_distance](https://dsd5zvtm8ll6.cloudfront.net/questions/2024/08/66b307ed2c460_1723009002578.jpg)



# your code here***
q = PriorityQueue()
source = graph.get_vertex_from_coords(source_coordinates[0], source_coordinates[1])
d = graph.get_vertex_from_coords(dest_coordinates[0], dest_coordinates[1])
source.d = 0
q.insert(source)
while not q.is_empty():
u = q.get_and_delete_min()
u.processed = True
if u.x == d.x and u.y == d.y:
shortest_path_distance = u.d
break
for k in range(len(graph.get_list_of_neighbors(u))):
v = graph.get_list_of_neighbors(u)[k][0]
w = graph.get_list_of_neighbors(u)[k][1]
if v.processed == False and v.d > (u.d + w):
v.d = u.d + w
v.pi = u
if v.idx_in_priority_queue == -1:
q.insert(v)
else:
q.update_vertex_weight(v)
path = [(d.x, d.y)]
nextnode = d
while nextnode != source:
path.insert(0,(nextnode.pi.x, nextnode.pi.y))
nextnode = nextnode.pi
return path, shortest_path_distance
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
