Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.08 KB | None | 0 0
  1. (defun a* (problem)
  2.     (setf initialNode (make-node :state (problem-initial-state problem) :g 0 :h (funcall (problem-fn-h problem) (problem-initial-state problem)) :f (funcall (problem-fn-h problem) (problem-initial-state problem))))
  3.     (setf standbyNodeList nil)
  4.     (setf standbyPositionList nil)
  5.     (push initialNode standbyNodeList)
  6.     (push (state-pos (node-state initialNode)) standbyPositionList)
  7.     (setf visitedPositions nil)
  8.     (setf currentNode nil)
  9.     (loop
  10.         (if (null standbyNodeList)
  11.             (return-from a* nil)
  12.         )
  13.         (setf standbyNodeList (sort standbyNodeList #'fNodeCompare))
  14.         (setf currentNode (first standbyNodeList))
  15.        
  16.         (if (funcall (problem-fn-isGoal problem) (node-state currentNode))
  17.                 (return-from a* (objectivePath currentNode))
  18.         )
  19.         (push (state-pos (node-state currentNode)) visitedPositions)
  20.         (setf nextStatesList (funcall (problem-fn-nextStates problem) (node-state currentNode)))
  21.         (loop for x in nextStatesList do
  22.             (setf childNode (make-node :parent currentNode :state x :g (+ (node-g currentNode) (state-cost x)) :h (funcall (problem-fn-h problem) x)))
  23.             (setf (node-f childNode) (+ (node-g childNode) (node-h childNode)))
  24.             (if (not (isMemberList (state-pos (node-state childNode)) visitedPositions))
  25.                 (if (not (isMemberList (state-pos (node-state childNode)) standbyPositionList))
  26.                     (progn
  27.                         (push childNode standbyNodeList)
  28.                         (push (state-pos (node-state childNode)) standbyPositionList)
  29.                     )
  30.                     (if (isMemberList (state-pos (node-state childNode)) standbyPositionList)
  31.                         (if (> (node-f (nth (isMemberList (state-pos (node-state childNode)) standbyPositionList) standbyNodeList)) (node-f childNode))
  32.                             (progn
  33.                                 (setf standbyNodeList (remove-nth (isMemberList (state-pos (node-state childNode)) standbyPositionList) standbyNodeList))
  34.                                 (setf standbyPositionList (remove-nth (isMemberList (state-pos (node-state childNode)) standbyPositionList) standbyPositionList))
  35.                                 (push childNode standbyNodeList)
  36.                                 (push (state-pos (node-state childNode)) standbyPositionList)
  37.                             )
  38.                         )
  39.                     )
  40.                 )
  41.             )
  42.         )
  43.     )
  44. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement