dribbling to file "09-27-01" NIL CL-USER(2): (defun tree-search (goalp queue successors combiner) (cond ((endp queue) nil) (t (let ((firstpath (first queue))) (if (funcall goalp (first firstpath)) (reverse firstpath) ;;else (tree-search goalp (funcall combiner (rest queue) (funcall successors firstpath)) successors combiner)))))) TREE-SEARCH CL-USER(3): (defun pathproblem4 (start goal map) (tree-search #'(lambda (s) (eql s goal)) (list (list start)) #'(lambda (path) (mapcar #'(lambda (n) (cons n path)) (cdr (assoc (first path) map)))) ;; combiner #'(lambda (old new) (append old new))) PATHPROBLEM4 CL-USER(4): (defun pathproblem4 (start goal map) (tree-search ;; goalp #'(lambda (s) (eql s goal)) ;; initial queue (list (list start)) ;; successors #'(lambda (path) (mapcar #'(lambda (n) (cons n path)) (cdr (assoc (first path) map)))) ;; combiner #'(lambda (old new) (append old new)))) PATHPROBLEM4 CL-USER(5): (setf bigmap '((a b c d z) (b e f) (c g h) (d i j) (e k z))) ((A B C D Z) (B E F) (C G H) (D I J) (E K Z)) CL-USER(6): (pathproblem4 'a 'z bigmap) (A Z) CL-USER(7): (defstruct problem initial-queue queue goalp successors) PROBLEM CL-USER(8): (defun tree-search (p) (cond ((endp (problem-queue p)) nil) (t (let ((firstpath (first (problem-queue p)))) (if (funcall (problem-goalp p) (caar problem-queue p)) (reverse (first (problem-queue p))) ;;else (progn tree-search goalp (funcall combiner (rest queue) (funcall successors firstpath)) successors combiner)))))) TREE-SEARCH CL-USER(9): (defun tree-search (p) (cond ((endp (problem-queue p)) nil) (t (let ((firstpath (first (problem-queue p)))) (if (funcall (problem-goalp p) (first firstpath)) (reverse (firstpath)) ;;else (progn (setf (problem-queue p) (funcall (problem-combiner p) (rest queue) (funcall (problem-successors p) firstpath))) (tree-search p))))))) TREE-SEARCH CL-USER(10): (defstruct problem initial-queue queue goalp successors combiner) PROBLEM CL-USER(11): (defun pathproblem5 (start goal map) (tree-search (make-problem :goalp #'(lambda (s) (eql s goal)) :initial-queue (list (list start)) :successors #'(lambda (path) (mapcar #'(lambda (n) (cons n path)) (cdr (assoc (first path) map)))) :combiner #'(lambda (old new) (append old new))))) PATHPROBLEM5 CL-USER(12): (defun pathproblem5 (start goal map) (tree-search (make-problem :goalp #'(lambda (s) (eql s goal)) :queue (list (list start)) :successors #'(lambda (path) (mapcar #'(lambda (n) (cons n path)) (cdr (assoc (first path) map)))) :combiner #'(lambda (old new) (append old new))))) PATHPROBLEM5 CL-USER(13): (pathproblem5 'a 'z bigmap) Error: Attempt to take the value of the unbound variable `QUEUE'. [condition type: UNBOUND-VARIABLE] Restart actions (select using :continue): 0: Try evaluating QUEUE again. 1: Use :QUEUE instead. 2: Set the symbol-value of QUEUE and use its value. 3: Use a value without setting QUEUE. 4: Return to Top Level (an "abort" restart) 5: Abort # [1] CL-USER(14): :pop CL-USER(15): (defun tree-search (p) (cond ((endp (problem-queue p)) nil) (t (let ((firstpath (first (problem-queue p)))) (if (funcall (problem-goalp p) (first firstpath)) (reverse (firstpath)) ;;else (progn (setf (problem-queue p) (funcall (problem-combiner p) (rest (problem-queue p)) (funcall (problem-successors p) firstpath))) (tree-search p))))))) TREE-SEARCH CL-USER(16): (pathproblem5 'a 'z bigmap) Error: attempt to call `FIRSTPATH' which is an undefined function. [condition type: UNDEFINED-FUNCTION] Restart actions (select using :continue): 0: Try calling FIRSTPATH again. 1: Return a value instead of calling FIRSTPATH. 2: Try calling a function other than FIRSTPATH. 3: Setf the symbol-function of FIRSTPATH and call it again. 4: Return to Top Level (an "abort" restart) 5: Abort # [1] CL-USER(17): :pop CL-USER(18): (defun tree-search (p) (cond ((endp (problem-queue p)) nil) (t (let ((firstpath (first (problem-queue p)))) (if (funcall (problem-goalp p) (first firstpath)) (reverse (firstpath)) ;;else (progn (setf (problem-queue p) (funcall (problem-combiner p) (rest (problem-queue p)) (funcall (problem-successors p) firstpath))) (tree-search p))))))) TREE-SEARCH CL-USER(19): (pathproblem5 'a 'z bigmap) Error: attempt to call `FIRSTPATH' which is an undefined function. [condition type: UNDEFINED-FUNCTION] Restart actions (select using :continue): 0: Try calling FIRSTPATH again. 1: Return a value instead of calling FIRSTPATH. 2: Try calling a function other than FIRSTPATH. 3: Setf the symbol-function of FIRSTPATH and call it again. 4: Return to Top Level (an "abort" restart) 5: Abort # [1] CL-USER(20): :bt Evaluation stack: LET <- TREE-SEARCH <- LET <- TREE-SEARCH <- LET <- TREE-SEARCH <- LET <- TREE-SEARCH <- LET <- TREE-SEARCH <- PATHPROBLEM5 <- EVAL <- TPL:TOP-LEVEL-READ-EVAL-PRINT-LOOP <- TPL:START-INTERACTIVE-TOP-LEVEL [1] CL-USER(21): :reset CL-USER(22): (trace tree-search) (TREE-SEARCH) CL-USER(23): (pathproblem5 'a 'z bigmap) 0: (TREE-SEARCH #S(PROBLEM :INITIAL-QUEUE NIL :QUEUE ((A)) :GOALP # :SUCCESSORS # :COMBINER #)) 1: (TREE-SEARCH #S(PROBLEM :INITIAL-QUEUE NIL :QUEUE ((B A) (C A) (D A) (Z A)) :GOALP # :SUCCESSORS # :COMBINER #)) 2: (TREE-SEARCH #S(PROBLEM :INITIAL-QUEUE NIL :QUEUE ((C A) (D A) (Z A) (E B A) (F B A)) :GOALP # :SUCCESSORS # :COMBINER #)) 3: (TREE-SEARCH #S(PROBLEM :INITIAL-QUEUE NIL :QUEUE ((D A) (Z A) (E B A) (F B A) (G C A) (H C A)) :GOALP # :SUCCESSORS # :COMBINER #)) 4: (TREE-SEARCH #S(PROBLEM :INITIAL-QUEUE NIL :QUEUE ((Z A) (E B A) (F B A) (G C A) (H C A) (I D A) (J D A)) :GOALP # :SUCCESSORS # :COMBINER #)) Error: attempt to call `FIRSTPATH' which is an undefined function. [condition type: UNDEFINED-FUNCTION] Restart actions (select using :continue): 0: Try calling FIRSTPATH again. 1: Return a value instead of calling FIRSTPATH. 2: Try calling a function other than FIRSTPATH. 3: Setf the symbol-function of FIRSTPATH and call it again. 4: Return to Top Level (an "abort" restart) 5: Abort # [1] CL-USER(24): :reet Unknown top-level command: "reet" Type `:help' for the list of commands. [1] CL-USER(24): :reset 4: returned-by-throwing NIL 3: returned-by-throwing NIL 2: returned-by-throwing NIL 1: returned-by-throwing NIL 0: returned-by-throwing NIL CL-USER(25): (defun tree-search (p) (cond ((endp (problem-queue p)) nil) (t (let ((firstpath (first (problem-queue p)))) (if (funcall (problem-goalp p) (first firstpath)) (reverse firstpath) ;;else (progn (setf (problem-queue p) (funcall (problem-combiner p) (rest (problem-queue p)) (funcall (problem-successors p) firstpath))) (tree-search p))))))) TREE-SEARCH CL-USER(26): (pathproblem5 'a 'z bigmap) 0: (TREE-SEARCH #S(PROBLEM :INITIAL-QUEUE NIL :QUEUE ((A)) :GOALP # :SUCCESSORS # :COMBINER #)) 1: (TREE-SEARCH #S(PROBLEM :INITIAL-QUEUE NIL :QUEUE ((B A) (C A) (D A) (Z A)) :GOALP # :SUCCESSORS # :COMBINER #)) 2: (TREE-SEARCH #S(PROBLEM :INITIAL-QUEUE NIL :QUEUE ((C A) (D A) (Z A) (E B A) (F B A)) :GOALP # :SUCCESSORS # :COMBINER #)) 3: (TREE-SEARCH #S(PROBLEM :INITIAL-QUEUE NIL :QUEUE ((D A) (Z A) (E B A) (F B A) (G C A) (H C A)) :GOALP # :SUCCESSORS # :COMBINER #)) 4: (TREE-SEARCH #S(PROBLEM :INITIAL-QUEUE NIL :QUEUE ((Z A) (E B A) (F B A) (G C A) (H C A) (I D A) (J D A)) :GOALP # :SUCCESSORS # :COMBINER #)) 4: returned (A Z) 3: returned (A Z) 2: returned (A Z) 1: returned (A Z) 0: returned (A Z) (A Z) CL-USER(27): (untrace) NIL CL-USER(28): (pathproblem5 'a 'z bigmap) (A Z) CL-USER(29): (pathproblem5 'a 'e bigmap) (A B E) CL-USER(30): (pathproblem5 'a 'x bigmap) NIL CL-USER(31): (defun tree-search (p) (cond ((endp (problem-queue p)) nil) ((funcall (problem-goalp p) (caar (problem-queue p))) (reverse (car (problem-queue p)))) (t (setf (problem-queue p) (funcall (problem-combiner p) (rest (problem-queue p)) (funcall (problem-successors p) (first (problem-queue p))))) (tree-search p)))) TREE-SEARCH CL-USER(32): (pathproblem5 'a 'x bigmap) NIL CL-USER(33): (pathproblem5 'a 'e bigmap) (A B E) CL-USER(34): (pathproblem5 'a 'z bigmap) (A Z) CL-USER(35): (defun tree-search-depth-first (p) (cond ((endp (problem-queue p)) nil) ((funcall (problem-goalp p) (caar (problem-queue p))) (reverse (car (problem-queue p)))) (t (setf (problem-queue p) (append (funcall (problem-successors p) (first (problem-queue p))) (rest (problem-queue p)))) (tree-search p)))) TREE-SEARCH-DEPTH-FIRST CL-USER(36): (defstruct problem initial-queue queue goalp successors) PROBLEM CL-USER(37): (defun pathproblem5 (start goal map) (tree-search (make-problem :goalp #'(lambda (s) (eql s goal)) :queue (list (list start)) :successors #'(lambda (path) (mapcar #'(lambda (n) (cons n path)) (cdr (assoc (first path) map))))))) PATHPROBLEM5 CL-USER(38): (pathproblem5 'a 'z bigmap) Error: Index 5 out of bounds for structure #S(PROBLEM :INITIAL-QUEUE NIL :QUEUE ((A)) :GOALP # :SUCCESSORS #) [condition type: SIMPLE-ERROR] Restart actions (select using :continue): 0: Return to Top Level (an "abort" restart) 1: Abort # [1] CL-USER(39): :bt Evaluation stack: LET* <- TREE-SEARCH <- PATHPROBLEM5 <- EVAL <- TPL:TOP-LEVEL-READ-EVAL-PRINT-LOOP <- TPL:START-INTERACTIVE-TOP-LEVEL [1] CL-USER(40): :reset CL-USER(41): CL-USER(41): (defun pathproblem5 (start goal map) (tree-search-depth-first (make-problem :goalp #'(lambda (s) (eql s goal)) :queue (list (list start)) :successors #'(lambda (path) (mapcar #'(lambda (n) (cons n path)) (cdr (assoc (first path) map))))))) PATHPROBLEM5 CL-USER(42): (pathproblem5 'a 'z bigmap) Error: Index 5 out of bounds for structure #S(PROBLEM :INITIAL-QUEUE NIL :QUEUE ((B A) (C A) (D A) (Z A)) :GOALP # :SUCCESSORS #) [condition type: SIMPLE-ERROR] Restart actions (select using :continue): 0: Return to Top Level (an "abort" restart) 1: Abort # [1] CL-USER(43): :pop CL-USER(44): (defun tree-search-depth-first (p) (cond ((endp (problem-queue p)) nil) ((funcall (problem-goalp p) (caar (problem-queue p))) (reverse (car (problem-queue p)))) (t (setf (problem-queue p) (append (funcall (problem-successors p) (first (problem-queue p))) (rest (problem-queue p)))) (tree-search-depth-first p)))) TREE-SEARCH-DEPTH-FIRST CL-USER(45): (pathproblem5 'a 'z bigmap) (A B E Z) CL-USER(46): (defun tree-search-depth-first-limited (p limit) (cond ((endp (problem-queue p)) nil) ((funcall (problem-goalp p) (caar (problem-queue p))) (reverse (car (problem-queue p)))) ((= 0 limit) (setf (problem-queue p) (rest (problem-queue p))) (tree-search-depth-first-limited p 0)) (t (setf (problem-queue p) (append (funcall (problem-successors p) (first (problem-queue p))) (rest (problem-queue p)))) (tree-search-depth-first-limited p (- limit 1))))) TREE-SEARCH-DEPTH-FIRST-LIMITED CL-USER(47): (defun pathproblem6 (start goal map limit) (tree-search-depth-first-limited (make-problem :goalp #'(lambda (s) (eql s goal)) :queue (list (list start)) :successors #'(lambda (path) (mapcar #'(lambda (n) (cons n path)) (cdr (assoc (first path) map))))) limit)) PATHPROBLEM6 CL-USER(48): (pathproblem6 'a 'z bigmap 10) (A B E Z) CL-USER(49): (pathproblem6 'a 'z bigmap 3) (A B E Z) CL-USER(50): (pathproblem6 'a 'z bigmap 2) (A Z) CL-USER(51): (pathproblem6 'a 'z bigmap 1) (A Z) CL-USER(52): bigmap ((A B C D Z) (B E F) (C G H) (D I J) (E K Z)) CL-USER(53): (pathproblem6 'a 'k bigmap 1) NIL CL-USER(54): (pathproblem6 'a 'k bigmap 2) NIL CL-USER(55): (pathproblem6 'a 'k bigmap 3) (A B E K) CL-USER(56): (pathproblem6 'a 'k bigmap 4) (A B E K) CL-USER(57): (dribble)