API
Every public item, package by package
Generated from the compiler's interface files and the comments beside each declaration, so nothing here is out of date with the code. Names in brass are the item itself; a signature is shown as the compiler sees it.
moongraph125 items
suberror Refused
Why a graph was refused.
fn Refused::at_offset( text : StringView, at : Int32, got : String, want : String, ) -> Refused
The refusal for a byte offset, with the line and column computed from the
text it points into. Parsers report positions in all three units because a
caller may be reading a file (line and column) or a byte stream (offset).
Refused::equal
Derived: whether two values of this type are the same, field by field.
Refused::not_equal
Derived: whether two values of this type differ.
Refused::to_repr
Derived: the debug view of a value, used when an assertion fails.
struct AllPairs
The result of an all-pairs search: a matrix of costs and a matrix of
successors.
fn AllPairs::path( self : AllPairs, from : Int32, to : Int32, ) -> Array[Int32]?
The cheapest route from
from to to, both included, or None when there
is none.fn AllPairs::reached(self : AllPairs, from : Int32, to : Int32) -> Bool
Whether
to is reachable from from.struct Cliques
A set of cliques.
struct Coloring
A colouring: a colour per node and how many colours were used.
struct Components
A labelling of nodes by component.
struct Condensation
The condensation of a directed graph: one node per strong component.
struct Cover
An edge cover: the edges that touch every node.
struct Csr[N, E]
A read-only snapshot of a graph in compressed adjacency form: one flat array
of neighbours per direction, with an offset per node.
impl[N, E] Topology for Csr[N, E] with fn directed(self)
impl[N, E] Topology for Csr[N, E] with fn edge_count(self)
fn[N, E] Csr::edge_data(self : Csr[N, E], edge : Int32) -> E
The payload of an edge.
impl[N, E] Topology for Csr[N, E] with fn endpoints(self, edge)
fn[N, E] Csr::from(graph : Graph[N, E]) -> Csr[N, E]
Builds the snapshot from a
Graph.fn[N, E] Csr::from_stable(graph : StableGraph[N, E]) -> Csr[N, E]
Builds the snapshot from a
StableGraph. Vacant numbers stay vacant: the
snapshot keeps the same node numbering, which is the point of the stable form.impl[N, E] Inbound for Csr[N, E] with fn in_incident(self, node)
impl[N, E] Inbound for Csr[N, E] with fn in_neighbors(self, node)
impl[N, E] Topology for Csr[N, E] with fn incident(self, node)
impl[N, E] Topology for Csr[N, E] with fn neighbors(self, node)
impl[N, E] Topology for Csr[N, E] with fn node_count(self)
fn[N, E] Csr::node_data(self : Csr[N, E], node : Int32) -> N
The payload of a node.
fn[N, E] Csr::to_graph(self : Csr[N, E]) -> Graph[N, E]
Back to a mutable graph carrying the same payloads and the same numbering.
fn[N, E] Csr::weights( self : Csr[N, E], of : (E) -> Double, ) -> (Int32) -> Double
A weight function over edge numbers, derived from one over payloads.
struct Cut
A cut: the value it separates, and which side each node falls on.
struct Flow
A feasible flow: its value and the flow on every edge.
struct Graph[N, E]
An adjacency-list graph: directed or undirected, parallel edges allowed, one
payload per node and one per edge.
fn[N, E] Graph::add_edge( self : Graph[N, E], from : Int32, to : Int32, data : E, ) -> Int32
Adds an edge from
from to to carrying data, and returns its number. In
an undirected graph the edge is reported from both endpoints.fn[N, E] Graph::add_node(self : Graph[N, E], data : N) -> Int32
Adds a node and returns its number.
fn[N, E] Graph::clear(self : Graph[N, E]) -> Unit
Removes every node and every edge.
fn[N, E] Graph::clear_edges(self : Graph[N, E]) -> Unit
Removes every edge, keeping the nodes.
fn[N, E] Graph::contains_edge(self : Graph[N, E], edge : Int32) -> Bool
Whether the edge exists and has not been removed.
fn[N, E] Graph::contains_node(self : Graph[N, E], node : Int32) -> Bool
Whether a node number is inside the graph.
fn[N, E] Graph::copy(self : Graph[N, E]) -> Graph[N, E]
An independent copy. Payloads are shared, because they are values the caller
owns; the structure is not.
impl[N, E] Topology for Csr[N, E] with fn directed(self)
impl[N, E] Topology for Csr[N, E] with fn edge_count(self)
fn[N, E] Graph::edge_data(self : Graph[N, E], edge : Int32) -> E
The payload of an edge.
fn[N, E] Graph::edges(self : Graph[N, E]) -> Iter[Int32]
Every live edge number, ascending.
impl[N, E] Topology for Csr[N, E] with fn endpoints(self, edge)
fn[N, E] Graph::find_edge( self : Graph[N, E], from : Int32, to : Int32, ) -> Int32?
The lowest-numbered edge from
from to to, or None when there is none. In
an undirected graph either direction counts.fn[N, E] Graph::find_edges( self : Graph[N, E], from : Int32, to : Int32, ) -> Array[Int32]
Every edge between the pair, in number order.
fn[N, E] Graph::from_edges( edges : Array[(Int32, Int32)], node~ : N, edge~ : E, directed~ : Bool = true, ) -> Graph[N, E]
A graph built from
(from, to) pairs, every node carrying node and every
edge edge. Nodes are created up to the highest number in the list.impl[N, E] Inbound for Csr[N, E] with fn in_incident(self, node)
impl[N, E] Inbound for Csr[N, E] with fn in_neighbors(self, node)
impl[N, E] Topology for Csr[N, E] with fn incident(self, node)
impl[N, E] Topology for Csr[N, E] with fn neighbors(self, node)
fn[N, E] Graph::new(directed~ : Bool = true) -> Graph[N, E]
An empty graph.
directed decides how every later edge is read; it cannot be
changed afterwards, because the adjacency is stored that way.impl[N, E] Topology for Csr[N, E] with fn node_count(self)
fn[N, E] Graph::node_data(self : Graph[N, E], node : Int32) -> N
The payload of a node. Reading a number outside the graph aborts, which is the
only place in this package that does: a payload has no neutral value to give.
fn[N, E] Graph::nodes(self : Graph[N, E]) -> Iter[Int32]
Every node number, ascending.
fn[N, E] Graph::remove_edge(self : Graph[N, E], edge : Int32) -> Unit
Removes an edge. Its number stays vacant, and the numbers of the other edges
do not change. A number outside the graph, or one already removed, is
ignored.
fn[N, E] Graph::remove_node(self : Graph[N, E], node : Int32) -> Unit
Removes a node and every edge on it, and renumbers the nodes after it down by
one so the numbering stays dense. A number outside the graph is ignored.
fn[N, E] Graph::set_edge_data( self : Graph[N, E], edge : Int32, data : E, ) -> Unit
Replaces an edge's payload.
fn[N, E] Graph::set_node_data( self : Graph[N, E], node : Int32, data : N, ) -> Unit
Replaces a node's payload.
fn[N, E] Graph::weights( self : Graph[N, E], of : (E) -> Double, ) -> (Int32) -> Double
A weight function over edge numbers, derived from one over payloads. Pass the
result as the
weight argument of an algorithm.fn[N, E] Graph::with_capacity( nodes? : Int32, edges? : Int32, directed~ : Bool = true, ) -> Graph[N, E]
An empty graph with room for the given counts, so that a build loop does not
reallocate. The counts are hints; exceeding them is not an error.
struct Keyed[K, N, E]
A graph addressed by keys instead of numbers: keys go in, keys come out, and
the numbers stay inside.
fn[K : Hash + Eq, N, E] Keyed::add_edge( self : Keyed[K, N, E], from : K, to : K, data : E, ) -> Int32 raise Refused
Adds an edge between two keys and returns its number. Either key missing is
refused, because an edge to a node that is not there has no number to use.
fn[K : Hash + Eq, N, E] Keyed::add_node( self : Keyed[K, N, E], key : K, data : N, ) -> Int32 raise Refused
Adds a node under a key and returns its number. A key that is already present
is refused rather than silently overwriting the node.
fn[K, N, E] Keyed::graph(self : Keyed[K, N, E]) -> Graph[N, E]
The wrapped graph, for an algorithm that works in numbers.
fn[K, N, E] Keyed::key(self : Keyed[K, N, E], node : Int32) -> K?
The key behind a number.
fn[K : Hash + Eq, N, E] Keyed::new(graph~ : Graph[N, E]) -> Keyed[K, N, E]
Wraps a graph. The wrapper takes ownership of the numbering from here on: add
nodes and edges through it so the two views cannot drift.
fn[K : Hash + Eq, N, E] Keyed::node( self : Keyed[K, N, E], key : K, ) -> Int32?
The number behind a key.
fn[K : Hash + Eq, N, E] Keyed::path( self : Keyed[K, N, E], paths : Paths, key : K, ) -> Array[K]?
The route to a key, as keys.
None when the node was not reached.fn[K : Hash + Eq, N, E] Keyed::scores( self : Keyed[K, N, E], scores : Scores, ) -> Map[K, Double]
A score per key, for a caller that thinks in keys.
struct Mapping
A node-to-node map between two graphs.
struct Matching
A matching: pairs of nodes and the weight those pairs add up to.
struct Matrix[E]
A dense V by V grid of cells, one edge payload per cell.
impl[N, E] Topology for Csr[N, E] with fn directed(self)
impl[N, E] Topology for Csr[N, E] with fn edge_count(self)
fn[E] Matrix::edges(self : Matrix[E]) -> Array[(Int32, Int32)]
Every edge of the matrix, as
(from, to) pairs in cell order.impl[N, E] Topology for Csr[N, E] with fn endpoints(self, edge)
fn[E] Matrix::get(self : Matrix[E], from : Int32, to : Int32) -> E?
The payload of a cell, or
None when it is empty or the coordinates are
outside the matrix.impl[N, E] Inbound for Csr[N, E] with fn in_incident(self, node)
impl[N, E] Inbound for Csr[N, E] with fn in_neighbors(self, node)
impl[N, E] Topology for Csr[N, E] with fn incident(self, node)
impl[N, E] Topology for Csr[N, E] with fn neighbors(self, node)
fn[E] Matrix::new(nodes : Int32) -> Matrix[E]
A matrix of
nodes rows and columns with every cell empty.impl[N, E] Topology for Csr[N, E] with fn node_count(self)
fn[E] Matrix::remove(self : Matrix[E], from : Int32, to : Int32) -> Unit
Empties a cell.
fn[E] Matrix::set( self : Matrix[E], from : Int32, to : Int32, data : E, ) -> Unit
Writes a cell, adding an edge when it was empty and replacing the payload when
it was not.
struct Partition
A partition of the nodes into groups.
struct Paths
The result of a single-source search: one distance and one predecessor per
node.
fn Paths::path_to(self : Paths, node : Int32) -> Array[Int32]?
The node numbers from a source to
node, source first, or None when the
node was not reached.fn Paths::reached(self : Paths, node : Int32) -> Bool
Whether the node was reached at all.
struct Scores
A score per node.
struct Spanning
A spanning tree: its edges and its weight.
struct StableGraph[N, E]
An adjacency-list graph whose node numbers never change: removing a node
leaves its number vacant and occupied numbers stay where they were.
fn[N, E] StableGraph::add_edge( self : StableGraph[N, E], from : Int32, to : Int32, data : E, ) -> Int32
Adds an edge from
from to to carrying data, and returns its number.fn[N, E] StableGraph::add_node(self : StableGraph[N, E], data : N) -> Int32
Adds a node in the lowest vacant number, or at the end when none is vacant,
and returns that number.
fn[N, E] StableGraph::contains_edge( self : StableGraph[N, E], edge : Int32, ) -> Bool
Whether the edge exists and has not been removed.
fn[N, E] StableGraph::contains_node( self : StableGraph[N, E], node : Int32, ) -> Bool
Whether a node number is inside the graph and occupied.
fn[N, E] StableGraph::copy(self : StableGraph[N, E]) -> StableGraph[N, E]
An independent copy.
impl[N, E] Topology for Csr[N, E] with fn directed(self)
impl[N, E] Topology for Csr[N, E] with fn edge_count(self)
fn[N, E] StableGraph::edge_data( self : StableGraph[N, E], edge : Int32, ) -> E
The payload of an edge.
fn[N, E] StableGraph::edges(self : StableGraph[N, E]) -> Iter[Int32]
Every live edge number, ascending.
impl[N, E] Topology for Csr[N, E] with fn endpoints(self, edge)
fn[N, E] StableGraph::find_edge( self : StableGraph[N, E], from : Int32, to : Int32, ) -> Int32?
The lowest-numbered edge from
from to to.fn[N, E] StableGraph::find_edges( self : StableGraph[N, E], from : Int32, to : Int32, ) -> Array[Int32]
Every edge between the pair, in number order.
fn[N, E] StableGraph::from_edges( edges : Array[(Int32, Int32)], node~ : N, edge~ : E, directed~ : Bool = true, ) -> StableGraph[N, E]
A graph built from
(from, to) pairs, every node carrying node and every
edge edge.fn[N, E] StableGraph::highest_node(self : StableGraph[N, E]) -> Int32?
The largest occupied node number, or
None for a graph with no nodes.impl[N, E] Inbound for Csr[N, E] with fn in_incident(self, node)
impl[N, E] Inbound for Csr[N, E] with fn in_neighbors(self, node)
impl[N, E] Topology for Csr[N, E] with fn incident(self, node)
fn[N, E] StableGraph::is_vacant( self : StableGraph[N, E], node : Int32, ) -> Bool
Whether a node number is inside the graph and vacant.
impl[N, E] Topology for Csr[N, E] with fn neighbors(self, node)
fn[N, E] StableGraph::new(directed~ : Bool = true) -> StableGraph[N, E]
An empty graph.
impl[N, E] Topology for Csr[N, E] with fn node_count(self)
fn[N, E] StableGraph::node_data( self : StableGraph[N, E], node : Int32, ) -> N
The payload of an occupied node.
fn[N, E] StableGraph::nodes(self : StableGraph[N, E]) -> Iter[Int32]
Every occupied node number, ascending.
fn[N, E] StableGraph::remove_edge( self : StableGraph[N, E], edge : Int32, ) -> Unit
Removes an edge, leaving its number vacant.
fn[N, E] StableGraph::remove_node( self : StableGraph[N, E], node : Int32, ) -> Unit
Removes a node and every edge on it, leaving its number vacant.
fn[N, E] StableGraph::set_edge_data( self : StableGraph[N, E], edge : Int32, data : E, ) -> Unit
Replaces an edge's payload.
fn[N, E] StableGraph::set_node_data( self : StableGraph[N, E], node : Int32, data : N, ) -> Unit
Replaces a node's payload.
fn[N, E] StableGraph::slot_count(self : StableGraph[N, E]) -> Int32
How many numbers exist, vacant ones included: one more than the largest
number ever handed out.
fn[N, E] StableGraph::slot_data( self : StableGraph[N, E], slot : Int32, ) -> N
The payload in a slot, vacant or not. A vacant slot keeps the payload it had
when it was removed, which is what lets a snapshot copy the array whole.
fn[N, E] StableGraph::vacant_count(self : StableGraph[N, E]) -> Int32
How many numbers are vacant.
fn[N, E] StableGraph::weights( self : StableGraph[N, E], of : (E) -> Double, ) -> (Int32) -> Double
A weight function over edge numbers, derived from one over payloads.
trait Inbound
A graph that can also walk its edges backwards.
trait Topology
What every algorithm needs from a graph.
moongraph/traverse17 items
fn[G : @moongraph.Topology] bfs(graph : G, source : Int32) -> Array[Int32]
The order a breadth-first walk discovers nodes, ordered by distance from the
source and then by node number.
fn[G : @moongraph.Topology] bfs_beam( graph : G, source : Int32, width~ : Int32 = 8, ) -> Array[Int32]
A beam walk: the same layer expansion as
bfs_layers, but each layer keeps
only its width lowest-numbered nodes, which is how a search stays inside a
budget when the frontier explodes.fn[G : @moongraph.Topology] bfs_edges( graph : G, source : Int32, ) -> Iter[(Int32, Int32)]
The tree edges of a breadth-first walk, as
(parent, child), in discovery
order.fn[G : @moongraph.Topology] bfs_layers( graph : G, sources : Array[Int32], ) -> Array[Array[Int32]]
The nodes at each distance from a set of sources, layer by layer, each layer
ascending.
fn[G : @moongraph.Topology] bfs_tree( graph : G, source : Int32, ) -> @moongraph.Paths
Distances and parents from a breadth-first walk.
fn[G : @moongraph.Topology] descendants_at( graph : G, source : Int32, distance : Int32, ) -> Array[Int32]
The nodes exactly
distance edges from source, ascending. A distance of 0
is the source itself, and a negative distance is nothing.fn[G : @moongraph.Topology] dfs(graph : G, source : Int32) -> Array[Int32]
The preorder of a depth-first walk: a node is listed when the walk reaches it,
and its edges are visited in ascending neighbour number.
fn[G : @moongraph.Topology] dfs_events( graph : G, source : Int32, ) -> Iter[Event]
A depth first walk reported as one event per step: entering a node, looking at an
edge to a node already on the stack, looking at an edge to a node already finished,
and leaving a node.
fn[G : @moongraph.Topology] dfs_labeled( graph : G, source : Int32, ) -> Array[(Int32, Int32, Int32)]
Every edge a depth-first walk looks at, as
(from, to, kind).fn[G : @moongraph.Topology] dfs_postorder( graph : G, source : Int32, ) -> Array[Int32]
The postorder of the same walk: a node is listed after all of its descendants.
fn[G : @moongraph.Topology] dfs_tree( graph : G, source : Int32, ) -> @moongraph.Paths
The depth-first forest from one source, as distances (how many edges deep) and
parents.
fn[G : @moongraph.Topology] edge_bfs( graph : G, source : Int32, ) -> Iter[(Int32, Int32)]
The tree edges of a breadth-first walk that covers every component, as
(from, to). Each component is entered at its lowest-numbered node, and the given
source goes first when it is in range.fn[G : @moongraph.Topology] edge_dfs( graph : G, source : Int32, ) -> Iter[(Int32, Int32)]
The tree edges of a depth-first walk that covers every component, as
(from, to). Each component is entered at its lowest-numbered node, and the given
source goes first when it is in range.enum Event
A moment in a depth-first walk.
Event::equal
Derived: whether two values of this type are the same, field by field.
Event::not_equal
Derived: whether two values of this type differ.
Event::to_repr
Derived: the debug view of a value, used when an assertion fails.
moongraph/path18 items
fn[G : @moongraph.Topology] all_simple( graph : G, from : Int32, to : Int32, ) -> Iter[Array[Int32]]
Every simple route between two nodes, as node sequences, source first.
fn[G : @moongraph.Topology] all_simple_edges( graph : G, from : Int32, to : Int32, ) -> Iter[Array[Int32]]
The same routes, named by edge number instead of by node.
fn[G : @moongraph.Topology] astar( graph : G, from : Int32, to : Int32, weight? : (Int32) -> Double, estimate~ : (Int32) -> Double, ) -> @moongraph.Paths raise @moongraph.Refused
The cheapest route between two nodes with a hint to steer the search.
fn[G : @moongraph.Topology] bellman_ford( graph : G, source : Int32, weight? : (Int32) -> Double, ) -> @moongraph.Paths raise @moongraph.Refused
Cheapest routes from one source when edges may be negative.
fn[G : @moongraph.Topology] bfs_all(graph : G) -> @moongraph.AllPairs
Every pair on an unweighted graph, by one breadth-first pass per node. On such
a graph this is the fastest all-pairs method there is, and naming it keeps a
caller from running Dijkstra over unit weights.
fn[G : @moongraph.Topology] dijkstra( graph : G, source : Int32, weight? : (Int32) -> Double, ) -> @moongraph.Paths raise @moongraph.Refused
Cheapest routes from one source, by Dijkstra's method.
fn[G : @moongraph.Topology] dijkstra_all( graph : G, weight? : (Int32) -> Double, ) -> @moongraph.AllPairs raise @moongraph.Refused
Every pair, by one Dijkstra pass per node.
fn[G : @moongraph.Topology + @moongraph.Inbound] dijkstra_bidirectional( graph : G, from : Int32, to : Int32, weight? : (Int32) -> Double, ) -> @moongraph.Paths raise @moongraph.Refused
The cheapest route between two nodes, searched from both ends at once.
fn[G : @moongraph.Topology] dijkstra_multi( graph : G, sources : Array[Int32], weight? : (Int32) -> Double, ) -> @moongraph.Paths raise @moongraph.Refused
Cheapest routes from several sources at once; every source starts at 0.
fn[G : @moongraph.Topology] floyd_warshall( graph : G, weight? : (Int32) -> Double, ) -> @moongraph.AllPairs raise @moongraph.Refused
Every pair, by the triple loop.
fn[G : @moongraph.Topology] has_path( graph : G, from : Int32, to : Int32, ) -> Bool
Whether any route joins the two nodes. Directed graphs follow the edge
direction, as every other function here does.
fn[G : @moongraph.Topology] is_simple_path( graph : G, path : Array[Int32], ) -> Bool
Whether a node sequence is a simple path: every node distinct, and every
consecutive pair joined by an edge.
fn[G : @moongraph.Topology] johnson( graph : G, weight? : (Int32) -> Double, ) -> @moongraph.AllPairs raise @moongraph.Refused
Every pair, by Johnson's reweighting: one Bellman-Ford pass makes the weights
non-negative, then a Dijkstra pass per node.
fn[G : @moongraph.Topology] k_shortest( graph : G, from : Int32, to : Int32, k : Int32, weight? : (Int32) -> Double, ) -> Array[Array[Int32]] raise @moongraph.Refused
Up to
k cheapest routes between two nodes, cheapest first, without repeats.fn[G : @moongraph.Topology] path_weight( graph : G, path : Array[Int32], weight? : (Int32) -> Double, ) -> Double raise @moongraph.Refused
The cost of walking a node sequence, taking the cheapest edge between each
consecutive pair.
fn[G : @moongraph.Topology] shortest( graph : G, from : Int32, to : Int32, weight? : (Int32) -> Double, ) -> Array[Int32]? raise @moongraph.Refused
The cheapest route between two nodes, by whichever method the weights allow.
fn[G : @moongraph.Topology] spfa( graph : G, source : Int32, weight? : (Int32) -> Double, ) -> @moongraph.Paths raise @moongraph.Refused
Cheapest routes from one source by the queue-based relaxation that is
Bellman-Ford with the redundant passes skipped. Same answer, usually fewer
passes.
fn[G : @moongraph.Topology] widest( graph : G, source : Int32, weight? : (Int32) -> Double, ) -> @moongraph.Paths raise @moongraph.Refused
The route that keeps the least capacity as high as possible: the widest path.
moongraph/component23 items
fn[G : @moongraph.Topology] articulation_points(graph : G) -> Array[Int32]
The nodes whose removal disconnects the graph, ascending.
fn[G : @moongraph.Topology] attracting_components( graph : G, ) -> Array[Array[Int32]]
The nodes from which a random walk never leaves its component: those with no
edge to another strong component.
fn[G : @moongraph.Topology] biconnected_component_nodes( graph : G, ) -> Array[Array[Int32]]
The nodes of each biconnected piece, ascending inside each piece, pieces in the
order
biconnected_components returns them.fn[G : @moongraph.Topology] biconnected_components( graph : G, ) -> Array[Array[Int32]]
Every edge that lies on a cycle, grouped by biconnected piece, with an isolated
edge forming a piece of its own.
fn[G : @moongraph.Topology] bridges(graph : G) -> Array[Int32]
The edges whose removal disconnects the graph, in number order.
fn[G : @moongraph.Topology] chain_decomposition( graph : G, ) -> Array[Array[Int32]]
Splits the graph into chains around a depth-first tree: every back edge with the
tree path under it, and every bridge on its own.
fn[G : @moongraph.Topology + @moongraph.Inbound] component_count( graph : G, ) -> Int32
How many components there are.
fn[G : @moongraph.Topology + @moongraph.Inbound] component_of( graph : G, node : Int32, ) -> Array[Int32]
The nodes in the same component as
node, ascending.fn[G : @moongraph.Topology + @moongraph.Inbound] components( graph : G, ) -> @moongraph.Components
The components of a graph, as a label per node.
fn[G : @moongraph.Topology] condensation( graph : G, ) -> @moongraph.Condensation
The condensation: one node per strong component, one edge per component pair
that has an edge between them.
fn[G : @moongraph.Topology] edge_boundary( graph : G, set : Array[Int32], ) -> Array[Int32]
The edges with one endpoint in
set and one outside it, in number order.fn[G : @moongraph.Topology] has_bridges(graph : G) -> Bool
Whether any edge is a bridge.
fn[G : @moongraph.Topology] is_biconnected(graph : G) -> Bool
Whether removing any single node leaves the graph connected.
fn[G : @moongraph.Topology + @moongraph.Inbound] is_connected( graph : G, ) -> Bool
Whether the graph is one piece.
fn[G : @moongraph.Topology] is_semiconnected(graph : G) -> Bool
Whether the nodes can be laid on a line so that every pair has an edge in at
least one direction: the condensation has to be a single chain.
fn[G : @moongraph.Topology] is_strongly_connected(graph : G) -> Bool
Whether every node reaches every other.
fn[G : @moongraph.Topology + @moongraph.Inbound] is_weakly_connected( graph : G, ) -> Bool
Whether the graph is one piece when direction is ignored.
fn[G : @moongraph.Topology] local_bridges( graph : G, span~ : Int32 = 1, ) -> Array[Int32]
The edges whose endpoints have no route between them short enough to make the
edge part of a small cycle.
fn[G : @moongraph.Topology + @moongraph.Inbound] node_boundary( graph : G, set : Array[Int32], ) -> Array[Int32]
The nodes outside
set with an edge to it, ascending.fn[G : @moongraph.Topology] reachable_count( graph : G, node : Int32, ) -> Int32
How many nodes
node reaches, itself included.fn[G : @moongraph.Topology] strong_components( graph : G, ) -> @moongraph.Components
Strongly connected components by Tarjan's method: one depth-first pass, one
stack.
fn[G : @moongraph.Topology + @moongraph.Inbound] strong_components_kosaraju( graph : G, ) -> @moongraph.Components
Strong components by two passes: one forward, one over the reversed edges.
fn[G : @moongraph.Topology + @moongraph.Inbound] weak_components( graph : G, ) -> @moongraph.Components
The same components under the name that says the edges were read both ways.
moongraph/dag23 items
fn[G : @moongraph.Topology] all_topological_orders( graph : G, ) -> Iter[Array[Int32]]
Every topological order, in lexicographic order of the node sequences.
fn[G : @moongraph.Topology + @moongraph.Inbound] ancestors( graph : G, node : Int32, ) -> Array[Int32]
The nodes that reach
node, ascending, itself excluded.fn[G : @moongraph.Topology] antichains(graph : G) -> Array[Array[Int32]]
The maximal antichains of the reachability order: sets of nodes no two of which
are comparable.
fn[G : @moongraph.Topology + @moongraph.Inbound] colliders( graph : G, ) -> Array[Int32]
The nodes that sit at the head of a fork: two incoming edges from nodes that are
not themselves joined.
fn[G : @moongraph.Topology] descendants( graph : G, node : Int32, ) -> Array[Int32]
The nodes
node reaches, ascending, itself excluded.fn[G : @moongraph.Topology + @moongraph.Inbound] dominance_frontiers( graph : G, entry : Int32, ) -> Array[Array[Int32]]
The dominance frontier of each node: the nodes where its dominance stops.
fn[G : @moongraph.Topology + @moongraph.Inbound] dominators( graph : G, entry : Int32, ) -> Array[Int32?]
The immediate dominator of each node from
entry: the last node every route
from the entry must pass through.fn[G : @moongraph.Topology] is_aperiodic(graph : G) -> Bool
Whether the lengths of the cycles in the graph have no common divisor above one.
fn[G : @moongraph.Topology] is_dag(graph : G) -> Bool
Whether the graph has no cycle.
fn[G : @moongraph.Topology] longest_path( graph : G, weight? : (Int32) -> Double, ) -> Array[Int32] raise @moongraph.Refused
A longest route in the graph, as node numbers, by relaxing in topological order.
fn[G : @moongraph.Topology] longest_path_length( graph : G, weight? : (Int32) -> Double, ) -> Double raise @moongraph.Refused
The weight of the longest route.
fn[G : @moongraph.Topology] topological_generations( graph : G, ) -> Array[Array[Int32]] raise @moongraph.Refused
The order cut into generations: every node of a generation has all of its
predecessors in earlier generations.
fn[G : @moongraph.Topology] topological_order( graph : G, ) -> Array[Int32] raise @moongraph.Refused
A node order in which every edge points forward.
fn[G : @moongraph.Topology] topological_smallest( graph : G, ) -> Array[Int32] raise @moongraph.Refused
The smallest-numbered node that is ready at every step, which is the
lexicographically smallest topological order.
fn[G : @moongraph.Topology] transitive_closure( graph : G, ) -> Array[Array[Bool]]
The reachability matrix:
closure[from][to] is true when an edge or a chain of
them joins the two. A node reaches itself.fn[G : @moongraph.Topology] transitive_reduction( graph : G, ) -> Array[(Int32, Int32)]
The edges that no other route makes redundant, as
(from, to) pairs.struct Sorter
An incremental topological sorter: nodes are added as they become known, and the
caller asks which are ready without restarting the walk.
fn Sorter::add( self : Sorter, node : Int32, after : Array[Int32], ) -> Unit raise @moongraph.Refused
Declares that
node must come after every node in after. The node may be one
the graph did not have.fn Sorter::finish( self : Sorter, nodes : Array[Int32], ) -> Unit raise @moongraph.Refused
Marks nodes as done, which may release the nodes that were waiting on them.
fn Sorter::is_active(self : Sorter) -> Bool
Whether any node is still waiting.
fn[G : @moongraph.Topology] Sorter::new(graph : G) -> Sorter
A sorter holding every node of the graph, with the graph's edges as
prerequisites.
fn Sorter::order(self : Sorter) -> Array[Int32] raise @moongraph.Refused
The full order, as the sorter sees it from the start, which is the same as
topological_order on the graph plus every node added since.fn Sorter::ready(self : Sorter) -> Array[Int32] raise @moongraph.Refused
The nodes whose prerequisites are all finished, ascending. Each node is handed
out once until it is finished.
moongraph/cycle15 items
fn[G : @moongraph.Topology] chinese_postman( graph : G, weight? : (Int32) -> Double, ) -> Array[Int32] raise @moongraph.Refused
A route that walks every edge at least once, duplicating edges when the graph
has odd-degree nodes, as edge numbers in walk order.
fn[G : @moongraph.Topology] chordless_cycles( graph : G, length_bound? : Int32, ) -> Iter[Array[Int32]]
The cycles with no edge joining two of their own nodes.
fn[G : @moongraph.Topology] cycle_basis(graph : G) -> Array[Array[Int32]]
A basis of the cycle space: one fundamental cycle per edge that is not a bridge,
enough of them to generate every cycle by symmetric difference.
fn[G : @moongraph.Topology] eulerian_circuit( graph : G, ) -> Array[Int32] raise @moongraph.Refused
A closed walk that uses every edge exactly once, as edge numbers.
fn[G : @moongraph.Topology + @moongraph.Inbound] eulerian_path( graph : G, ) -> Array[Int32]?
The one trail that uses every edge exactly once, or
None when there is none.fn[G : @moongraph.Topology] eulerize( graph : G, weight? : (Int32) -> Double, ) -> Array[(Int32, Int32)] raise @moongraph.Refused
The edges to duplicate so that the graph becomes Eulerian, as
(from, to)
pairs.fn[G : @moongraph.Topology + @moongraph.Inbound] feedback_arc_set( graph : G, ) -> Array[Int32]
A set of edges whose removal leaves a graph without cycles, chosen greedily.
fn[G : @moongraph.Topology] find_cycle(graph : G) -> Array[Int32]?
One cycle, as node numbers, first and last equal;
None when the graph is
acyclic.fn[G : @moongraph.Topology] girth(graph : G) -> Int32?
The length of the shortest cycle, or
None when the graph is a forest.fn[G : @moongraph.Topology + @moongraph.Inbound] has_eulerian_path( graph : G, ) -> Bool
Whether every edge can be walked in one trail that is not closed: exactly two
nodes have odd degree and they are the ends.
fn[G : @moongraph.Topology] is_cyclic(graph : G) -> Bool
Whether the graph has a cycle. A self-loop counts.
fn[G : @moongraph.Topology] is_eulerian(graph : G) -> Bool
Whether every edge lies on one closed walk: every node is joined to the rest and
every degree is even.
fn[G : @moongraph.Topology] min_cycle_ratio( graph : G, cost~ : (Int32) -> Double, weight? : (Int32) -> Double, ) -> Double raise @moongraph.Refused
The smallest cost-to-weight ratio over all cycles.
fn[G : @moongraph.Topology] minimum_cycle_basis( graph : G, weight? : (Int32) -> Double, ) -> Array[Array[Int32]]
A cycle basis of total length as small as possible.
fn[G : @moongraph.Topology] simple_cycles(graph : G) -> Iter[Array[Int32]]
Every simple cycle, each reported once.
moongraph/tree25 items
fn[G] branching_weight( graph : G, spanning : @moongraph.Spanning, weight? : (Int32) -> Double, ) -> Double
The weight of a branching, which is the sum of the weights of its edges.
fn[G : @moongraph.Topology] broadcast_center( graph : G, ) -> (Int32, Int32) raise @moongraph.Refused
The node whose furthest node is nearest: the best place to start a broadcast.
fn from_nested(nested : Nested) -> (@moongraph.Graph[Int32, Unit], Int32)
The tree a nested shape describes, and the number it gives its root.
fn from_prufer(sequence : Array[Int32]) -> @moongraph.Graph[Int32, Unit]
The tree a Prüfer code describes, over node numbers
0 .. n.fn[G : @moongraph.Topology] maximum_branching( graph : G, weight? : (Int32) -> Double, root? : Int32, ) -> @moongraph.Spanning raise @moongraph.Refused
The most expensive branching, by the same walk on negated weights.
fn[G : @moongraph.Topology] maximum_spanning( graph : G, weight? : (Int32) -> Double, ) -> @moongraph.Spanning raise @moongraph.Refused
A maximum spanning tree, by the same walk with the comparison turned around.
fn[G : @moongraph.Topology] minimum_branching( graph : G, weight? : (Int32) -> Double, root? : Int32, ) -> @moongraph.Spanning raise @moongraph.Refused
The cheapest set of directed edges that gives every node at most one parent and
the whole graph a root, by Chu-Liu/Edmonds.
fn[G : @moongraph.Topology] minimum_spanning( graph : G, weight? : (Int32) -> Double, kind~ : SpanningMethod = Kruskal, ) -> @moongraph.Spanning raise @moongraph.Refused
A minimum spanning tree.
fn[G : @moongraph.Topology] prufer_sequence( graph : G, ) -> Array[Int32] raise @moongraph.Refused
Prüfer's code of a labelled tree: the sequence of labels a leaf-stripping walk
leaves behind.
fn[G : @moongraph.Topology] random_spanning( graph : G, rng~ : &@contract.Rng, ) -> @moongraph.Spanning
A spanning tree picked at random, by a random permutation of the edges fed to
Kruskal. Every tree is equally likely when the edges are shuffled uniformly.
fn[G : @moongraph.Topology] spanning_count(graph : G) -> Double
How many spanning trees the graph has, by Kirchhoff's determinant.
fn[G : @moongraph.Topology] spanning_trees( graph : G, weight? : (Int32) -> Double, ) -> Iter[@moongraph.Spanning]
Every distinct spanning tree.
fn[G : @moongraph.Topology] steiner_tree( graph : G, terminals : Array[Int32], weight? : (Int32) -> Double, ) -> @moongraph.Spanning raise @moongraph.Refused
A tree that connects the terminals, by the Dreyfus-Wagner dynamic program over
subsets of terminals.
fn[G : @moongraph.Topology] subtree_sizes( graph : G, root : Int32, ) -> Array[Int32] raise @moongraph.Refused
The number of nodes in the subtree under each node when the tree is rooted at
root, the node itself included.fn[G : @moongraph.Topology] to_nested( graph : G, root : Int32, ) -> Nested raise @moongraph.Refused
The nested form of the tree rooted at
root.fn[G : @moongraph.Topology] tree_center( graph : G, ) -> Array[Int32] raise @moongraph.Refused
The middle of a tree's longest route: the one or two nodes with the smallest
eccentricity. A tree has one centre.
fn[G : @moongraph.Topology] tree_centroid( graph : G, ) -> Array[Int32] raise @moongraph.Refused
The node whose removal leaves the largest remaining piece as small as possible.
fn[G : @moongraph.Topology] tree_depth( graph : G, root : Int32, ) -> Array[Int32] raise @moongraph.Refused
The depth of every node below
root.struct Lca
Lowest common ancestor queries on a rooted tree, after one preprocessing pass.
fn Lca::ancestor_at(self : Lca, node : Int32, up : Int32) -> Int32?
The ancestor
up steps above a node, or None when the walk leaves the tree.fn Lca::depth(self : Lca, node : Int32) -> Int32
How deep a node is under the root the object was built at.
fn[G : @moongraph.Topology] Lca::new( graph : G, root : Int32, ) -> Lca raise @moongraph.Refused
Preprocesses the tree rooted at
root, by binary lifting.fn Lca::of(self : Lca, a : Int32, b : Int32) -> Int32?
The lowest node that is an ancestor of both.
enum Nested
A rooted tree without node numbers: the shape a caller wants when comparing two
trees.
enum SpanningMethod
How a spanning tree is grown.
moongraph/flow35 items
fn[G : @moongraph.Topology] all_min_cuts( graph : G, source : Int32, sink : Int32, capacity? : (Int32) -> Double, ) -> Iter[@moongraph.Cut]
Every cut of least capacity between the two nodes.
fn[G : @moongraph.Topology] edge_connectivity( graph : G, capacity? : (Int32) -> Double, ) -> Int32
The smallest number of edges whose removal disconnects the graph.
fn[G : @moongraph.Topology] edge_connectivity_pair( graph : G, from : Int32, to : Int32, ) -> Int32
The smallest number of edges whose removal separates the two nodes.
fn[G : @moongraph.Topology] edge_disjoint_paths( graph : G, from : Int32, to : Int32, ) -> Array[Array[Int32]]
Routes between the two nodes that share no edge, as many as the edge connectivity
allows.
fn[G] flow_cost( graph : G, flow : @moongraph.Flow, cost? : (Int32) -> Double, ) -> Double
The cost of a flow, edge by edge.
fn[G : @moongraph.Topology] gomory_hu( graph : G, capacity? : (Int32) -> Double, ) -> Array[(Int32, Int32, Double)]
A cut tree:
V - 1 pairs with the capacity that separates them.fn[G : @moongraph.Topology] k_components(graph : G) -> Array[Array[Int32]]
The pieces that stay joined after any
k - 1 nodes are removed.fn[G : @moongraph.Topology] k_edge_components( graph : G, k : Int32, ) -> Array[Array[Int32]]
The pieces that stay joined after any
k - 1 edges are removed.fn[G : @moongraph.Topology] max_flow( graph : G, source : Int32, sink : Int32, capacity? : (Int32) -> Double, kind~ : FlowMethod = Dinitz, ) -> @moongraph.Flow raise @moongraph.Refused
The maximum flow from
source to sink.fn[G : @moongraph.Topology] max_flow_min_cost( graph : G, source : Int32, sink : Int32, cost? : (Int32) -> Double, capacity? : (Int32) -> Double, ) -> @moongraph.Flow raise @moongraph.Refused
The maximum flow that costs the least to send.
fn[G : @moongraph.Topology] max_flow_value( graph : G, source : Int32, sink : Int32, capacity? : (Int32) -> Double, ) -> Double raise @moongraph.Refused
The value alone, which costs the same as the flow itself.
fn[G : @moongraph.Topology] min_cost_flow( graph : G, supply : Array[Double], cost? : (Int32) -> Double, capacity? : (Int32) -> Double, ) -> @moongraph.Flow raise @moongraph.Refused
A flow that meets the supplies at the least cost.
fn[G : @moongraph.Topology] min_cut( graph : G, source : Int32, sink : Int32, capacity? : (Int32) -> Double, ) -> @moongraph.Cut raise @moongraph.Refused
The cut of least capacity that separates the two nodes.
fn[G : @moongraph.Topology] min_cut_global( graph : G, capacity? : (Int32) -> Double, ) -> @moongraph.Cut
The cut of least capacity anywhere in the graph, by Stoer-Wagner.
fn[G : @moongraph.Topology] min_edge_cut(graph : G) -> Array[Int32]
The edges of one smallest cut anywhere in the graph.
fn[G : @moongraph.Topology] min_node_cut(graph : G) -> Array[Int32]
The nodes of one smallest separating set.
fn[G : @moongraph.Topology] node_connectivity(graph : G) -> Int32
The smallest number of nodes whose removal disconnects the graph, other than the
two that are being separated.
fn[G : @moongraph.Topology] node_connectivity_pair( graph : G, from : Int32, to : Int32, ) -> Int32
The smallest number of nodes other than the two ends whose removal separates them.
fn[G : @moongraph.Topology] node_disjoint_paths( graph : G, from : Int32, to : Int32, ) -> Array[Array[Int32]]
Routes between the two nodes that share no node but the ends.
fn[G : @moongraph.Topology] split_network( graph : G, source : Int32, sink : Int32, ) -> Network
The graph split into two nodes per node, joined by a capacity of one, so that a
minimum cut through it names a set of nodes rather than a set of edges.
enum FlowMethod
Which solver a caller wants. The answer is the same for all of them; the work and
the constant factor are not.
struct Network
A residual network over a graph: two arcs per edge, capacities that fall as flow
is sent, and the reverse arc that gives it back.
fn[G : @moongraph.Topology] Network::build( graph : G, capacity : (Int32) -> Double, ) -> Network
fn Network::dinitz(self : Network, source : Int32, sink : Int32) -> Unit
Dinitz: build a level graph by breadth-first search, then push a blocking flow
through it, and repeat while the sink is still reachable.
fn Network::edmonds_karp( self : Network, source : Int32, sink : Int32, ) -> Unit
Edmonds-Karp: the same walk with a plain breadth-first search for the route.
fn[G] Network::paths( self : Network, graph : G, from : Int32, to : Int32, ) -> Array[Array[Int32]]
The routes the flow takes: one at a time, each found in the graph of arcs that still
carry flow and then removed from it, so the next search looks for a different route.
fn Network::paths_split( self : Network, from : Int32, to : Int32, ) -> Array[Array[Int32]]
The same, over a network whose nodes are half-nodes.
fn Network::push_along( self : Network, node : Int32, sink : Int32, limit : Double, level : Array[Int32], cursor : Array[Int32], ) -> Double
Pushes what it can along one route of the level graph, resuming from the cursor so
an arc that is full is never looked at twice in one phase.
fn Network::push_relabel( self : Network, source : Int32, sink : Int32, ) -> Unit
Push-relabel: keep an excess at every node and push it towards the sink, lifting a
node only when it has nowhere to push.
fn Network::reachable(self : Network, source : Int32) -> Array[Bool]
fn[G : @moongraph.Topology] Network::report( self : Network, graph : G, ) -> @moongraph.Flow
The flow per original edge, after a solve.
fn Network::residual_forward(self : Network, edge : Int32) -> Double
The capacity still free on the forward arc of an edge.
fn Network::shift( self : Network, source : Int32, sink : Int32, cost : (Int32) -> Double, ) -> Double
Sends as much as it can from
source to sink along routes of least weight, and
answers how much moved.fn Network::solve( self : Network, source : Int32, sink : Int32, kind : FlowMethod, ) -> Unit raise @moongraph.Refused
Runs one solver to completion.
fn Network::source_side(self : Network, source : Int32) -> Array[Bool]
The nodes the source can still reach, which is the source side of the cut.
moongraph/matching12 items
fn[G : @moongraph.Topology] assignment( graph : G, weight~ : (Int32) -> Double, ) -> @moongraph.Matching raise @moongraph.Refused
An assignment of the left side to the right side with the least total cost, by the
Hungarian method.
fn[G : @moongraph.Topology] bipartition(graph : G) -> Array[Int32]?
A two-colouring of the graph, or
None when an odd cycle makes one impossible.fn[G : @moongraph.Topology] edge_cover(graph : G) -> @moongraph.Cover
A smallest set of edges that touches every node.
fn[G : @moongraph.Topology] is_edge_cover( graph : G, cover : @moongraph.Cover, ) -> Bool
Whether the cover leaves no node untouched.
fn[G : @moongraph.Topology] is_matching( graph : G, pairs : Array[(Int32, Int32)], ) -> Bool
Whether the pairs form a matching: no node appears twice and every pair is an edge.
fn[G : @moongraph.Topology] is_maximal_matching( graph : G, pairs : Array[(Int32, Int32)], ) -> Bool
Whether no further pair could be added to the matching.
fn[G : @moongraph.Topology] is_perfect_matching( graph : G, pairs : Array[(Int32, Int32)], ) -> Bool
Whether every node is paired.
fn[G : @moongraph.Topology] matching_bipartite( graph : G, weight? : (Int32) -> Double, ) -> @moongraph.Matching raise @moongraph.Refused
The matching of a bipartite graph, by the augmenting walk of König's theorem.
fn[G : @moongraph.Topology] matching_maximal( graph : G, ) -> @moongraph.Matching
A maximal matching: no two pairs share a node and no further pair can be added.
fn[G : @moongraph.Topology] matching_maximum( graph : G, weight? : (Int32) -> Double, ) -> @moongraph.Matching
A matching of the largest number of pairs, by Edmonds' blossom walk.
fn[G : @moongraph.Topology] matching_min_weight( graph : G, weight~ : (Int32) -> Double, ) -> @moongraph.Matching raise @moongraph.Refused
A minimum-weight matching of the largest size, by the same assignment step with the
weights turned around.
fn[G : @moongraph.Topology] vertex_cover_bipartite( graph : G, ) -> Array[Int32]
A smallest set of nodes that touches every edge of a bipartite graph, read off a
maximum matching: the nodes on one side of a König cover.
moongraph/color8 items
fn[G : @moongraph.Topology] chromatic_number( graph : G, limit~ : Int32 = 32, ) -> Int32 raise @moongraph.Refused
The fewest colours any colouring needs, by trying each count in turn.
fn[G : @moongraph.Topology] dsatur(graph : G) -> @moongraph.Coloring
The colouring that saturates first: at each step the node whose neighbours already
use the most distinct colours gets the next colour.
fn[G : @moongraph.Topology] edge_coloring(graph : G) -> @moongraph.Coloring
A colouring of the edges: no two edges of the same colour share a node.
fn[G : @moongraph.Topology] equitable_coloring( graph : G, colors : Int32, ) -> @moongraph.Coloring raise @moongraph.Refused
A colouring in which the colour classes differ in size by at most one.
fn[G : @moongraph.Topology] greedy_coloring( graph : G, order~ : ColoringOrder = LargestFirst, rng? : &@contract.Rng, ) -> @moongraph.Coloring
A colouring of the nodes, one colour at a time, taking the lowest colour that no
neighbour already has.
fn[G : @moongraph.Topology] is_coloring( graph : G, coloring : @moongraph.Coloring, ) -> Bool
Whether no two neighbours share a colour.
fn[G : @moongraph.Topology] is_edge_coloring( graph : G, coloring : @moongraph.Coloring, ) -> Bool
Whether no two edges of the same colour touch.
enum ColoringOrder
The order in which nodes are offered a colour.
moongraph/clique15 items
fn[G : @moongraph.Topology] all_cliques( graph : G, at_least~ : Int32 = 3, ) -> @moongraph.Cliques
Every clique of at least
at_least nodes.fn[G : @moongraph.Topology] chordal_cliques( graph : G, ) -> @moongraph.Cliques
The maximal cliques of a chordal graph, read off its elimination order: the node and
its later neighbours form one, and the ones that another contains are dropped.
fn[G : @moongraph.Topology] chordal_fill_in( graph : G, ) -> Array[(Int32, Int32)]
The edges that have to be added to make the graph chordal, keeping the elimination
order the search found. A graph that is already chordal gets none.
fn[G : @moongraph.Topology] chordal_treewidth(graph : G) -> Int32
The width of the tree decomposition the elimination order gives: one less than the
largest clique in it.
fn[G : @moongraph.Topology] clique_graph( graph : G, ) -> @moongraph.Graph[Int32, Unit]
The graph whose nodes are the maximal cliques, joined when those cliques share a node.
fn[G : @moongraph.Topology] clique_number(graph : G) -> Int32
The size of the largest clique.
fn[G : @moongraph.Topology] clique_numbers(graph : G) -> Array[Int32]
The size of the largest clique each node belongs to.
fn[G : @moongraph.Topology] independence_number(graph : G) -> Int32
The size of the largest independent set.
fn[G : @moongraph.Topology] is_chordal(graph : G) -> Bool
Whether every cycle of four or more nodes has a chord.
fn[G : @moongraph.Topology] is_clique( graph : G, nodes : Array[Int32], ) -> Bool
Whether every pair of the given nodes is joined, so that they form a clique.
fn[G : @moongraph.Topology] is_perfect(graph : G) -> Bool
Whether every induced subgraph has a clique and an independent set of the same size,
which chordal graphs and bipartite graphs both satisfy.
fn[G : @moongraph.Topology] max_weight_clique( graph : G, weight~ : (Int32) -> Double, ) -> @moongraph.Cliques
The clique with the largest total weight, where a node's weight is its payload.
fn[G : @moongraph.Topology] maximal_cliques( graph : G, ) -> @moongraph.Cliques
Every maximal clique, each one sorted and reported once.
fn[G : @moongraph.Topology] maximum_independent_set( graph : G, ) -> Array[Int32]
A largest set of nodes no two of which are joined.
fn[G : @moongraph.Topology] perfect_elimination_order( graph : G, ) -> Array[Int32]?
A perfect elimination order: a node order in which the later neighbours of each node
are all joined to each other.
None when the graph is not chordal.moongraph/centrality13 items
fn[G : @moongraph.Topology] betweenness_centrality( graph : G, ) -> @moongraph.Scores
The number of shortest routes that pass through each node, halved for an undirected
graph so that a route counts once.
fn[G : @moongraph.Topology] closeness_centrality( graph : G, ) -> @moongraph.Scores
One over the total distance from a node to every other, so a node at the middle of the
graph scores highest.
fn[G : @moongraph.Topology] degree_centrality( graph : G, ) -> @moongraph.Scores
The share of nodes a node is joined to.
fn[G : @moongraph.Topology] edge_betweenness(graph : G) -> Array[Double]
The number of shortest routes that use each edge.
fn[G : @moongraph.Topology] eigenvector_centrality( graph : G, iterations~ : Int32 = 100, tolerance~ : Double = 1.0e-9, ) -> @moongraph.Scores
The score a walk that keeps stepping to a neighbour settles on, by power iteration
over the adjacency matrix.
fn[G : @moongraph.Topology] group_betweenness( graph : G, group : Array[Int32], ) -> Double
How central a whole set is, read as the routes that pass through any member.
fn[G : @moongraph.Topology] group_closeness( graph : G, group : Array[Int32], ) -> Double
How close a whole set is to everything else: one over the summed distance from the set.
fn[G : @moongraph.Topology] harmonic_centrality( graph : G, ) -> @moongraph.Scores
Harmonic centrality: the sum of one over the distance to every other node, which is
defined even when the graph is not connected.
fn[G : @moongraph.Topology] hits( graph : G, iterations~ : Int32 = 100, ) -> (@moongraph.Scores, @moongraph.Scores)
The hub and authority scores a link graph implies, by the iteration that gives each
node the sum of its neighbours' authority and the other way round.
fn[G : @moongraph.Topology] katz( graph : G, alpha~ : Double = 0.1, beta~ : Double = 1.0, iterations~ : Int32 = 100, ) -> @moongraph.Scores
Katz centrality: every route between two nodes counts, with longer routes counting
less, which makes it work on graphs a power iteration would stall on.
fn[G : @moongraph.Topology] load_centrality(graph : G) -> @moongraph.Scores
Load centrality: the share of the shortest routes through each node when every pair
sends one unit, counted without halving.
fn[G : @moongraph.Topology] pagerank( graph : G, damping~ : Double = 0.85, iterations~ : Int32 = 100, tolerance~ : Double = 1.0e-9, ) -> @moongraph.Scores
PageRank: the share of a walk's time each node holds, with a jump back to a random
node now and then.
fn[G : @moongraph.Topology] subgraph_centrality( graph : G, ) -> @moongraph.Scores
Subgraph centrality: the weighted count of closed routes from a node back to itself,
longer ones counting less.
moongraph/community6 items
fn[G : @moongraph.Topology] girvan_newman( graph : G, count : Int32, ) -> @moongraph.Partition
Groups formed by taking out the edges that carry the most routes, one at a time, and
stopping when the graph falls into
count pieces. The pieces are what comes back.fn[G : @moongraph.Topology] greedy_modularity( graph : G, ) -> @moongraph.Partition
Groups grown greedily on modularity: start from every node alone and merge the pair of
groups that raises modularity most, until no merge helps.
fn[G : @moongraph.Topology] k_clique_communities( graph : G, k : Int32, ) -> @moongraph.Partition
The groups of a graph that overlap: the maximal cliques of size at least
k, merged
when they share k - 1 nodes.fn[G : @moongraph.Topology] label_propagation( graph : G, rounds~ : Int32 = 20, ) -> @moongraph.Partition
Groups found by letting every node shout its label and take the most common one among
its neighbours until nothing changes.
fn[G : @moongraph.Topology] leiden( graph : G, resolution~ : Double = 1.0, rounds~ : Int32 = 8, ) -> @moongraph.Partition
Groups grown by the Leiden walk: local moving, then a refinement that cuts every
group into connected pieces, then a fold that treats those pieces as nodes.
fn[G : @moongraph.Topology] louvain( graph : G, resolution~ : Double = 1.0, rounds~ : Int32 = 8, ) -> @moongraph.Partition
Groups grown by local search on modularity: every node starts alone, moves to the group
that raises modularity most, and the groups are then treated as nodes and the walk
repeats.
moongraph/metric24 items
fn[G : @moongraph.Topology] adamic_adar( graph : G, a : Int32, b : Int32, ) -> Double
The same idea with the neighbourhood size taken as just over one, which fades faster
as a hub grows.
fn[G : @moongraph.Topology] assortativity(graph : G) -> Double
The degree correlation: whether nodes of like degree prefer each other.
fn[G : @moongraph.Topology] average_clustering(graph : G) -> Double
The mean of the local clustering over every node.
fn[G : @moongraph.Topology] center(graph : G) -> Array[Int32]
The nodes at the radius: the middle of the graph.
fn[G : @moongraph.Topology] clustering(graph : G, node : Int32) -> Double
How many of a node's neighbours are themselves neighbours, as a fraction of the pairs
that could be.
fn[G : @moongraph.Topology] degree(graph : G) -> Array[Int32]
The number of edges out of each node.
fn[G : @moongraph.Topology] degree_histogram(graph : G) -> Array[Int32]
How many nodes have each degree, from 0 up to the largest.
fn[G : @moongraph.Topology] density(graph : G) -> Double
How many of the possible edges are present: 0 for an empty graph, 1 for a complete
one.
fn[G : @moongraph.Topology] diameter(graph : G) -> Int32
The largest eccentricity: the longest shortest route.
fn[G : @moongraph.Topology] distinct_edge_count(graph : G) -> Int32
How many edges there are, counting a pair once however many parallel edges join it.
fn[G : @moongraph.Topology] eccentricity(graph : G, node : Int32) -> Int32
The number of hops from
node to its furthest node.fn[G : @moongraph.Topology] efficiency(graph : G) -> Double
How well the graph moves information: the mean of one over the shortest route between
every pair.
fn[G : @moongraph.Topology + @moongraph.Inbound] in_degree( graph : G, ) -> Array[Int32]
The number of edges into each node.
fn[G : @moongraph.Topology] modularity( graph : G, partition : @moongraph.Partition, ) -> Double
How well the edges between two groups explain themselves: the edge weight inside each
group compared with what a random rewiring would give.
fn[G : @moongraph.Topology] periphery(graph : G) -> Array[Int32]
The nodes at the diameter: the ends of the longest shortest route.
fn[G : @moongraph.Topology] radius(graph : G) -> Int32
The smallest eccentricity: the best node to stand at.
fn[G : @moongraph.Topology] reciprocity(graph : G) -> Double
The fraction of edges that point both ways, over the edges a directed graph has.
fn[G : @moongraph.Topology] resource_allocation( graph : G, a : Int32, b : Int32, ) -> Double
How much traffic a route could carry between two nodes under the similarity measures
above: the resources a node and its neighbours allocate to it.
fn[G : @moongraph.Topology] similarity( graph : G, a : Int32, b : Int32, kind~ : SimilarityKind = Jaccard, ) -> Double
How alike two nodes are: how much their neighbourhoods overlap, under one of three
measures that differ only in what they divide by.
fn[G : @moongraph.Topology] square_clustering( graph : G, node : Int32, ) -> Double
The square clustering of a node: how many of the pairs of its neighbours that share a
non-neighbour are joined by a four-node square.
fn[G : @moongraph.Topology + @moongraph.Inbound] total_degree( graph : G, ) -> Array[Int32]
The number of edges on each node, both directions together.
fn[G : @moongraph.Topology] transitivity(graph : G) -> Double
Three times the number of triangles over the number of open triples: the chance that
two neighbours of a node are neighbours of each other, weighted by node.
fn[G : @moongraph.Topology] triangles(graph : G) -> (Array[Int32], Int32)
The triangles each node takes part in, and the number of them.
enum SimilarityKind
Which similarity measure to use.
moongraph/struct27 items
fn[G : @moongraph.Topology] bipartition(graph : G) -> Array[Int32]?
A two-colouring of the graph, or
None when an odd cycle makes one impossible.fn[G : @moongraph.Topology] core_numbers(graph : G) -> Array[Int32]
The core number of each node: the largest
k such that the node lies in a subgraph
where every node has at least k neighbours inside it.fn[G : @moongraph.Topology] d_separator( graph : G, x : Array[Int32], y : Array[Int32], z : Array[Int32], ) -> Bool
Whether the three sets separate the first two in the sense of d-separation: every
route between them meets the third.
fn[G : @moongraph.Topology + @moongraph.Inbound] is_arborescence( graph : G, ) -> Bool
Whether the directed graph is a tree with every edge pointing away from its root.
fn[G : @moongraph.Topology] is_at_free(graph : G) -> Bool
Whether the graph has no four nodes that induce exactly two edges with nothing else.
fn[G : @moongraph.Topology] is_bipartite(graph : G) -> Bool
Whether the graph has two colours.
fn[G : @moongraph.Topology + @moongraph.Inbound] is_branching( graph : G, ) -> Bool
Whether every node has at most one edge entering it.
fn is_digraphical(degrees : Array[(Int32, Int32)]) -> Bool
Whether the pairs can be the in- and out-degrees of a directed graph without
repeated edges.
fn[G : @moongraph.Topology] is_distance_regular(graph : G) -> Bool
Whether any two non-adjacent nodes have the same number of common neighbours.
fn[G : @moongraph.Topology] is_forest(graph : G) -> Bool
Whether every component is a tree.
fn is_graphical(degrees : Array[Int32]) -> Bool
Whether the degrees can be the degrees of a simple graph, by the Erdős-Gallai
criterion.
fn[G : @moongraph.Topology] is_isolate(graph : G, node : Int32) -> Bool
Whether a node has no edges.
fn is_multigraphical(degrees : Array[Int32]) -> Bool
Whether the degrees can be the degrees of a graph that may repeat an edge.
fn[G : @moongraph.Topology] is_planar(graph : G) -> Bool
Whether the graph can be drawn in the plane without crossed edges.
fn[G : @moongraph.Topology] is_regular(graph : G) -> Bool
Whether every node has the same degree.
fn[G : @moongraph.Topology] is_threshold(graph : G) -> Bool
Whether the graph is a threshold graph: one that can be built by adding isolated
nodes and dominating nodes one at a time.
fn[G : @moongraph.Topology] is_tournament(graph : G) -> Bool
Whether every pair of nodes has exactly one edge, in one direction or the other.
fn[G : @moongraph.Topology] is_tree(graph : G) -> Bool
Whether the graph is connected and has one edge fewer than nodes.
fn[G : @moongraph.Topology] isolates(graph : G) -> Array[Int32]
The nodes with no edges, ascending.
fn[G : @moongraph.Topology] k_core(graph : G, k : Int32) -> Array[Int32]
The nodes of the
k-core: the largest subgraph where every node has at least k
neighbours inside it.fn[G : @moongraph.Topology] k_shell(graph : G, k : Int32) -> Array[Int32]
The nodes of the
k-shell: in the k-core but not in the k+1-core.fn[G : @moongraph.Topology] k_truss(graph : G, k : Int32) -> Array[Int32]
The nodes of the
k-truss: the largest subgraph in which every edge lies in at
least k - 2 triangles inside it.fn[G : @moongraph.Topology] minimal_d_separator( graph : G, x : Array[Int32], y : Array[Int32], ) -> Array[Int32]?
A smallest set of nodes that separates the first two sets, or
None when they
cannot be separated.fn[G : @moongraph.Topology + @moongraph.Inbound] moral_graph( graph : G, ) -> @moongraph.Graph[Int32, Unit]
The moral graph: the graph with every pair of parents of a node joined, which turns
a directed model into one where separation is plain reachability.
fn[G : @moongraph.Topology] onion_layers(graph : G) -> Array[Int32]
The onion layer of each node: how many rounds of peeling it takes to strip the
graph down to it.
fn[G : @moongraph.Topology] planarity_embedding( graph : G, ) -> Array[Array[Int32]]?
A rotation system that draws the graph on a surface with no crossing, or
None when
no such drawing was found.fn[G : @moongraph.Topology] score_sequence(graph : G) -> Array[Int32]
The out-degree of each node, without the self-loops a tournament cannot have.
moongraph/iso4 items
fn[G : @moongraph.Topology] could_be_isomorphic(a : G, b : G) -> Bool
A cheap necessary condition: the same number of nodes, edges and the same degree
sequence. Two graphs that pass may still differ; two that fail cannot match.
fn[G : @moongraph.Topology] fast_could_be_isomorphic(a : G, b : G) -> Bool
The cheapest necessary condition there is: the same node and edge counts.
fn[G : @moongraph.Topology] is_isomorphic(a : G, b : G) -> Bool
Whether the two graphs are the same graph with the nodes renamed.
fn[G : @moongraph.Topology] vf2_mapping( a : G, b : G, ) -> @moongraph.Mapping?
A renaming that turns the first graph into the second, or
None when there is none.moongraph/op16 items
fn cartesian_product( a : @moongraph.Graph[Int32, Unit], b : @moongraph.Graph[Int32, Unit], ) -> @moongraph.Graph[Int32, Unit]
The pair graph: one node per pair of inputs, joined when both coordinates are joined.
fn[G : @moongraph.Topology] complement( graph : G, ) -> @moongraph.Graph[Int32, Unit]
The graph with the same nodes and the edges it does not have.
fn compose( a : @moongraph.Graph[Int32, Unit], b : @moongraph.Graph[Int32, Unit], ) -> @moongraph.Graph[Int32, Unit]
The graph with
b laid over a where their node numbers agree.fn contraction( graph : @moongraph.Graph[Int32, Unit], nodes : Array[Int32], ) -> @moongraph.Graph[Int32, Unit]
The graph with a set of nodes replaced by one: the contraction.
fn difference( a : @moongraph.Graph[Int32, Unit], b : @moongraph.Graph[Int32, Unit], ) -> @moongraph.Graph[Int32, Unit]
The edges of the first graph that the second does not have.
fn disjoint_union( a : @moongraph.Graph[Int32, Unit], b : @moongraph.Graph[Int32, Unit], ) -> @moongraph.Graph[Int32, Unit]
The two graphs side by side with the second one's numbers shifted up, so nothing
collides.
fn edge_subgraph( graph : @moongraph.Graph[Int32, Unit], edges : Array[Int32], ) -> @moongraph.Graph[Int32, Unit]
The part of the graph on the given edges, keeping the node numbers.
fn graph_power( graph : @moongraph.Graph[Int32, Unit], power : Int32, ) -> @moongraph.Graph[Int32, Unit]
The graph reached in at most
power steps of the input.fn intersection( a : @moongraph.Graph[Int32, Unit], b : @moongraph.Graph[Int32, Unit], ) -> @moongraph.Graph[Int32, Unit]
The graph that keeps the edges both inputs have.
fn line_graph( graph : @moongraph.Graph[Int32, Unit], ) -> @moongraph.Graph[Int32, Unit]
The line graph: one node per edge of the input, joined when the edges met.
fn reverse( graph : @moongraph.Graph[Int32, Unit], ) -> @moongraph.Graph[Int32, Unit]
The same edges with every direction turned around.
fn strong_product( a : @moongraph.Graph[Int32, Unit], b : @moongraph.Graph[Int32, Unit], ) -> @moongraph.Graph[Int32, Unit]
The strong product: an edge where either coordinate has one or both do.
fn subgraph( graph : @moongraph.Graph[Int32, Unit], nodes : Array[Int32], ) -> @moongraph.Graph[Int32, Unit]
The part of the graph on the given nodes, with the numbers renumbered from 0 in the order
the nodes are listed.
fn symmetric_difference( a : @moongraph.Graph[Int32, Unit], b : @moongraph.Graph[Int32, Unit], ) -> @moongraph.Graph[Int32, Unit]
The edges exactly one of the two graphs has.
fn tensor_product( a : @moongraph.Graph[Int32, Unit], b : @moongraph.Graph[Int32, Unit], ) -> @moongraph.Graph[Int32, Unit]
The tensor product: an edge where both coordinates have one.
fn union( a : @moongraph.Graph[Int32, Unit], b : @moongraph.Graph[Int32, Unit], ) -> @moongraph.Graph[Int32, Unit]
The graph that keeps every node and edge present in either input.
moongraph/approx7 items
fn[G : @moongraph.Topology] densest_subgraph(graph : G) -> Array[Int32]
The subgraph with the most edges per node, by peeling away the node of least degree until
the density stops rising.
fn[G : @moongraph.Topology] dominating_set(graph : G) -> Array[Int32]
A set of nodes every other node is joined to or part of, by taking the highest-degree node
until none is left uncovered.
fn[G : @moongraph.Topology] random_rewire( graph : G, rng~ : &@contract.Rng, ) -> @moongraph.Graph[Int32, Unit]
The graph with every edge cut and reattached somewhere else, keeping the degree sequence.
fn[G : @moongraph.Topology] spanner( graph : G, stretch~ : Int32 = 2, ) -> @moongraph.Graph[Int32, Unit]
A subgraph that keeps every short route short: the distance between any two nodes grows by
at most the given factor, and the spanner has far fewer edges than the original.
fn[G : @moongraph.Topology] traveling_salesman( graph : G, start~ : Int32, weight? : (Int32) -> Double, ) -> Array[Int32] raise @moongraph.Refused
A tour that visits every node and returns to the start, by taking the nearest unvisited
node each step and then straightening the result.
fn[G : @moongraph.Topology] treewidth_bound(graph : G) -> Int32
An upper bound on the treewidth, by eliminating the node of least degree and remembering
the largest neighbourhood that had to be made a clique.
fn[G : @moongraph.Topology] vertex_cover(graph : G) -> Array[Int32]
A set of nodes that touches every edge, at most twice the smallest such set.
moongraph/gen15 items
fn barabasi_albert( nodes : Int32, attach~ : Int32, rng~ : &@contract.Rng, ) -> @moongraph.Graph[Int32, Unit]
A preferential-attachment graph: every new node joins the existing ones that already
have the most edges, which is what makes the degree distribution heavy tailed.
fn barbell(nodes : Int32) -> @moongraph.Graph[Int32, Unit]
Two complete graphs joined by one edge: the graph a minimum cut is worst on.
fn complete( nodes : Int32, directed~ : Bool = false, ) -> @moongraph.Graph[Int32, Unit]
The complete graph on
nodes nodes: every pair joined.fn cycle(nodes : Int32) -> @moongraph.Graph[Int32, Unit]
A single cycle through every node.
fn grid(rows : Int32, columns : Int32) -> @moongraph.Graph[Int32, Unit]
A grid of
rows by columns nodes, each joined to the ones beside it.fn ladder(nodes : Int32) -> @moongraph.Graph[Int32, Unit]
Two paths with rungs between them: a ladder.
fn path( nodes : Int32, directed~ : Bool = false, ) -> @moongraph.Graph[Int32, Unit]
A path through every node, in number order.
fn petersen() -> @moongraph.Graph[Int32, Unit]
The Petersen graph: three nodes joined to three, with the matching inside each.
fn random_gnm( nodes : Int32, edges : Int32, rng~ : &@contract.Rng, directed~ : Bool = false, ) -> @moongraph.Graph[Int32, Unit]
A random graph with exactly
edges edges, drawn without repeats.fn random_gnp( nodes : Int32, probability~ : Double, rng~ : &@contract.Rng, directed~ : Bool = false, ) -> @moongraph.Graph[Int32, Unit]
A random graph in which every pair is joined with the same chance.
fn random_regular( nodes : Int32, degree~ : Int32, rng~ : &@contract.Rng, ) -> @moongraph.Graph[Int32, Unit]
A graph in which every node has the same number of edges, by repeatedly retrying pairs
until the degrees line up.
fn random_tree( nodes : Int32, rng~ : &@contract.Rng, ) -> @moongraph.Graph[Int32, Unit]
A tree grown at random: every new node joins one node already in the tree.
fn star(nodes : Int32) -> @moongraph.Graph[Int32, Unit]
One node joined to all the others, which are joined to nothing else.
fn watts_strogatz( nodes : Int32, neighbours~ : Int32, probability~ : Double, rng~ : &@contract.Rng, ) -> @moongraph.Graph[Int32, Unit]
A small-world graph: a ring with each node joined to its nearest neighbours and a few
edges rewired at random.
fn wheel(nodes : Int32) -> @moongraph.Graph[Int32, Unit]
A cycle with a hub in the middle joined to every node of it.
moongraph/io13 items
fn[G : @moongraph.Topology] adjacency_list(graph : G) -> String
A graph as an adjacency list: one line per node, starting with its number.
fn[G : @moongraph.Topology] edge_list( graph : G, data~ : Bool = false, ) -> String
A graph as an edge list: one
from to pair per line, an optional third column for the
weight, and # for comments.fn[G : @moongraph.Topology] gml(graph : G) -> String
A graph in GML: a nested list of key and value.
fn[G : @moongraph.Topology] graph6(graph : G) -> String
A graph in graph6: the node count in the first bytes, then one bit per possible edge.
fn[G : @moongraph.Topology] pajek(graph : G) -> String
A graph in Pajek's format: a vertex count, then the arcs.
fn parse_adjacency( text : StringView, directed~ : Bool = false, ) -> @moongraph.Graph[Unit, Unit] raise @moongraph.Refused
The graph an adjacency list describes.
fn parse_edges( text : StringView, directed~ : Bool = false, ) -> @moongraph.Graph[Unit, Double] raise @moongraph.Refused
The graph an edge list describes.
fn parse_gml( text : StringView, ) -> @moongraph.Graph[Unit, Unit] raise @moongraph.Refused
The graph a GML document describes.
fn parse_graph6( text : StringView, ) -> @moongraph.Graph[Unit, Unit] raise @moongraph.Refused
The graph a graph6 string describes.
fn parse_pajek( text : StringView, ) -> @moongraph.Graph[Unit, Unit] raise @moongraph.Refused
The graph a Pajek document describes. Node numbers are shifted down by one, because the
format counts from one.
fn parse_sparse6( text : StringView, ) -> @moongraph.Graph[Unit, Unit] raise @moongraph.Refused
The graph a sparse6 string describes.
fn[G : @moongraph.Topology] sparse6(graph : G) -> String
A graph in sparse6, which stores only the edges that are there.
fn[G : @moongraph.Topology] text(graph : G) -> String
A graph in a plain form, which is its adjacency list.
moongraph/io/graphml4 items
fn read(text : StringView) -> Loaded raise @moongraph.Refused
Reads a GraphML document.
fn[G : @moongraph.Topology] write( graph : G, labels~ : (Int32) -> String = fn(node)
Writes a graph as GraphML.
struct Keys
The keys a document declares, so that a caller can tell a label from a weight.
struct Loaded
A graph carrying node labels and edge weights.