Commits

Thomas Bartscher  committed 5a056c7

DEPTH-FIRST-SEARCH now returns a SEQ.
Bug in BREADTH-FIRST-SEARCH concerning the use of predicates squashed.

  • Participants
  • Parent commits e568b05
  • Branches dev

Comments (0)

Files changed (2)

File package.lisp

 	   #:standard-graph #:contract-edge #:subdivide-edge
 	   #:make-standard-graph #:add-nodes #:rem-nodes
 	   #:replace-ends #:make-edge #:add-edges #:contains-node?
-	   #:contains-edge?))
+	   #:contains-edge? #:expanded-neighbourhood))

File source/graph/graph.lisp

     (when (and (contains-node? graph source)
 	       (contains-node? graph target))
       (if (equal? source target)
-	  (list source)
+	  (seq source)
 	  (loop for n in (if predicate
 			     (convert 'list
 				      (sort (neighbours graph source)
 			     (convert 'list
 				      (neighbours graph source)))
 	     do (if (equal? n target)
-		    (return (list source target))
+		    (return (seq source target))
 		    (awhen (depth-first-search (rem-node graph source)
 					       n target predicate)
-		      (return (cons source it)))))))))
+		      (return (concat (seq source)
+				      it)))))))))
 
 (defgeneric breadth-first-search (graph source target &optional
 					predicate)
       (let ((paths (sort (image (lambda (n)
 				  (seq n))
 				(neighbours graph source))
-			 predicate))
+			 (lambda (a b)
+			   (funcall predicate (if (seq? a)
+						  (last a)
+						  a)
+				    (if (seq? b)
+					(last b)
+					b)))))
 	    (visited (set source)))
 	(if (equal? source target)
 	    (seq source)