In Mathematics and Computer Science, a graph is a collection of vertexes connected by edges. Edges may be directed or undirected (i.e., sometimes you really can't get there from here). Both edges and vertexes may have additional data associated with them. Graphs are useful because you can use them to represent most anything: food webs, hypertext, the world wide web, protein/protein interactions, language, who publishes with whom, etc.
CL-Graph is a general graph library built on cl-containers. It provides an open-ended API for building, examining and manipulating graphs as well as implementations of many of the usual suspects of graph algorithms and measures.
Adds an edge between two vertexes and returns it. If force-new? is true, the edge is added even if one already exists. If the vertexes are not found in the graph, they will be added (unless :error-if-not-found? is true). The class of the edge can be specified using :edge-class or :edge-type. If :edge-type is used, it can be either :directed or :undirected; the actual class of the edge will be determined by using the edge-types of the graph. If neither :edge-type nor :edge-class is specified, then a directed edge will be created.
If-duplicate-do is used when the 'same' edge is added more than once. It can be either a function on one variable or :ignore or :force. If it is :ignore, then the previously added edge is returned; if it is :force, then another edge is added between the two vertexes; if it is a function, then this function will be called with the previous edge.
edge' from the
graph' and returns it.
old
in graph graph
with vertex new
. The edge structure of the graph is maintained.
edge
to the vertex vertex
.
Creates a new vertex for graph graph
. The keyword arguments include:
element
of the vertexand any other initialization arguments that make sense for the vertex class.
vertex
. Compare with the more flexible vertex-degree
.
graph
. [?? could be a defun]
vertex
(cf. neighbor-vertexes
). [?? could be a defun]
has-children-p
is testing only whether or not the vertex has any edges.
has-parent-p
is testing only whether or not the vertex has any edges.
vertex-1
.
vertex-2
.
edge
, this method returns the other vertex of edge
. If the value-or-vertex is not part of edge, then an error is signaled. [?? Should create a new condition for this]
weighted-edge-mixin
.
vertex
is a root vertex (i.e., it has no incoming (source) edges).
start-vertex
is in some cycle in graph
. This uses child-vertexes to generate the vertexes adjacent to a vertex.
graph
.
graph
for an edge whose vertexes match edge
. This means that vertex-1
of the edge in the graph must match vertex-1
of edge
and so forth. Wil signal an error of type graph-edge-not-found-error
unless error-if-not-found?
is nil. [?? Unused. Remove?]
graph
for an edge that connects vertex-1 and vertex-2. [?? Ignores error-if-not-found? Does directedness matter? need test]
thing
for which the predicate
function returns non-nil. If the key
is supplied, then it is applied to the vertex before the predicate is.
thing
for which the predicate
function returns non-nil. If the key
is supplied, then it is applied to the edge before the predicate is.
thing
for which the predicate
returns non-nil. [?? why no key function?]
thing
for which the predicate
returns non-nil. [?? why no key function?]
fn
. Unless error-if-not-found? is nil, then a error will be signaled. [?? IS error really signaled? need a test.]
graph
.
graph
where each sub-graph is a different connected component of graph. Compare with connected-components and connected-component-count.
vertex-classifier
is eq to vertex-class
and where an edge existing between two vertexes of the graph if and only if they are connected to a shared vertex in the existing-graph.
vertex
to level and then recursively sets the depth of all of the children of vertex
to (1+ level).
fn
on every child of node
.
fn
on each edge of graph or vertex.
fn
on each edge of a vertex that begins at vertex. In an undirected graph, this is equivalent to iterate-edges
.
fn
on each edge of a vertex that ends at vertex. In an undirected graph, this is equivalent to iterate-edges
.
vertex
. I.e., the edges that begin at vertex
.
vertex
. I.e., the edges that end at vertex
.
vertex
is connected by an edge and for which vertex
is the source vertex. If the connecting edge is undirected, then the vertex is always counted as a source. [?? Could be a defun].
vertex
is connected by an edge and for which vertex
is the target vertex. If the connecting edge is undirected, then the vertex is always counted as a target. [?? Could be a defun].
vertex
is connected by an edge disregarding edge direction. In a directed graph, neighbor-vertexes is the union of parent-vertexes and child-vertexes. [?? Could be a defun].
fn
on each of the vertexes of thing
.
thing
.
thing
.
Generates a description of graph
in DOT file format. The formatting can be altered using graph->dot-properties,
vertex->dot,
and edge->dot
as well as edge-formatter,
vertex-formatter,
vertex-labeler,
and edge-labeler
. These can be specified directly in the call to graph->dot
or by creating subclasses of basic-graph, basic-vertex and basic-edge.
The output can be a stream or pathname or one of the values nil
or t
. If output is nil
, then graph->dot returns a string containing the DOT description. If it is t
, then the DOT description is written to *standard-output*.
Here is an example;
(let ((g (make-container 'graph-container :default-edge-type :directed)))
(loop for (a b) in '((a b) (b c) (b d) (d e) (e f) (d f)) do
(add-edge-between-vertexes g a b))
(graph->dot g nil))
"digraph G {
E []
C []
B []
A []
D []
F []
E->F []
B->C []
B->D []
A->B []
D->E []
D->F []
}"
For more information about DOT file format, search the web for 'DOTTY' and 'GRAPHVIZ'.
vertex
onto the stream
. The function can assume that openning and closing square brackets and label have already been taken care of.
edge
onto the stream
. The function can assume that openning and closing square brackets and label have already been taken care of.
Requires cl-variants.
find-vertex
.
graph
that contains vertex
and all of the other vertexes that can be reached from vertex by paths of less than or equal of length depth
. If depth is not specified, then the entire sub-graph reachable from vertex will be returned. [?? Edge weights are always assumed to be one.]
Takes a GRAPH and a TEST-FN (a single argument function returning NIL or non-NIL), and filters the graph nodes according to the test-fn (those that return non-NIL are accepted), returning a new graph with only nodes corresponding to those in the original graph that satisfy the test (the nodes in the new graph are new, but their values and name point to the same contents of the original graph). There are four options for how the new graph is filled-out, depending on the following keywords passed to the optional GRAPH-COMPLETION-METHOD argument:
New graph has only nodes that correspond to those in the original graph that pass the test. NO LINKS are reproduced.
New graph has only nodes that pass, but reproduces corresponding links between passing nodes in the original graph.
New graph also includes nodes corresponding to the transitive closure(s) that include the passign nodes in the original graph. NO LINKS are reproduced.
Same as above, except corresponding links are reproduced.
For both transitive closure options, an additional optional argument, DEPTH, specifies how many links away from a source vertex to travel in gathering vertexes of the closure. E.g., a depth of 1 returns the source vertex and the parents and children of that vertex (all vertexes one link away from the source). The default value is NIL, indicating that all vertexes are to be included, no matter their depth. This value is ignored in non closure options.
tag
of all the edges of thing
to true. [?? why does this exist?]
tag
of all the edges of thing
to true. [?? why does this exist?]
tag
of all the edges of thing
to true. [?? why does this exist?]
tag
of all the edges of thing
to nil. [?? why does this exist?]