! See http://factorcode.org/license.txt for BSD licence.
USING:help.markuphelp.syntax;
IN:graph-theory
ARTICLE: "graph-protocol""Graph protocol"
"All graphs must be instances of the graph mixin:"
{ $subsection graph }
"All graphs must implement a method on the following generic word:"
{ $subsection vertices }
"At least one of the following two generic words must have a method; the " { $link graph } " mixin has default definitions which are mutually recursive:"
{ $subsection adjlist }
{ $subsection adj? }
"All mutable graphs must implement a method on the following generic word:"
{ $subsection add-blank-vertex }
"All mutable undirected graphs must implement a method on the following generic word:"
{ $subsection add-edge }
"Mutable directed graphs should not implement the above word, as it has a default definition defined in terms of the following generic word:"
{ $subsection add-edge* }
"The following two words have default definitions, but are available as generics to allow implementations to optimize them:"
{ $subsection num-vertices }
{ $subsection num-edges } ;
HELP:graph
{ $class-description "A mixin class whose instances are graphs. Custom implementations of the graph protocol should be declared as instances of this mixin for all graph functionality to work correctly:"
{ "?list""A list of booleans describing the vertices visited in the search" }
{ "?""A boolean describing whether or not the end-search error was thrown" } }
{ $description "Performs a depth-first search on " { $emphasis "graph" } ". The variable " { $emphasis "graph" } " can be accessed in both quotations."
$nl
"The " { $emphasis "pre" } " quotation is run before the recursive application of depth-first."
$nl
"The " { $emphasis "post" } " quotation is run after the recursive application of depth-first."
$nl
{ $emphasis "?list" } " is a list of booleans, " { $link t } " for every vertex visted during the search, and " { $link f } " for every vertex not visited." } ;
HELP:full-depth-first
{ $values
{ "graph""The graph to search" }
{ "pre""A quotation of the form ( n -- )" }
{ "post""A quotation of the form ( n -- )" }
{ "tail""A quotation of the form ( -- )" }
{ "?""A boolean describing whether or not the end-search error was thrown" } }
{ $description "Performs a depth-first search on " { $emphasis "graph" } ". The variable " { $emphasis "graph" } "can be accessed in both quotations."
$nl
"The " { $emphasis "pre" } " quotation is run before the recursive application of depth-first."
$nl
"The " { $emphasis "post" } " quotation is run after the recursive application of depth-first."
$nl
"The " { $emphasis "tail" } " quotation is run after each time the depth-first search runs out of nodes. On an undirected graph this will be each connected subgroup but on a directed graph it can be more complex." } ;
HELP:dag?
{ $values
{ "graph" graph }
{ "?""A boolean indicating if the graph is acyclic" } }
{ $description "Using a depth-first search, determines if the specified directed graph is a directed acyclic graph. An undirected graph will produce a false result, as the algorithm does not eliminate cycles of length 2, which will include any edge that goes both ways." } ;
HELP:topological-sort
{ $values
{ "graph" graph }
{ "seq/f""Either a sequence of values or f" } }
{ $description "Using a depth-first search, topologically sorts the specified directed graph. Returns f if the graph contains any cycles, and a topologically sorted sequence otherwise." } ;