Liking cljdoc? Tell your friends :D

loom.alg

Graph algorithms. Any graph record/type that satisfies the Graph, Digraph, or WeightedGraph protocols (as appropriate per algorithm) can use these functions.

Graph algorithms. Any graph record/type that satisfies the
Graph, Digraph, or WeightedGraph protocols (as appropriate per algorithm)
can use these functions.
raw docstring

all-pairs-shortest-pathsclj/s

(all-pairs-shortest-paths g)

Finds all-pairs shortest paths in a graph. Uses Johnson's algorithm for weighted graphs which is efficient for sparse graphs. Breadth-first spans are used for unweighted graphs.

Finds all-pairs shortest paths in a graph. Uses Johnson's algorithm for weighted graphs
which is efficient for sparse graphs. Breadth-first spans are used for unweighted graphs.
sourceraw docstring

astar-distclj/s

(astar-dist g src target heur)

Returns the length of the shortest path between src and target using the A* algorithm

Returns the length of the shortest path between src and target using
the A* algorithm
sourceraw docstring

astar-pathclj/s

(astar-path g src target heur)
(astar-path g src target heur q explored)

Returns the shortest path using A* algorithm. Returns a map of predecessors.

Returns the shortest path using A* algorithm. Returns a map of predecessors.
sourceraw docstring

bellman-fordclj/s

(bellman-ford g start)

Given a weighted, directed graph G = (V, E) with source start, the Bellman-Ford algorithm produces map of single source shortest paths and their costs if no negative-weight cycle that is reachable from the source exists, and false otherwise, indicating that no solution exists.

Given a weighted, directed graph G = (V, E) with source start,
the Bellman-Ford algorithm produces map of single source shortest
paths and their costs if no negative-weight cycle that is reachable
from the source exists, and false otherwise, indicating that no
solution exists.
sourceraw docstring

bf-all-pairs-shortest-pathsclj/s

(bf-all-pairs-shortest-paths g)

Uses bf-span on each node in the graph.

Uses bf-span on each node in the graph.
sourceraw docstring

bf-pathclj/s

(bf-path g start end & opts)

Returns a path from start to end with the fewest hops (i.e. irrespective of edge weights)

Returns a path from start to end with the fewest hops (i.e. irrespective
of edge weights)
sourceraw docstring

bf-path-biclj/s

(bf-path-bi g start end)

Using a bidirectional breadth-first search, finds a path from start to end with the fewest hops (i.e. irrespective of edge weights). Can be much faster than a unidirectional search on certain types of graphs

Using a bidirectional breadth-first search, finds a path from start to
end with the fewest hops (i.e. irrespective of edge weights). Can be much
faster than a unidirectional search on certain types of graphs
sourceraw docstring

bf-spanclj/s

(bf-span g)
(bf-span g start)

Returns a breadth-first spanning tree of the form {node [successors]}

Returns a breadth-first spanning tree of the form {node [successors]}
sourceraw docstring

bf-traverseclj/s

(bf-traverse g)
(bf-traverse g start)
(bf-traverse g start & opts)

Traverses graph g breadth-first from start. When option :f is provided, returns a lazy seq of (f node predecessor-map depth) for each node traversed. Otherwise, returns a lazy seq of the nodes. When option :when is provided, filters successors with (f neighbor predecessor depth).

Traverses graph g breadth-first from start. When option :f is provided,
returns a lazy seq of (f node predecessor-map depth) for each node traversed.
Otherwise, returns a lazy seq of the nodes. When option :when is provided,
filters successors with (f neighbor predecessor depth).
sourceraw docstring

bipartite-colorclj/s

(bipartite-color g)

Attempts a two-coloring of graph g. When successful, returns a map of nodes to colors (1 or 0). Otherwise, returns nil.

Attempts a two-coloring of graph g. When successful, returns a map of
nodes to colors (1 or 0). Otherwise, returns nil.
sourceraw docstring

bipartite-setsclj/s

(bipartite-sets g)

Returns two sets of nodes, one for each color of the bipartite coloring, or nil if g is not bipartite

Returns two sets of nodes, one for each color of the bipartite coloring,
or nil if g is not bipartite
sourceraw docstring

bipartite?clj/s

(bipartite? g)

Returns true if g is bipartite

Returns true if g is bipartite
sourceraw docstring

coloring?clj/s

(coloring? g coloring)

Returns true if a map of nodes to colors is a proper coloring of a graph.

Returns true if a map of nodes to colors is a proper coloring of a graph.
sourceraw docstring

connectclj/s

(connect g)

Returns graph g with all connected components connected to each other

Returns graph g with all connected components connected to each other
sourceraw docstring

connected-componentsclj/s

(connected-components g)

Returns the connected components of graph g as a vector of vectors. If g is directed, returns the weakly-connected components.

Returns the connected components of graph g as a vector of vectors. If g
is directed, returns the weakly-connected components.
sourceraw docstring

connected?clj/s

(connected? g)

Returns true if g is connected

Returns true if g is connected
sourceraw docstring

dag?clj/s

(dag? g)

Returns true if g is a directed acyclic graph

Returns true if g is a directed acyclic graph
sourceraw docstring

degeneracy-orderingclj/s

(degeneracy-ordering g)

Returns sequence of vertices in degeneracy order.

Returns sequence of vertices in degeneracy order.
sourceraw docstring

densityclj/s

(density g & {:keys [loops] :or {loops false}})

Return the density of graph g

Return the density of graph g
sourceraw docstring

dijkstra-pathclj/s

(dijkstra-path g start end)

Finds the shortest path from start to end

Finds the shortest path from start to end
sourceraw docstring

dijkstra-path-distclj/s

(dijkstra-path-dist g start end)

Finds the shortest path from start to end. Returns a vector: [path distance]

Finds the shortest path from start to end. Returns a vector:
[path distance]
sourceraw docstring

dijkstra-spanclj/s

(dijkstra-span g)
(dijkstra-span g start)

Finds all shortest distances from start. Returns a map in the format {node {successor distance}}

Finds all shortest distances from start. Returns a map in the
format {node {successor distance}}
sourceraw docstring

dijkstra-traverseclj/s

(dijkstra-traverse g)
(dijkstra-traverse g start)
(dijkstra-traverse g start f)

Returns a lazy-seq of [current-node state] where state is a map in the format {node [distance predecessor]}. When f is provided, returns a lazy-seq of (f node state) for each node

Returns a lazy-seq of [current-node state] where state is a map in
the format {node [distance predecessor]}. When f is provided,
returns a lazy-seq of (f node state) for each node
sourceraw docstring

distinct-edgesclj/s

(distinct-edges g)

Returns the distinct edges of g. Only useful for undirected graphs

Returns the distinct edges of g. Only useful for undirected graphs
sourceraw docstring

eql?clj/s

(eql? g1 g2)

Returns true iff g1 is a subgraph of g2 and g2 is a subgraph of g1

Returns true iff g1 is a subgraph of g2 and g2 is a subgraph of g1
sourceraw docstring

greedy-coloringclj/s

(greedy-coloring g)

Greedily color the vertices of a graph using the first-fit heuristic. Returns a map of nodes to colors (0, 1, ...).

Greedily color the vertices of a graph using the first-fit heuristic.
Returns a map of nodes to colors (0, 1, ...).
sourceraw docstring

isomorphism?clj/s

(isomorphism? g1 g2 phi)

Given a mapping phi between the vertices of two graphs, determine if the mapping is an isomorphism, e.g., {(phi x), (phi y)} connected in g2 iff {x, y} are connected in g1.

Given a mapping phi between the vertices of two graphs, determine
if the mapping is an isomorphism, e.g., {(phi x), (phi y)} connected
in g2 iff {x, y} are connected in g1.
sourceraw docstring

johnsonclj/s

(johnson g)

Finds all-pairs shortest paths using Bellman-Ford to remove any negative edges before using Dijkstra's algorithm to find the shortest paths from each vertex to every other. This algorithm is efficient for sparse graphs.

If the graph is unweighted, a default weight of 1 will be used. Note that it is more efficient to use breadth-first spans for a graph with a uniform edge weight rather than Dijkstra's algorithm. Most callers should use shortest-paths and allow the most efficient implementation be selected for the graph.

Finds all-pairs shortest paths using Bellman-Ford to remove any negative edges before
using Dijkstra's algorithm to find the shortest paths from each vertex to every other.
This algorithm is efficient for sparse graphs.

If the graph is unweighted, a default weight of 1 will be used. Note that it is more efficient
to use breadth-first spans for a graph with a uniform edge weight rather than Dijkstra's algorithm.
Most callers should use shortest-paths and allow the most efficient implementation be selected
for the graph.
sourceraw docstring

