0
我有一个BFS的实现我得到了其他地方,并稍加修改,但我有其输入问题。
它需要一个图表,并将其视为'((abc)(bc)(cd)) 但我给它的输入是一个加权图...我知道这对BFS没有用,但是我稍后使用更靠后的权重。此输入看起来像
'(
(a (b 3) (c 1))
(b (a 3) (d 1))
(c (a 1) (d2) (e 2))
)
依此类推。LISP - 广度优先搜索
我的代码:
(defun shortest-path (start end net)
(BFS end (list (list start)) net))
(defun BFS (end queue net)
(if (null queue)
nil
(expand-queue end (car queue) (cdr queue) net)))
(defun expand-queue (end path queue net)
(let ((node (car path)))
(if (eql node end)
(reverse path)
(BFS end
(append queue
(new-paths path node net))
net))))
(defun new-paths (path node net)
(mapcar #'(lambda (n)
(cons n path))
(cdr (assoc node net))))
我只是不知道在哪里,我需要最有可能修改它以接受新的样式列表,或者做一个帮助功能,以正确的格式呢?
这工作完美。这有点超出了我的Lisp技能,所以非常感谢您的帮助。 – snivek 2011-04-11 19:08:46