;;; Prof R. Williams Artificial Intelligence ;;; ;;; The following implements depth-limited depth-first search for a path ;;; from a given start state to any goal state in a graph. For simplicity, ;;; the only checking for repeated states is the avoidance of loops. (defun find-path-dldfs (start goal-test successors equal-states depth-limit) (check-node start goal-test nil successors equal-states depth-limit) ) (defun check-node (node goal-test path-so-far successors equal-states dl) (if (not (member node path-so-far :test equal-states)) (let ((path-so-far (cons node path-so-far))) (cond ((funcall goal-test node) path-so-far) ((zerop dl) nil) (t (check-nodes (funcall successors node) goal-test path-so-far successors equal-states dl)) )))) (defun check-nodes (nodes goal-test path-so-far successors equal-states dl) (unless (null nodes) (or (check-node (first nodes) goal-test path-so-far successors equal-states (1- dl)) (check-nodes (rest nodes) goal-test path-so-far successors equal-states dl)) ))