This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
def a_star(graph, start, goal, heuristic): | |
open_list = [(0, start)] # Priority queue with initial node | |
came_from = {} # Dictionary to store parent nodes | |
g_score = {node: float('inf') for node in graph} # Initialize g_score to infinity for all nodes | |
g_score[start] = 0 # Cost from start to start is 0 | |
while open_list: | |
_, current_node = heapq.heappop(open_list) # Pop node with lowest f_score |