# HG changeset patch
# User Steve Losh Here's the list of changes in each released version. Added an explicit condition hierarchy. Fixed a bug where certain kinds of
+cycles were not correctly detected during topological sorting. Fixed a bug for recent SBCL versions
when creating a digraph without a custom hash function. Return the number of successors of A directed graph. Use Base condition for digraph-related errors. Insert an edge from The Returns The Call The order in which the vertices are processed is unspecified. Returns An error signaled when trying to insert an edge whose predecessor is not in the graph. An error signaled when trying to insert an edge whose successor is not in the graph. Base condition for errors signaled when inserting an edge with a vertex missing.Changelog
v1.4.0
+v1.3.2
+v1.3.1
vertex.DIGRAPH (class)make-digraph to create one.
+DIGRAPH-ERROR (class)EDGES (function)(EDGES DIGRAPH)
predecessor to successor if not already present.predecessor and successor vertices must exist in the graph already.t if the edge was already in the graph, or nil if it was
inserted.predecessor and successor vertices must already exist in the graph.
+ If predecessor is not in the graph a missing-predecessor error will be
+ signaled. Otherwise, if successor is not in the graph, a missing-successor
+ error will be signaled.INSERT-VERTEX (function)(INSERT-VERTEX DIGRAPH VERTEX)
function on each vertex in digraph.nil.
+MISSING-PREDECESSOR (class)vertex-involved can be used to retrieve the offending predecessor.
+MISSING-SUCCESSOR (class)vertex-involved can be used to retrieve the offending successor.
+MISSING-VERTEX (class)NEIGHBORS (function)(NEIGHBORS DIGRAPH VERTEX)
The order in which the vertices are processed is unspecified.
-An error will be signaled if the graph contains a cycle.
+A topological-sort-cycle error will be signaled if the graph contains
+ a cycle.
TOPOLOGICAL-SORT-CYCLE (class)An error signaled when topologically sorting a graph that contains a cycle.
+vertex-involved can be used to retrieve one of the vertices involved in a
+ cycle. Which vertex in the cycle is chosen is arbitrary.
VERTEX-INVOLVED (generic function)(VERTEX-INVOLVED CONDITION) +
Retrieve the vertex involved in the condition.
VERTICES (function)(VERTICES DIGRAPH)
Digraphs can be created with make-digraph:
(digraph:make-digraph) -; => -#<DIGRAPH:DIGRAPH () {1002CFD343}> +; => #<DIGRAPH:DIGRAPH () {1002CFD343}>
See the Conditions section for more information about the error +hierarchy.
Edges can be removed with remove-edge. Removing an edge that's not in the
graph is silently ignored:
(defparameter *d* @@ -335,12 +343,64 @@ (digraph:topological-sort *d*) ; => one of -(C B A D) -(B C A D) +; (C B A D) +; (B C A D) +
A digraph:topological-sort-cycle will be signaled if the digraph
+contains a cycle:
(defparameter *d* + (digraph:make-digraph :initial-vertices '(a b c d))) + +(digraph:insert-edge *d* 'a 'b) ; a depends on b +(digraph:insert-edge *d* 'b 'c) ; b depends on c +(digraph:insert-edge *d* 'c 'a) ; c depends on a + +(digraph:topological-sort *d*) +; => +; Cycle detected during topological sort involving vertex A +; [Condition of type DIGRAPH:TOPOLOGICAL-SORT-CYCLE] +; +; Restarts: +; R 0. ABORT - Exit debugger, returning to top level.
An error will be signaled if the digraph contains a cycle.
+See the Conditions section for more information about the error +hierarchy.
+The following condition types are defined by cl-digraph:
+ +Dotted outlines denote abstract types that are never actually instantiated, but +can be useful for handling whole classes of errors.
+digraph-error: abstract type for digraph-related errors.missing-vertex: abstract type for errors signaled when trying to insert an edge involving a vertex that is not in the graph.missing-predecessor: error signaled when trying to insert an edge whose predecessor is not in the graph.missing-successor: error signaled when trying to insert an edge whose successor is not in the graph.topological-sort-cycle: error signaled when trying to topologically sort a graph involving a cycle.For missing-vertex errors of both kinds you can use the vertex-involved
+reader to retrieve the offending vertex from the condition object.
For topological-sort-cycle errors you can use the vertex-involved reader to
+retrieve one of the vertices involved in a cycle from the condition object.
+Which vertex of the cycle is returned is arbitrary:
(defparameter *d* + (digraph:make-digraph :initial-vertices '(a b c d))) + +(digraph:insert-edge *d* 'a 'b) ; a depends on b +(digraph:insert-edge *d* 'b 'c) ; b depends on c +(digraph:insert-edge *d* 'c 'a) ; c depends on a + +(handler-case (digraph:topological-sort *d*) + (digraph:topological-sort-cycle-error (c) + (list :cyclic (digraph:vertex-involved c)))) +; => +; (:CYCLIC A) +
If you have Graphviz installed, you can draw digraph objects to images with
the cl-dot library by loading the optional cl-digraph.dot system: