该程序适用于2 operators
并且还有更多,但我只是使用empty-a
和empty-b
来测试函数,当我使用单个运算符但是如果我使用了列表运算符返回nil
;;the function no-test
(defun no-test()
(list '(2 2) 0 nil))
;; the function operators
(defun operators()
(list 'empty-a 'empty-b))
;; the function create node
(defun create-node (bucket &optional (g 0) (father nil))
(list bucket g father))
;; the function dfs
(defun dfs (no sucessors)
(list (append no (car sucessors))))
;; the function bfs
(defun bfs (no sucessors)
(list (append (car sucessors) no)))
;;operator empty-a
(defun empty-a (state)
(cond
((> (car state) 0)
(list 0 (cadr state)))))
;; operator empty-b
(defun empty-b (state)
(cond
((> (cadr state) 0)
(list (car state) 0))))
这个生成successors-aux1
的函数非常适合单(sucessors-aux1 (no-test) 'empty-a)
或(sucessors-aux1 (no-test) 'empty-b)
和see test in Ideone.com
;; the function sucessors aux1
(defun sucessors-aux1 (no operator)
(print operator);; to show operator
(cond
((create-node
(funcall (symbol-function operator) (first no))
(+ (second no) 1) no))
(t (sucessors-aux1 no operator))))
此函数sucessors
与sucessors-aux1
不同,因为。{
sucessors
会收到list
或(sucessors (no-test) (operators) 'bfs nil)
等(sucessors (no-test) (operators) 'dfs 2)
个运营商,并应返回所有sucessors-aux1
但返回nil
see the test in Ideone.com
;; the function sucessors
(defun sucessors (no operator algoritm depth)
(cond
((equal algoritm 'bfs)
(loop for x in operator
do (sucessors-aux1 no x)))
((equal algoritm 'dfs)
(loop for y in operator
do (sucessors-aux1 no y)))
(t (sucessors no operator algoritm depth))))
有什么建议吗?