生成具有运算符列表的后继者

时间:2017-01-26 17:52:17

标签: lisp

该程序适用于2 operators并且还有更多,但我只是使用empty-aempty-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))))

此函数sucessorssucessors-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))))

有什么建议吗?

0 个答案:

没有答案