fork(1) download
  1. ;;the function no - test
  2. (defun no-test()
  3. (list '(2 2) 0 nil))
  4.  
  5. ;; the function operators
  6. (defun operators()
  7. (list 'empty-a 'empty-b))
  8.  
  9. ;; the function create node
  10. (defun create-node (bucket &optional (g 0) (father nil))
  11. (list bucket g father))
  12.  
  13. ;; the function dfs
  14. (defun dfs (no sucessors)
  15. (list (append no (car sucessors))))
  16.  
  17. ;; the function bfs
  18. (defun bfs (no sucessors)
  19. (list (append (car sucessors) no)))
  20.  
  21. ;;operator empty-a
  22. (defun empty-a (state)
  23. (cond ((> (car state) 0)
  24. (list 0 (cadr state)))))
  25.  
  26. ;; operator empty-b
  27. (defun empty-b (state)
  28. (cond ((> (cadr state) 0)
  29. (list (car state) 0))))
  30.  
  31.  
  32.  
  33. ;; the function sucessors
  34. (defun sucessors (no operator algoritm depth)
  35. (cond
  36. ((equal algoritm 'bfs)
  37. (loop for x in operator
  38. do (sucessors-aux1 no x)))
  39. ((equal algoritm 'dfs)
  40. (loop for y in operator
  41. do (sucessors-aux1 no y)))
  42. (t (sucessors no operator algoritm depth))))
  43.  
  44.  
  45. ;; the function sucessors aux1
  46. (defun sucessors-aux1 (no operator)
  47. (print operator);; to show operator
  48. (cond
  49. ((create-node
  50. (funcall (symbol-function operator) (first no))
  51. (+ (second no) 1) no))
  52. (t (sucessors-aux1 no operator))))
  53.  
  54.  
  55. (print "--- Test Empty-A ---")
  56. (print (sucessors-aux1 (no-test) 'empty-a))
  57.  
  58. (terpri)
  59. (print "--- Test Empty-B ---")
  60. (print (sucessors-aux1 (no-test) 'empty-b))
  61.  
  62. (terpri)
  63. (print "--- Test All Operators ---")
  64. (sucessors (no-test) (operators) 'bfs nil)
  65. (sucessors (no-test) (operators) 'dfs 2)
  66.  
Success #stdin #stdout 0.01s 535040KB
stdin
1
2
10
42
11
stdout
"--- Test Empty-A ---" 
EMPTY-A 
((0 2) 1 ((2 2) 0 NIL)) 

"--- Test Empty-B ---" 
EMPTY-B 
((2 0) 1 ((2 2) 0 NIL)) 

"--- Test All Operators ---" 
EMPTY-A 
EMPTY-B 
EMPTY-A 
EMPTY-B