lonersclj/s

(loners g)

Returns nodes with no connections to other nodes (i.e., isolated nodes)

Returns nodes with no connections to other nodes (i.e., isolated nodes)
sourceraw docstring

longest-shortest-pathclj/s

(longest-shortest-path g start)

Finds the longest shortest path beginning at start, using Dijkstra's algorithm if the graph is weighted, breadth-first search otherwise.

Finds the longest shortest path beginning at start, using Dijkstra's
algorithm if the graph is weighted, breadth-first search otherwise.
sourceraw docstring

max-flowclj/s

(max-flow g source sink & {:keys [method] :or {method :edmonds-karp}})

Returns [flow-map flow-value], where flow-map is a weighted adjacency map representing the maximum flow. The argument should be a weighted digraph, where the edge weights are flow capacities. Source and sink are the vertices representing the flow source and sink vertices. Optionally, pass in :method :algorithm to use. Currently, the only option is :edmonds-karp .

Returns [flow-map flow-value], where flow-map is a weighted adjacency map
representing the maximum flow.  The argument should be a weighted digraph,
where the edge weights are flow capacities.  Source and sink are the vertices
representing the flow source and sink vertices.  Optionally, pass in
  :method :algorithm to use.  Currently, the only option is :edmonds-karp .
sourceraw docstring

maximal-cliquesclj/s

(maximal-cliques g)

Enumerate the maximal cliques using Bron-Kerbosch.

Enumerate the maximal cliques using Bron-Kerbosch.
sourceraw docstring

post-traverseclj/s

(post-traverse g)
(post-traverse g start & opts)

Traverses graph g depth-first, post-order from start. Returns a vector of the nodes.

Traverses graph g depth-first, post-order from start. Returns a
vector of the nodes.
sourceraw docstring

pre-spanclj/s

(pre-span g)
(pre-span g start)

Returns a depth-first spanning tree of the form {node [successors]}

Returns a depth-first spanning tree of the form {node [successors]}
sourceraw docstring

pre-traverseclj/s

(pre-traverse g)
(pre-traverse g start)

Traverses graph g depth-first from start. Returns a lazy seq of nodes. When no starting node is provided, traverses the entire graph, connected or not.

Traverses graph g depth-first from start. Returns a lazy seq of nodes.
When no starting node is provided, traverses the entire graph, connected
or not.
sourceraw docstring

prim-mstclj/s

(prim-mst wg)

Minimum spanning tree of given graph. If the graph contains more than one component then returns a spanning forest of minimum spanning trees.

Minimum spanning tree of given graph. If the graph contains more than one
component then returns a spanning forest of minimum spanning trees.
sourceraw docstring

prim-mst-edgesclj/s

(prim-mst-edges wg)
(prim-mst-edges wg n h visited acc)

An edge-list of an minimum spanning tree along with weights that represents an MST of the given graph. Returns the MST edge-list for un-weighted graphs.

An edge-list of an minimum spanning tree along with weights that
represents an MST of the given graph. Returns the MST edge-list
for un-weighted graphs.
sourceraw docstring

sccclj/s

(scc g)

Returns the strongly-connected components of directed graph g as a vector of vectors. Uses Kosaraju's algorithm.

Returns the strongly-connected components of directed graph g as a vector of
vectors. Uses Kosaraju's algorithm.
sourceraw docstring

shortest-pathclj/s

(shortest-path g start end)

Finds the shortest path from start to end in graph g, using Dijkstra's algorithm if the graph is weighted, breadth-first search otherwise.

Finds the shortest path from start to end in graph g, using Dijkstra's
algorithm if the graph is weighted, breadth-first search otherwise.
sourceraw docstring

strongly-connected?clj/s

(strongly-connected? g)
source

subgraph?clj/s

(subgraph? g1 g2)

Returns true iff g1 is a subgraph of g2. An undirected graph is never considered as a subgraph of a directed graph and vice versa.

Returns true iff g1 is a subgraph of g2. An undirected graph is never
considered as a subgraph of a directed graph and vice versa.
sourceraw docstring

topsortclj/s

(topsort g)
(topsort g start)

Topological sort of a directed acyclic graph (DAG). Returns nil if g contains any cycles.

Topological sort of a directed acyclic graph (DAG). Returns nil if
g contains any cycles.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close