23
23
'all_pair_shortest_paths' ,
24
24
'topological_sort' ,
25
25
'topological_sort_parallel' ,
26
- 'max_flow'
26
+ 'max_flow' ,
27
27
]
28
28
29
29
Stack = Queue = deque
@@ -851,20 +851,20 @@ def heuristic(node: str, goal: str) -> float:
851
851
dist = {v : float ('inf' ) for v in graph .vertices }
852
852
pred = {v : None for v in graph .vertices }
853
853
dist [source ] = 0
854
- # Priority queue using f-score (g_score + heuristic)
855
- pq = PriorityQueue (implementation = 'binomial_heap' )
856
- pq .push (source , heuristic (source , target ))
857
- while not pq .is_empty ():
854
+ from pydatastructs .miscellaneous_data_structures .queue import PriorityQueue , BinomialHeapPriorityQueue
855
+ pq = PriorityQueue (implementation = 'binomial_heap' )
856
+ f_score = heuristic (source , target )
857
+ pq .push (source , f_score )
858
+ while not pq .is_empty :
858
859
current = pq .pop ()
859
860
if current == target :
860
- print (f"Returning: { dist [target ]} , { pred } " )
861
861
return dist [target ], pred
862
862
if visited [current ]:
863
863
continue
864
- visited [current ] = True
864
+ visited [current ] = True
865
865
neighbors = graph .neighbors (current )
866
866
if not neighbors :
867
- continue
867
+ continue
868
868
for neighbor in neighbors :
869
869
if visited [neighbor .name ]:
870
870
continue
@@ -877,10 +877,8 @@ def heuristic(node: str, goal: str) -> float:
877
877
pred [neighbor .name ] = current
878
878
f_score = new_dist + heuristic (neighbor .name , target )
879
879
pq .push (neighbor .name , f_score )
880
- print (f"Returning: { float ('inf' )} , { pred } " )
881
880
return float ('inf' ), pred
882
881
_a_star_adjacency_matrix = _a_star_adjacency_list
883
-
884
882
def all_pair_shortest_paths (graph : Graph , algorithm : str ,
885
883
** kwargs ) -> tuple :
886
884
"""
0 commit comments