Last active
September 22, 2022 16:44
-
-
Save kartikkukreja/3eb7f38e026bd642f8b0 to your computer and use it in GitHub Desktop.
A* Graph Search Pseudocode
This file contains 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
def A*-GRAPH-SEARCH (start): | |
Let pq be an empty min priority queue | |
Let closed be an empty set | |
g(start) = 0 | |
f(start) = h(start) | |
path(start) = [] | |
pq.push(start, f(start)) | |
while not pq.empty(): | |
top = pq.pop() | |
if isGoal(top): | |
return f(top), path(top) | |
closed.add(top) | |
foreach next in succ(top): | |
if next not in closed: | |
g(next) = g(top) + cost(top, next) | |
f(next) = g(next) + h(next) | |
path(next) = path(top).append(next) | |
pq.push(next, f(next)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment