b7f6e004d3a3feef4d69566e0af30bd7e44cc53d
[cl-graph.git] / dev / api.lisp
1 (in-package #:cl-graph)
2
3
4 (defgeneric make-vertex-container (graph initial-size)
5   (:documentation "Make-vertex-container is called during graph creation and can be used to create specialized containers to hold graph vertexes."))
6
7
8 (defgeneric make-edge-container (graph initial-size)
9   (:documentation "Make-edge-container is called during graph creation and can be used to create specialized containers to hold graph edges."))
10
11 ;;; API
12
13 (defgeneric make-graph (graph-type &key &allow-other-keys)
14   (:documentation "Create a new graph of type `graph-type'. Graph type can be 
15 a symbol naming a sub-class of basic-graph or a list. If it is a list of symbols naming
16 different classes. If graph-type is a list, then a class which has all of the listed 
17 classes as superclasses will be found (or created). In either case, the new graph will
18 be created as if with a call to make-instance."))
19
20
21 (defgeneric make-edge-for-graph (graph vertex-1 vertex-2 
22                                        &key edge-type edge-class &allow-other-keys)
23   (:documentation "It should not usually necessary to call this in user code. Creates a new edge between vertex-1 and vertex-2 for the graph. If the edge-type and edge-class are not specified, they will be determined from the defaults of the graph."))
24
25
26 (defgeneric add-edge (graph edge &rest args &key force-new?)
27   (:documentation "Add-edge adds an existing edge to a graph. As add-edge-between-vertexes is generally more natural to use, this method is rarely called."))
28
29
30 (defgeneric add-edge-between-vertexes (graph value-or-vertex-1 value-or-vertex-2
31                                               &rest args &key if-duplicate-do
32                                               edge-type &allow-other-keys)
33   (:documentation "Adds an edge between two vertexes and returns it.  
34 If force-new? is true, 
35 the edge is added even if one already exists. 
36 If the vertexes are not 
37 found in the graph, they will be added \(unless :error-if-not-found? is
38 true\). The class of the edge can be specified using :edge-class or
39 :edge-type. If :edge-type is used, it can be either :directed or 
40 :undirected; the actual class of the edge will be determined by using
41 the edge-types of the graph. If neither :edge-type nor :edge-class is
42 specified, then a directed edge will be created.
43
44 If-duplicate-do is used when the 'same' edge is added more than once. It can be
45 either a function on one variable or :ignore or :force. If it is :ignore, then
46 the previously added edge is returned; if it is :force, then another edge is
47 added between the two vertexes; if it is a function, then this function will
48 be called with the previous edge."))
49
50
51 (defgeneric delete-edge (graph edge)
52   (:documentation "Delete the `edge' from the `graph' and returns it."))
53
54
55 (defgeneric delete-edge-between-vertexes (graph value-or-vertex-1
56                                                 value-or-vertex-2 &rest args)
57   (:documentation "Finds an edge in the graph between the two specified vertexes. If values (i.e., non-vertexes) are passed in, then the graph will be searched for matching vertexes."))
58
59
60 (defgeneric add-vertex (graph value-or-vertex &key if-duplicate-do &allow-other-keys)
61   (:documentation  "Adds a vertex to a graph. If called with a vertex, then this vertex is added. If called with a value, then a new vertex is created to hold the value. If-duplicate-do can be one of :ignore, :force, :replace, :replace-value or a function. The default is :ignore."))
62
63
64 (defgeneric delete-vertex (graph value-or-vertex)
65   (:documentation "Remove a vertex from a graph. The 'vertex-or-value' argument can be
66 a vertex of the graph or a 'value' that will find a vertex via a call to find-vertex. A
67 graph-vertex-not-found-error will be raised if the vertex is not found or is not part of
68 the graph."))
69
70
71 (defgeneric find-vertex (graph value &optional error-if-not-found?)
72   (:documentation "Search 'graph' for a vertex with element 'value'. The search is fast but inflexible because it uses an associative-container. If you need more flexibity, see search-for-vertex."))
73
74
75 (defgeneric search-for-vertex (graph value &key key test error-if-not-found?)
76   (:documentation "Search 'graph' for a vertex with element 'value'. The 'key' function is applied to each element before that element is compared with the value. The comparison is done using the function 'test'. If you don't need to use key or test, then consider using find-vertex instead."))
77
78
79 (defgeneric find-edge (graph edge &optional error-if-not-found?)
80   (:documentation "Search `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?]"))
81
82
83 (defgeneric find-edge-between-vertexes (graph value-or-vertex-1 value-or-vertex-2
84                                               &key error-if-not-found?)
85   (:documentation "Searches `graph` for an edge that connects vertex-1 and vertex-2.  [?? Ignores error-if-not-found? Does directedness matter? need test]"))
86
87
88 (defgeneric source-vertex (edge)
89   (:documentation "Returns the source-vertex of a directed edge. Compare with `vertex-1`."))
90
91
92 (defgeneric target-vertex (edge)
93   (:documentation "Returns the target-vertex of a directed edge. Compare with `vertex-2`."))
94
95
96 (defgeneric iterate-edges (graph-or-vertex fn)
97   (:documentation "Calls `fn` on each edge of graph or vertex."))
98
99
100 (defgeneric iterate-source-edges (vertex fn)
101   (:documentation "In a directed graph, calls `fn` on each edge of a vertex that begins at vertex. In an undirected graph, this is equivalent to `iterate-edges`."))
102
103
104 (defgeneric iterate-target-edges (vertex fn)
105   (:documentation "In a directed graph, calls `fn` on each edge of a vertex that ends at vertex. In an undirected graph, this is equivalent to `iterate-edges`."))
106
107
108 (defgeneric iterate-children (vertex fn)
109   (:documentation "Calls fn on every vertex that is either connected to vertex by an undirected edge or is at the target end of a directed edge."))
110
111
112 (defgeneric has-children-p (vertex)
113   (:documentation "In a directed graph, returns true if vertex has any edges that point from vertex to some other vertex (cf. iterate-target-edges). In an undirected graph, `has-children-p` is testing only whether or not the vertex has any edges."))
114
115
116 (defgeneric has-parent-p (vertex)
117   (:documentation "In a directed graph, returns true if vertex has any edges that point from some other vertex to this vertex (cf. iterate-source-edges). In an undirected graph, `has-parent-p` is testing only whether or not the vertex has any edges."))
118
119
120 (defgeneric iterate-parents (vertex fn)
121   (:documentation "Calls fn on every vertex that is either connected to vertex by an undirected edge or is at the source end of a directed edge."))
122
123
124 (defgeneric iterate-neighbors (vertex fn)
125   (:documentation "Calls fn on every vertex adjecent to vertex See also iterate-children and iterate-parents."))
126
127
128 (defgeneric renumber-vertexes (graph)
129   (:documentation "Assign a number to each vertex in a graph in some unspecified order. [?? internal]"))
130
131
132 (defgeneric renumber-edges (graph)
133   (:documentation "Assign a number to each edge in a graph in some unspecified order. [?? internal]"))
134
135
136 (defgeneric generate-directed-free-tree (graph root)
137   (:documentation "Returns a version of graph which is a directed free tree
138 rooted at root."))
139
140
141 (defgeneric in-undirected-cycle-p (graph start-vertex &optional marked previous)
142   (:documentation "Return true if-and-only-if an undirected cycle in graph is reachable from start-vertex."))
143
144
145 (defgeneric undirected-edge-p (edge)
146   (:documentation "Returns true if-and-only-if edge is undirected"))
147
148
149 (defgeneric directed-edge-p (edge)
150   (:documentation "Returns true if-and-only-if edge is directed"))
151
152
153 (defgeneric tagged-edge-p (edge)
154   (:documentation "Returns true if-and-only-if edge's tag slot is t"))
155
156
157 (defgeneric untagged-edge-p (edge)
158   (:documentation "Returns true if-and-only-if edge's tage slot is nil"))
159           
160
161 (defgeneric adjacentp (graph vertex-1 vertex-2)
162   (:documentation "Return true if vertex-1 and vertex-2 are connected by an edge. [?? compare with vertices-share-edge-p and remove one or maybe call one directed-adjacentp]"))
163
164
165 (defgeneric make-filtered-graph (old-graph test-fn &key
166                                            graph-completion-method depth
167                                            new-graph)
168   (:documentation "Takes a GRAPH and a TEST-FN (a single argument function
169 returning NIL or non-NIL), and filters the graph nodes according to 
170 the test-fn (those that return non-NIL are accepted), returning 
171 a new graph with only nodes corresponding to those in the 
172 original graph that satisfy the test (the nodes in the new graph 
173 are new, but their values and name point to the same contents of 
174 the original graph).  There are four options for how the new 
175 graph is filled-out, depending on the following keywords passed 
176 to the optional GRAPH-COMPLETION-METHOD argument:
177
178 *  NIL (default)    
179
180      New graph has only nodes that correspond to those in
181        the original graph that pass the test.  NO LINKS are
182        reproduced.
183
184 *  :COMPLETE-LINKS  
185
186      New graph has only nodes that pass, but reproduces 
187        corresponding links between passing nodes in the
188        original graph.
189
190 *  :COMPLETE-CLOSURE-NODES-ONLY
191
192      New graph also includes nodes corresponding to the 
193        transitive closure(s) that include the passign nodes 
194        in the original graph.  NO LINKS are reproduced.
195
196 *  :COMPLETE-CLOSURE-WITH-LINKS
197
198      Same as above, except corresponding links are reproduced.
199
200 For both transitive closure options, an additional optional argument,
201 DEPTH, specifies how many links away from a source vertex to travel 
202 in gathering vertexes of the closure.  E.g., a depth of 1 returns the 
203 source vertex and the parents and children of that vertex (all vertexes
204 one link away from the source).  The default value is NIL, indicating
205 that all vertexes are to be included, no matter their depth.  This
206 value is ignored in non closure options."))
207
208
209 (defgeneric project-bipartite-graph  
210   (new-graph existing-graph vertex-class vertex-classifier)
211   (:documentation "Creates the unimodal bipartite projects of existing-graph with
212 vertexes for each vertex of existing graph whose `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."))
213
214
215 (defgeneric assortativity-coefficient (mixing-matrix)
216   (:documentation "An assortative graph is one where vertexes of the same type are more likely to 
217 have edges between them. The \(discrete\) assortativity-coefficient measures how
218 assortative a graph is based on its mixing matrix. The definition we use is from 
219 Mixing Patterns in Networks by Mark Newman. See the citation 'newman200-mixing' in moab 
220 or the URL 'http://arxiv.org/abs/cond-mat/0209450'."))
221
222
223 (defgeneric graph->dot (graph output
224                        &key 
225                        graph-formatter
226                        vertex-key
227                        vertex-labeler
228                        vertex-formatter
229                        edge-labeler 
230                        edge-formatter)
231   (:documentation 
232    "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. 
233
234 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*.
235
236 Here is an example;
237
238     (let ((g (make-container 'graph-container :default-edge-type :directed)))
239       (loop for (a b) in '((a b) (b c) (b d) (d e) (e f) (d f)) do
240             (add-edge-between-vertexes g a b))
241       (graph->dot g nil))
242
243     \"digraph G {
244     E []
245     C []
246     B []
247     A []
248     D []
249     F []
250     E->F []
251     B->C []
252     B->D []
253     A->B []
254     D->E []
255     D->F []
256     }\"
257
258 For more information about DOT file format, search the web for 'DOTTY' and 
259 'GRAPHVIZ'."))
260
261
262 (defgeneric graph->dot-properties (g stream)
263   (:documentation "Unless a different graph-formatter is specified, this method is called by graph->dot to output graph-properties onto a stream. The function can assume that the openning and closing brackets will be taken care of by the graph->dot."))
264
265
266 (defgeneric vertex->dot (vertex stream)
267   (:documentation "Unless a different vertex-formatter is specified with a keyword argument, this is used by graph->dot to output vertex formatting for `vertex` onto the `stream`. The function can assume that openning and closing square brackets and label have already been taken care of."))
268
269
270 (defgeneric edge->dot (edge stream)
271   (:documentation "Used by graph->dot to output edge formatting for `edge` onto the `stream`. The function can assume that openning and closing square brackets and label have already been taken care of."))
272
273
274 (defgeneric generate-gnm (generator graph n m &key)
275   (:documentation "Generate a 'classic' random graph G(n, m) with n vertexes and m edges."))
276
277
278 (defgeneric generate-gnp (generator graph n p &key)
279   (:documentation  "Generate the Erd\"os-R\'enyi random graph G\(n, p\). I.e., a graph with n vertexes where
280 each possible edge appears with probability p. This implementation is from Efficient Generation
281 of Large Random Networks \(see batagelj-generation-2005 in doab\)."))
282
283
284 (defgeneric generate-undirected-graph-via-assortativity-matrix 
285   (generator graph-class size edge-count kind-matrix assortativity-matrix
286              vertex-labeler &key)
287   (:documentation "This generates a random graph with 'size' vertexes. 
288 The vertexes can be in multiple different classes and the number of vertexes in each class is specified in the 'kind-matrix'. If the matrix has all fixnums, then it specifies the counts and these should add up to the size. If the kind-matrix contains non-fixnums then the values are treated as ratios.
289
290 The assortativity-matrix specifies the number of edges between vertexes of different kinds.
291
292 The vertex-labeler is a function of two parameters: the vertex kind and the index. It should return whatever the 'value' of the vertex ought to be."))
293
294
295 (defgeneric generate-undirected-graph-via-vertex-probabilities 
296   (generator graph-class size kind-matrix probability-matrix vertex-labeler)
297   (:documentation   "Generate an Erd\"os-R/'enyi like random graph having multiple vertex kinds. See the function
298 Gnp for the simple one vertex kind method.
299
300 Generator and graph-class specify the random number generator used and the class of the graph produced; Size
301 the number of vertexes. Kind matrix is a vector of ratios specifying the distribution of vertex kinds {0 ... \(1- k\)}.
302 The probability-matrix is a k x k matrix specifying the probability that two vertexes of the row-kind and the
303 column-kind will have an edge between them. vertex-labeler is a function of two arguments \(the kind and the vertex number\)
304 called to create values for vertexes. It will be called only once for each vertex created.
305
306 The clever sequential sampling technique in this implementation is from Efficient Generation
307 of Large Random Networks \(see batagelj-generation-2005 in moab\)."))
308
309
310 (defgeneric generate-scale-free-graph 
311   (generator graph size kind-matrix add-edge-count
312              other-vertex-kind-samplers vertex-labeler &key)
313   (:documentation "Generates a 'scale-free' graph using preferential attachment -- too damn slow.
314
315 Size is the number of vertexes; 
316 kind-matrix is as in generate-undirected-graph-via-assortativity-matrix, etc.;
317 add-edge-count is the number of edges to add for each vertex;
318 other-vertex-kind-samplers are confusing...; and
319 vertex-labeler is used to create vertex elements \(as in other generators\)."))
320
321
322 (defgeneric generate-assortative-graph-with-degree-distributions
323   (generator graph
324              edge-count assortativity-matrix
325              average-degrees
326              degree-distributions
327              vertex-labeler
328              &key)
329   (:documentation ""))
330
331
332 (defgeneric generate-simple-preferential-attachment-graph (generator graph size minimum-degree)
333   (:documentation "Generate a simple scale-free graph using the preferential attachment
334 mechanism of Barabasi and Albert. The implementation is from Efficient Generation
335 of Large Random Networks \(see batagelj-generation-2005 in moab\). Self-edges are possible."))
336
337
338 (defgeneric generate-preferential-attachment-graph 
339   (generator graph size kind-matrix minimum-degree 
340              assortativity-matrix 
341              &key)
342   (:documentation "Generate a Barabasi-Albert type scale free graph with multiple vertex kinds.
343
344 The idea behind this implementation is from Efficient Generation
345 of Large Random Networks \(see batagelj-generation-2005 in moab\)."))
346
347
348 ;;; more
349
350 (defgeneric make-vertex-for-graph (graph &key &allow-other-keys)
351   (:documentation "Creates a new vertex for graph `graph`. The keyword arguments include:
352
353 * vertex-class : specify the class of the vertex
354 * element      : specify the `element` of the vertex
355
356 and any other initialization arguments that make sense for the vertex class."))
357
358
359 (defgeneric tag-all-edges (thing)
360   (:documentation "Sets the `tag` of all the edges of `thing` to true. [?? why does this exist?\]"))
361
362
363 (defgeneric untag-all-edges (thing)
364   (:documentation "Sets the `tag` of all the edges of `thing` to nil.  [?? why does this exist?\]"))
365
366
367 (defgeneric untag-edges (edges)
368   (:documentation "Sets the `tag` of all the edges of `thing` to true. [?? why does this exist?\]"))
369
370
371 (defgeneric tag-edges (edges)
372   (:documentation "Sets the `tag` of all the edges of `thing` to true. [?? why does this exist?\]"))
373
374
375 (defgeneric replace-vertex (graph old new)
376   (:documentation "Replace vertex `old` in graph `graph` with vertex `new`. The edge structure of the graph is maintained."))
377
378
379 (defgeneric add-edge-to-vertex (edge vertex)
380   (:documentation "Attaches the edge `edge` to the vertex `vertex`."))
381
382
383 (defgeneric source-edges (vertex &optional filter)
384   (:documentation "Returns a list of the source edges of `vertex`. I.e., 
385 the edges that begin at `vertex`."))
386
387
388 (defgeneric target-edges (vertex &optional filter)
389   (:documentation "Returns a list of the target edges of `vertex`. 
390 I.e., the edges that end at `vertex`."))
391
392
393 (defgeneric child-vertexes (vertex &optional filter)
394   (:documentation "Returns a list of the vertexes to which `vertex` 
395 is connected by an edge and for which `vertex` is the source vertex. 
396 If the connecting edge is undirected, then the vertex is always 
397 counted as a source. [?? Could be a defun]."))
398
399
400 (defgeneric parent-vertexes (vertex &optional filter)
401   (:documentation "Returns a list of the vertexes to which `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]."))
402
403
404 (defgeneric neighbor-vertexes (vertex &optional filter)
405   (:documentation "Returns a list of the vertexes to which `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]."))
406
407
408 (defgeneric number-of-neighbors (vertex)
409   (:documentation "Returns the number of neighbors of `vertex` (cf. `neighbor-vertexes`). [?? could be a defun]"))
410
411
412 (defgeneric in-cycle-p (graph start-vertex)
413   (:documentation "Returns true if `start-vertex` is in some cycle in `graph`. This uses child-vertexes to generate the vertexes adjacent to a vertex."))
414
415
416 (defgeneric iterate-vertexes (thing fn)
417   (:documentation "Calls `fn` on each of the vertexes of `thing`."))
418
419
420 (defgeneric edges (thing)
421   (:documentation "Returns a list of the edges of `thing`."))
422
423
424 (defgeneric vertex-count (graph)
425   (:documentation "Returns the number of vertexes in `graph`. [?? could be a defun]"))
426
427
428 (defgeneric vertexes (thing)
429   (:documentation "Returns a list of the vertexes of `thing`."))
430
431
432 (defgeneric source-edge-count (vertex)
433   (:documentation "Returns the number of source edges of vertex (cf. source-edges). [?? could be a defun]"))
434
435
436 (defgeneric target-edge-count (vertex)
437   (:documentation "Returns the number of target edges of vertex (cf. target-edges). [?? could be a defun]"))
438
439
440 (defgeneric graph-roots (graph)
441   (:documentation "Returns a list of the roots of graph. A root is defined as a vertex with no source edges \(i.e., all of the edges are out-going\). (cf. rootp) [?? could be a defun]"))
442
443
444 (defgeneric rootp (vertex)
445   (:documentation "Returns true if `vertex` is a root vertex \(i.e., it has no incoming \(source\) edges\)."))
446
447
448 (defgeneric find-vertex-if (thing predicate &key key)
449   (:documentation "Returns the first vertex in `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."))
450
451
452 (defgeneric find-edge-if (graph fn &key key)
453   (:documentation "Returns the first edge in `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."))
454
455
456 (defgeneric find-edges-if (thing predicate)
457   (:documentation "Returns a list of edges in `thing` for which the `predicate` returns non-nil. [?? why no key function?]"))
458
459
460 (defgeneric find-vertexes-if (thing predicate)
461   (:documentation "Returns a list of vertexes in `thing` for which the `predicate` returns non-nil. [?? why no key function?]"))
462
463
464 (defgeneric force-undirected (graph)
465   (:documentation "Ensures that the graph is undirected (possibly by calling change-class on the edges)."))
466
467
468 (defgeneric traverse-elements (thing style fn)
469   (:documentation "WIP"))
470
471 (defgeneric traverse-elements-helper (thing style marker fn)
472   (:documentation "WIP"))
473
474 (defgeneric any-undirected-cycle-p (graph)
475   (:documentation "Returns true if there are any undirected cycles in `graph`."))
476
477 (defgeneric edge-count (vertex)
478   (:documentation "Returns the number of edges attached to `vertex`. Compare with the more flexible `vertex-degree`."))
479
480 (defgeneric topological-sort (graph)
481   (:documentation "Returns a list of vertexes sorted by the depth from the roots of the graph. See also assign-level and graph-roots."))
482
483 (defgeneric assign-level (vertex level)
484   (:documentation "Sets the depth of `vertex` to level and then recursively sets the depth of all of the children of `vertex` to \(1+ level\)."))
485
486 (defgeneric depth (graph)
487   (:documentation "Returns the maximum depth of the vertexes in graph assuming that the roots are of depth 0 and that each edge distance from the roots increments the depth by one."))
488
489 (defgeneric make-vertex-edges-container (vertex container-class &rest args)
490   (:documentation "Called during the initialization of a vertex to create the create the container used to store the edges incident to the vertex. The initarg :vertex-edges-container-class can be used to alter the default container class."))
491
492 (defgeneric other-vertex (edge value-or-vertex)
493   (:documentation "Assuming that the value-or-vertex corresponds to one of the vertexes for `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]"))
494
495 (defgeneric find-edge-between-vertexes-if 
496   (graph value-or-vertex-1 value-or-vertex-2 fn &key error-if-not-found?)
497   (:documentation "Finds and returns an edge between value-or-vertex-1 and value-or-vertex-2 if one exists. Unless error-if-not-found? is nil, then a error will be signaled. [?? Error not signal, need test.]"))
498
499 (defgeneric vertices-share-edge-p (vertex-1 vertex-2)
500   (:documentation "Return true if vertex-1 and vertex-2 are connected by an edge. [?? Compare adjacentp]"))
501
502 (defgeneric graph-edge-mixture-matrix (graph vertex-classifier &key edge-weight)
503   (:documentation "Return the `mixing-matrix` of graph based on the classifier and the edge-weight function. The mixing matrix is a matrix whose runs and columns represent each class of vertex in the graph. The entries of the matrix show the total number of edges between vertexes of the two kinds. [?? Edge-weight is not used; also compare with graph-mixture-matrix.]"))
504
505 (defgeneric graph-mixing-matrix (graph vertex-classifier &key edge-weight)
506   (:documentation "Return the `mixing-matrix` of graph based on the classifier and the edge-weight function. The mixing matrix is a matrix whose runs and columns represent each class of vertex in the graph. The entries of the matrix show the total number of edges between vertexes of the two kinds. [?? Edge-weight is not used; also compare with graph-edge-mixture-matrix.]"))
507
508 (defgeneric connected-components (graph)
509   (:documentation "Returns a union-find-container representing the connected-components of `graph`."))
510
511 (defgeneric connected-component-count (graph)
512   (:documentation "Returns the number of connected-components of graph."))
513
514 (defgeneric find-connected-components (graph)
515   (:documentation "Returns a list of sub-graphs of `graph` where each sub-graph is a different connected component of graph. Compare with connected-components and connected-component-count."))
516
517 (defgeneric initialize-vertex-data (graph)
518   (:documentation ""))
519
520 (defgeneric breadth-first-visitor (graph source fn)
521   (:documentation ""))
522
523 (defgeneric breadth-first-search-graph (graph source)
524   (:documentation ""))
525
526 (defgeneric mst-find-set (vertex)
527   (:documentation ""))
528
529 (defgeneric mst-make-set (vertex)
530   (:documentation ""))
531
532 (defgeneric mst-tree-union (v1 v2)
533   (:documentation ""))
534
535 (defgeneric mst-link (v1 v2)
536   (:documentation ""))
537
538 (defgeneric add-edges-to-graph (graph edges &key if-duplicate-do)
539   (:documentation ""))
540
541 (defgeneric make-graph-from-vertexes (vertex-list)
542   (:documentation "Create a new graph given a list of vertexes \(which are assumed to be from the same graph\). The new graph contains all of the vertexes in the list and all of the edges between any vertexes on the list."))
543
544 (defgeneric edge-lessp-by-weight (edge-1 edge-2)
545   (:documentation "Returns true if the weight of edge-1 is strictly less than the weight of edge-2."))
546
547 (defgeneric minimum-spanning-tree (graph &key edge-sorter)
548   (:documentation "Returns a minimum spanning tree of graph if one exists and nil otherwise."))
549
550 (defgeneric connected-graph-p (graph &key edge-sorter)
551   (:documentation "Returns true if graph is a connected graph and nil otherwise."))
552
553 (defgeneric edge-lessp-by-direction (edge-1 edge-2)
554   (:documentation "Returns true if and only if edge-1 is undirected and edge-2 is directed."))
555
556 (defgeneric out-edge-for-vertex-p (edge vertex)
557   (:documentation "Returns true if the edge is connected to vertex and is either an undirected edge or a directed edge for which vertex is the source vertex of the edge."))
558
559 (defgeneric dfs (graph root fn &key out-edge-sorter)
560   (:documentation ""))
561
562 (defgeneric dfs-visit (graph u fn sorter)
563   (:documentation ""))
564
565 (defgeneric dfs-tree-edge-p (edge)
566   (:documentation ""))
567
568 (defgeneric dfs-back-edge-p (edge)
569   (:documentation ""))
570
571 (defgeneric dfs-forward-edge-p (edge)
572   (:documentation ""))
573
574 (defgeneric dfs-cross-edge-p (edge)
575   (:documentation ""))
576
577 (defgeneric dfs-edge-type (edge)
578   (:documentation ""))
579
580 (defgeneric map-over-all-combinations-of-k-vertexes (graph k fn)
581   (:documentation ""))
582
583 (defgeneric map-over-all-combinations-of-k-edges (vertex k fn)
584   (:documentation ""))
585
586 (defgeneric complete-links (new-graph old-graph)
587   (:documentation "Add edges between vertexes in the new-graph for which the matching  vertexes in the old-graph have edges. The vertex matching is done using `find-vertex`."))
588
589 (defgeneric subgraph-containing (graph vertex &key)
590   (:documentation "Returns a new graph that is a subset of `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.]"))
591
592
593 (defgeneric weight (edge)
594   (:documentation "Returns the weight of an edge. This defaults to 1.0 and can only be altered if the edge is a sub-class of `weighted-edge-mixin`."))