Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def deikstra(start_node, finish_node, graph):
- distance = {str(i): float('inf') for i in range(1, len(graph) + 1)}
- visited = []
- current_node = start_node
- distance[str(current_node)] = 0
- while finish_node not in visited:
- visited.append(current_node)
- for arr in matrix[current_node]:
- n = arr[0]
- w = arr[1]
- if n in visited:
- continue
- if distance[str(current_node)] + w < distance[str(n)]:
- distance[str(n)] = distance[str(current_node)] + w
- minWeight = 19000000
- for i in range(1, length + 1):
- if (i not in visited) and (distance[str(i)] < minWeight):
- current_node = i
- minWeight = distance[str(i)]
- return distance[str(finish_node)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement