Oi.Topology.Graph (oi v0.7.0)

Copy Markdown

The pure mathematical representation of the DAG.

Summary

Functions

Get all input edges pointing to a given node

Get all output edges emanating from a given node.

Validate graph structure and return topological order on success.

Types

t()

@type t() :: t(term())

t(container_type)

@type t(container_type) :: %Oi.Topology.Graph{
  edges: MapSet.t(Oi.Topology.Graph.Edge.t()),
  in_edges: %{
    required(Oi.Topology.Graph.Node.id()) => [Oi.Topology.Graph.Edge.t()]
  },
  nodes: %{
    required(Oi.Topology.Graph.Node.id()) =>
      Oi.Topology.Graph.Node.t(container_type)
  },
  out_edges: %{
    required(Oi.Topology.Graph.Node.id()) => [Oi.Topology.Graph.Edge.t()]
  }
}

Functions

add_edge(graph, edge)

add_node(graph, node)

get_in_edges(graph, node_id)

@spec get_in_edges(t(), Oi.Topology.Graph.Node.id()) :: [Oi.Topology.Graph.Edge.t()]

Get all input edges pointing to a given node

get_out_edges(graph, node_id)

@spec get_out_edges(t(), Oi.Topology.Graph.Node.id()) :: [Oi.Topology.Graph.Edge.t()]

Get all output edges emanating from a given node.

new()

remove_edge(graph, edge)

remove_node(graph, node_id)

same?(graph1, graph2)

topological_sort(graph)

@spec topological_sort(t()) ::
  {:ok, [Oi.Topology.Graph.Node.id()]} | {:error, [Oi.Topology.Graph.Node.id()]}

update_node(graph, node_id, new_node)

validate(graph)

@spec validate(t()) ::
  {:ok, [Oi.Topology.Graph.Node.id()]} | {:error, [{atom(), term()}]}

Validate graph structure and return topological order on success.

Returns {:ok, sorted_node_ids} or {:error, reasons} where reasons is a list of {tag, detail} tuples.

Checks:

  • No orphan edges — from_node / to_node must exist in graph.nodes
  • Port membership — from_port must be in the source node's outputs, to_port must be in the target node's inputs
  • No cycles (topological sort)