Yog.Multi (YogEx v0.98.0)

Copy Markdown View Source

Unified facade for multigraph operations.

Multigraphs allow multiple (parallel) edges between the same pair of nodes. This module provides creation, modification, traversal, and algorithmic analysis for multigraphs by delegating to specialized submodules.

Summary

Functions

Adds an edge to the multigraph, returning {updated_graph, edge_id}.

Adds a node to the multigraph.

Returns all edge IDs in the graph.

Returns all node IDs in the multigraph.

Performs a Breadth-First Search from source.

Returns the total degree of a node (in-degree + out-degree for directed, out-degree for undirected).

Performs a Depth-First Search from source.

Creates a new empty directed multigraph.

Returns the number of parallel edges between from and to.

Returns all parallel edges between from and to as [{edge_id, data}].

Finds an Eulerian circuit using Hierholzer's algorithm.

Finds an Eulerian path using Hierholzer's algorithm.

Folds over nodes during multigraph traversal with metadata.

Checks if the multigraph contains at least one cycle.

Checks if a specific edge_id exists in the multigraph.

Checks if the multigraph has an Eulerian circuit.

Checks if the multigraph has an Eulerian path.

Returns the in-degree of a node.

Creates a new empty multigraph of the given type.

Returns the number of nodes.

Returns the out-degree of a node.

Returns all incoming edges to id as [{from_node, edge_id, data}].

Removes a single edge by its EdgeId.

Removes a node and all edges connected to it.

Returns the total number of edges.

Returns all outgoing edges from id as [{to_node, edge_id, data}].

Collapses the multigraph into a simple graph, keeping only the first edge between each pair.

Collapses the multigraph into a simple graph using a combining function.

Collapses parallel edges, keeping the minimum weight.

Collapses parallel edges, summing weights with the provided function.

Returns a topological ordering of nodes (directed multigraphs only).

Creates a new empty undirected multigraph.

Functions

add_edge(graph, from, to, data)

Adds an edge to the multigraph, returning {updated_graph, edge_id}.

add_node(graph, id, data)

Adds a node to the multigraph.

all_edge_ids(graph)

Returns all edge IDs in the graph.

all_nodes(graph)

Returns all node IDs in the multigraph.

bfs(graph, source)

Performs a Breadth-First Search from source.

degree(graph, id)

Returns the total degree of a node (in-degree + out-degree for directed, out-degree for undirected).

dfs(graph, source)

Performs a Depth-First Search from source.

directed()

Creates a new empty directed multigraph.

edge_count(graph, from, to)

Returns the number of parallel edges between from and to.

edges_between(graph, from, to)

Returns all parallel edges between from and to as [{edge_id, data}].

find_eulerian_circuit(graph)

Finds an Eulerian circuit using Hierholzer's algorithm.

find_eulerian_path(graph)

Finds an Eulerian path using Hierholzer's algorithm.

fold_walk(graph, from, initial, folder)

Folds over nodes during multigraph traversal with metadata.

has_cycle?(graph)

@spec has_cycle?(Yog.Multi.Model.t()) :: boolean()

Checks if the multigraph contains at least one cycle.

Collapses parallel edges internally before checking.

has_edge(graph, edge_id)

Checks if a specific edge_id exists in the multigraph.

has_eulerian_circuit?(graph)

Checks if the multigraph has an Eulerian circuit.

has_eulerian_path?(graph)

Checks if the multigraph has an Eulerian path.

in_degree(graph, id)

Returns the in-degree of a node.

new(kind)

Creates a new empty multigraph of the given type.

order(graph)

Returns the number of nodes.

out_degree(graph, id)

Returns the out-degree of a node.

predecessors(graph, id)

Returns all incoming edges to id as [{from_node, edge_id, data}].

remove_edge(graph, edge_id)

Removes a single edge by its EdgeId.

remove_node(graph, id)

Removes a node and all edges connected to it.

size(graph)

Returns the total number of edges.

successors(graph, id)

Returns all outgoing edges from id as [{to_node, edge_id, data}].

to_simple_graph(graph)

Collapses the multigraph into a simple graph, keeping only the first edge between each pair.

to_simple_graph(graph, combine_fn)

Collapses the multigraph into a simple graph using a combining function.

to_simple_graph_min_edges(graph)

Collapses parallel edges, keeping the minimum weight.

to_simple_graph_sum_edges(graph, add)

Collapses parallel edges, summing weights with the provided function.

topological_sort(graph)

@spec topological_sort(Yog.Multi.Model.t()) ::
  {:ok, [Yog.node_id()]} | {:error, :contains_cycle}

Returns a topological ordering of nodes (directed multigraphs only).

Collapses parallel edges internally, then applies Kahn's algorithm. Returns {:ok, [node_id]} or {:error, :contains_cycle}.

undirected()

Creates a new empty undirected multigraph.