ubergraph.core
add-attr
(add-attr g node-or-edge k v)
(add-attr g n1 n2 k v)
Add an attribute to node or edge
add-attrs
(add-attrs g node-or-edge attribute-map)
(add-attrs g n1 n2 attribute-map)
Merges an attribute map with the existing attributes of a node or edge
add-directed-edges
(add-directed-edges g & edges)
Adds directed edges, regardless of whether the underlying graph is directed or undirected
add-directed-edges*
(add-directed-edges* g edges)
Adds directed edges regardless of the graph's undirected/directed default
add-edges
(add-edges g & edges)
Adds edges to graph g of the form [n1 n2], [n1 n2 weight], or [n1 n2 attr-map].
add-edges*
(add-edges* g edges)
Add edges to graph g. See add-edges
add-nodes
(add-nodes g & nodes)
Adds nodes to graph g. Nodes can be any type of object
add-nodes*
(add-nodes* g nodes)
Add nodes to graph g. See add-nodes
add-nodes-with-attrs
(add-nodes-with-attrs g & nodes-with-attrs)
Takes any number of [node attr-map] pairs, and adds them to graph g.
add-nodes-with-attrs*
(add-nodes-with-attrs* g nodes-with-attrs)
Takes a sequence of [node attr-map] pairs, and adds them to graph g.
add-undirected-edges
(add-undirected-edges g & edges)
Adds undirected edges, regardless of whether the underlying graph is directed or undirected
add-undirected-edges*
(add-undirected-edges* g edges)
Adds undirected edges regardless of the graph's undirected/directed default
allow-parallel-edges?
(allow-parallel-edges? g)
If true, two edges between the same pair of nodes in the same direction
are permitted. If false, adding a new edge between the same pair of nodes as an existing edge will
merge the edges into a single edge, and adding an undirected edge on top of an existing directed edge
will `upgrade' the directed edge to undirected and merge attributes.
attr
(attr g node-or-edge k)
(attr g n1 n2 k)
Return the attribute on a node or edge
attrs
(attrs g node-or-edge)
(attrs g n1 n2)
Return all attributes on a node or edge
build-graph
(build-graph g & inits)
Builds graphs using node descriptions of the form node-label or [node-label attribute-map]
and edge descriptions of the form [src dest], [src dest weight], or [src dest attribute-map].
Also can build from other ubergraphs and from adjacency maps.
Use ^:node and ^:edge metadata to resolve ambiguous inits, or build your graph with the more
precise add-nodes, add-nodes-with-attrs, and add-edges functions.
count-edges
(count-edges g)
Counts how many edges are in g.
Undirected edges are counted twice, once for each direction.
count-nodes
(count-nodes g)
Counts how many nodes are in g
count-unique-edges
(count-unique-edges g)
Counts how many edges are in g.
Undirected edges are counted only once.
dest
(dest edge)
Returns the dest node of the edge
digraph
(digraph & inits)
Digraph constructor. See build-graph for description of valid inits
directed-edge?
(directed-edge? e)
edge-description->edge
(edge-description->edge g ed)
Many ubergraph functions can take either an *edge description* (i.e., [src dest]
[src dest weight] or [src dest attribute-map]) or an actual edge object. This function
is used to convert edge descriptions into an edge object, or passing through an edge
object unchanged, so regardless of what you pass in, you're guaranteed to get out
an edge object.
edge-with-attrs
(edge-with-attrs g edge)
Returns [src dest attribute-map] with ^:edge metadata so it can be safely used as an input to build-graph
edge?
(edge? o)
Tests whether o is an edge object
edges
(edges g)
Edges in g. May return each edge twice in an undirected graph
edn->ubergraph
(edn->ubergraph {:keys [allow-parallel? undirected? nodes directed-edges undirected-edges]})
escape-label
(escape-label s)
Takes a string intended to be used as a node or edge label in a
Graphviz graph, and returns a string with several characters that
cause problems for Graphviz with suitable replacements. Called for
you automatically if you use the ':auto-label true' option of the
viz-graph function, but you may want to use it for label strings you
provide to viz-graph when you do not use that option.
find-edge
(find-edge g src dest)
(find-edge g query)
Returns first edge that matches the query
find-edges
(find-edges g src dest)
(find-edges g query)
Returns all edges that match the query
graph
(graph & inits)
Graph constructor. See build-graph for description of valid inits
has-edge?
(has-edge? g n1 n2)
Returns true when edge [n1 n2] is in g
has-node?
(has-node? g node)
Returns true when node is in g
in-degree
(in-degree g node)
Returns the number of direct predecessors to node
in-edges
(in-edges g node)
Returns all the incoming edges of node
mirror-edge?
(mirror-edge? e)
Is e the mirrored half of the undirected edge?
multidigraph
(multidigraph & inits)
Multidigraph constructor. See build-graph for description of valid inits
multigraph
(multigraph & inits)
Multigraph constructor. See build-graph for description of valid inits
neighbors
(neighbors g node)
Returns seq of nodes that are either successors or predecessors of the node
node-with-attrs
(node-with-attrs g node)
Returns [node attribute-map], which can be safely used as an input to build-graph
nodes
(nodes g)
Returns a collection of the nodes in graph g
other-direction
(other-direction g edge)
Returns the other direction of this edge in graph g
out-degree
(out-degree g node)
Returns the number of outgoing edges of node
out-edges
(out-edges g node)
Returns all the outgoing edges of node
pprint
(pprint g)
Pretty print an ubergraph
predecessors
(predecessors g)
(predecessors g node)
Returns direct predecessors of node
predecessors*
(predecessors* g node)
Returns direct predecessors of node
remove-all
(remove-all g)
Removes all nodes and edges from graph g
remove-attr
(remove-attr g node-or-edge k)
(remove-attr g n1 n2 k)
Remove an attribute from a node or edge
remove-attrs
(remove-attrs g node-or-edge attributes)
(remove-attrs g n1 n2 attributes)
Removes the attributes from the node or edge
remove-edges*
(remove-edges* g edges)
Removes edges from graph g. See remove-edges
remove-nodes
(remove-nodes g & nodes)
Removes nodes from graph g
remove-nodes*
(remove-nodes* g nodes)
Remove nodes from graph g. See remove-nodes
set-attrs
(set-attrs g node-or-edge attribute-map)
(set-attrs g n1 n2 attribute-map)
Sets the attribute map of a node or edge, overwriting existing attribute map
src
(src edge)
Returns the source node of the edge
successors
(successors g)
(successors g node)
Returns direct successors of node
successors*
(successors* g node)
Returns direct successors of node
transpose
(transpose g)
Returns a graph with all edges reversed
ubergraph
(ubergraph allow-parallel? undirected? & inits)
General ubergraph construtor. Takes booleans for allow-parallel? and undirected? to
call either graph, digraph, multigraph, or multidigraph.
See build-graph for description of valid inits
ubergraph->edn
(ubergraph->edn g)
undirected-edge?
(undirected-edge? e)
Is e one 'direction' of an undirected edge?
undirected-graph?
(undirected-graph? g)
If true, new edges in g are undirected by default. If false,
new edges in g are directed by default.
viz-graph
(viz-graph g)
(viz-graph g {layout :layout, {filename :filename, format :format, :as save} :save, auto-label :auto-label, :as opts, :or {layout :dot}})
Uses graphviz to generate a visualization of your graph. Graphviz
must be installed on your computer and in your path. Passes along
to graphviz the attributes on the nodes and edges, so graphviz-related
attributes such as color, style, label, etc. will be respected.
Takes an optional map which can contain:
:auto-label true (labels each node/edge with its attribute map)
:layout :dot, :neato, :fdp, :sfdp, :twopi, or :circo
:save {:filename _, :format _} where format is one of
:bmp :dot :eps :gif :ico :jpg :jpeg :pdf :png :ps :ps2 :svgz :tif :tiff :vmlz :wbmp
Additionally map can contain graph attributes for graphviz like :bgcolor, :label, :splines, ...
weight
(weight g)
(weight g e)
(weight g n1 n2)
Returns the weight of edge e or edge [n1 n2]
weight*
(weight* g e)
(weight* g n1 n2)
Returns the weight of edge e or edge [n1 n2]