(:documentation "Returns a path (if there is one) from SOURCE to

TARGET in GRAPH and NIL of there is none. The path is found via

- breadth first search."))

+ breadth first search.")

+ (:method ((graph graph)

+ source target &optional (predicate (constantly t)))

+ (when (and (contains-node? graph source)

+ (contains-node? graph target))

+ (let ((paths (sort (image (lambda (n)

+ (neighbours graph source))

+ (visited (set source)))

+ (if (equal? source target)

+ (return-from breadth-first-search

+ (let* ((path (lookup paths 0))

+ (if (equal? end target)

+ (return-from breadth-first-search

+ (concat (subseq paths 1)

+ (sort (set-difference (neighbours

+ visited (with visited end)))))))))))

(defgeneric normal-spanning-tree (graph root &optional predicate)

(:documentation "Returns a normal spanning tree of GRAPH with root