From beb0b76d1494ebd75b3d5c9d8de3e5dc865e303f Mon Sep 17 00:00:00 2001 From: Dobson Date: Tue, 20 Feb 2024 11:44:14 +0000 Subject: [PATCH] Test opposite and unindent in shortest path --- swmmanywhere/graph_utilities.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/swmmanywhere/graph_utilities.py b/swmmanywhere/graph_utilities.py index 40a4833f..a2809a1b 100644 --- a/swmmanywhere/graph_utilities.py +++ b/swmmanywhere/graph_utilities.py @@ -737,13 +737,15 @@ def __call__(self, G: nx.Graph, alt_dist = dist + edge_data['weight'] # If the alternative distance is shorter - if alt_dist < shortest_paths[neighbor]: - # Update the shortest path length - shortest_paths[neighbor] = alt_dist - # Update the path - paths[neighbor] = paths[node] + [neighbor] - # Push the neighbor to the heap - heappush(heap, (alt_dist, neighbor)) + if alt_dist >= shortest_paths[neighbor]: + continue + + # Update the shortest path length + shortest_paths[neighbor] = alt_dist + # Update the path + paths[neighbor] = paths[node] + [neighbor] + # Push the neighbor to the heap + heappush(heap, (alt_dist, neighbor)) edges_to_keep = set() for path in paths.values():