Changed implementation of Dijkstra algorithm a little.
This commit is contained in:
parent
cab460feb8
commit
256e8b3908
@ -61,16 +61,18 @@ def dijkstra_algorithm(graph, start, goal, is_directed=False):
|
||||
else:
|
||||
new_dist = dist[current[1]] + graph[(current[1], neighbor)]
|
||||
if new_dist < dist[neighbor]:
|
||||
dist[neighbor] = new_dist
|
||||
for k in range(len(queue)):
|
||||
if queue[k][1] == neighbor:
|
||||
queue[k] = (new_dist, neighbor)
|
||||
heap.heapify(queue)
|
||||
prev[neighbor] = current[1]
|
||||
if dist[neighbor] == float('inf'):
|
||||
dist[neighbor] = new_dist
|
||||
prev[neighbor] = current[1]
|
||||
heap.heappush(queue, (new_dist, neighbor))
|
||||
else:
|
||||
dist[neighbor] = new_dist
|
||||
prev[neighbor] = current[1]
|
||||
for k in range(len(queue)):
|
||||
if queue[k][1] == neighbor:
|
||||
queue[k] = (new_dist, neighbor)
|
||||
heap.heapify(queue)
|
||||
|
||||
if not visited[neighbor]:
|
||||
visited[neighbor] = True
|
||||
heap.heappush(queue, (new_dist, neighbor))
|
||||
temp = goal
|
||||
shortest_path = [goal]
|
||||
while prev[temp] is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user