ASTAR(state)
OPEN (node(state, NIL, 0, h(state), h(state)))
While OPEN ≠ ( )
; Take the next node to process, mark it is
closed.
next pop(OPEN)
push (next, CLOSE)
; If we reached the target, print the way to it
and
; finish. We knows that it is the shortest way
we can find.
if
goalp(next.state) then return(trace(next))
; For each son s of the selected node
for s
in succ(next.state)
; Calculate the cost of s
new-cost next.g+cost(next.state, s)
; Check if we already found it earlier,
; and also we didn't pass it yet (Not in
close list)
old-node
find-state(s, OPEN)
if
old-node ≠ {} then
; OK, we found it earlier. Let check if we
found
; better path to that node. If yes, we need
to reenter
; it to the open list, according to its new
cost
if
old-node.g > new-cost then
old-node.g new-cost;
old-node.f
old-node.g+old-node.
old-node.parent next;
delete(old-node, OPEN);
; Reinsert old node according to new f
insert(old-node, OPEN, f)
end
; If the node is already in the closed list,
and also
; we find better cost for it, we should take
it
; back to the OPEN list
else
old-node find-state(s, CLOSE)
if
old-node ≠ {} then
if
old-node.g > new-cost then
old-node.g
new-cost; old-node.f old-node.g+old-node.
old-node.parent
next; delete(old-node, CLOSE);
insert(old-node,
OPEN, f)
end
; If we are here, it means that we just
reached that node
; in the first time. insert it to the OPEN
list as new node
else
insert(node(s, next, new-cost, h(s), h(s)+new-cost),
OPEN, f)
end;
end;
return
FAIL
אבל הוא עדיין לא נפתח...