I am trying to implement Dijkstra’s algorithm on my python code but I can't really get the algorithm right. The algorithm I am using is from this youtube link: https://www.youtube.com/watch?v=pVfj6mxhdMw
So basically my class has these 3 variables:
self.nodes = [] #a,b,c
self.neighbours = {} # a:[b,c], b:[c], c:[a]
self.weights = {} #[a,b] = 2, [a,c] = 5
Here is how I partially implemented my shortest path function using the algorithm provided in the video:
def dijkstra(self, start, end):
nodes = {}
for n in self.nodes:
if n == start:
nodes[n] = 0
else:
nodes[n] = float('inf')
unvisited = self.neighbours
visited = []
current_node = start
current_distance = 0
while unvisited:
for n in unvisited[current_node]:
print(n)
#calc_weight = nodes[n] + self.weights[n, current_node]
#if (unvisited[n] is None or calc_weight > nodes[n]):
#nodes[n] = calc_weight
visited.append(current_node)
del unvisited[current_node]
if not unvisited: break
I havent really completed because I know I missing something out somewhere. Can someone please help me with this. Thank you