@@ -99,7 +99,8 @@ def periodic_dijkstra(
99
99
min_val , (cur_idx , cur_image ) = heapq .heappop (pq )
100
100
if target_reached (cur_idx , cur_image ):
101
101
return best_ans
102
- best_ans [(cur_idx , cur_image )] = min_val
102
+ if min_val < best_ans [(cur_idx , cur_image )]:
103
+ best_ans [(cur_idx , cur_image )] = min_val
103
104
for next_node , keyed_data in conn_dict [cur_idx ].items ():
104
105
for k , d in keyed_data .items ():
105
106
# get the node index, image pair
@@ -112,10 +113,11 @@ def periodic_dijkstra(
112
113
new_cost = min_val + d [weight ]
113
114
114
115
if new_cost < best_ans [next_index_pair ]:
115
- best_ans [(next_node , new_image )] = new_cost
116
- path_parent [(next_node , new_image )] = (cur_idx , cur_image )
117
- heapq .heappush (pq , (new_cost , (next_node , new_image )))
118
- return best_ans , path_parent
116
+ best_ans [next_index_pair ] = new_cost
117
+ path_parent [next_index_pair ] = (cur_idx , cur_image )
118
+ heapq .heappush (pq , (new_cost , next_index_pair ))
119
+
120
+ # return best_ans, path_parent
119
121
120
122
121
123
def periodic_dijkstra_on_sgraph (
0 commit comments