(defun new-nodes (path graph) (remove-if #'(lambda (n) (member n path)) (vertex-adjacency-list (first path) graph))) (defun new-paths (new-nodes path) (mapcar #'(lambda (n) (cons n path)) new-nodes))new-nodesはpathをもらってpathの先頭の頂点(現在探索中の頂点) の隣接点リストを取りだし,隣接点リストの各頂点のうちpathに すでに含まれているものを取り除きます.つまり,すでに通って来た 道にある頂点を除いた点のみを返します. new-pathsは,new-nodesとpathをもらって,新しいpathを 生成します.new-nodesに含まれる頂点の数だけの新しいpathの リストが返されます. vertex-adjacency-listは,
(defun vertex-adjacency-list (vertex graph) (if (listp graph) (case (car graph) (elist (vertex-adjacency-list-from-elist vertex (cadr graph))) (alist (cdr (assoc vertex (cdr graph)))) (plist (get vertex 'neighbors)) (hash (gethash vertex (cadr graph))) (amatrix (vertex-adjacency-list-from-amatrix vertex graph))) (if (graph-p graph) (mapcar #'vertex-name (vertex-alist (find vertex (graph-vlist graph) :key #'(lambda (x) (vertex-name x))))))))
(defun vertex-adjacency-list-from-elist (vertex edge-list &key (adjacency-list (list vertex))) (cond ((null edge-list) (remove vertex adjacency-list)) ((member vertex (car edge-list)) (vertex-adjacency-list-from-elist vertex (cdr edge-list) :adjacency-list (union (car edge-list) adjacency-list))) (t (vertex-adjacency-list-from-elist vertex (cdr edge-list) :adjacency-list adjacency-list)))) ;;; (defun amatrix-vlist (amatrix) (caddr amatrix)) (defun amatrix-matrix (amatrix) (cadr amatrix)) (defun vertex-adjacency-list-from-amatrix (vertex graph) (let* ((vlist (amatrix-vlist graph)) (amatrix (amatrix-matrix graph)) (index (position vertex vlist)) (len (length vlist)) (result nil)) (dotimes (i len) (if (aref amatrix index i) (push (elt vlist i) result))) result))