Yog.Connectivity (YogEx v0.70.0)

Copy Markdown View Source

Graph connectivity analysis - finding connected components, bridges, articulation points, strongly connected components, and k-core decomposition.

This module provides a unified API for analyzing the connectivity structure of graphs.

Algorithms

Connectivity Analysis

  • analyze/1 - Find bridges and articulation points (undirected).

Strongly Connected Components (Directed)

(Weakly) Connected Components

Higher-Order Connectivity

Summary

Functions

Analyzes an undirected graph to find all bridges and articulation points.

Finds Connected Components in an undirected graph.

Calculates all core numbers for all nodes in the graph.

Finds the degeneracy of the graph, which is the maximum core number.

Extracts the k-core of a graph (maximal subgraph with minimum degree k).

Finds Strongly Connected Components (SCC) using Kosaraju's Algorithm.

Finds Strongly Connected Components (SCC) using Tarjan's Algorithm.

Finds Weakly Connected Components in a directed graph.

Types

bridge()

@type bridge() :: Yog.Connectivity.Analysis.bridge()

component()

@type component() :: Yog.Connectivity.Components.component()

connectivity_results()

@type connectivity_results() :: Yog.Connectivity.Analysis.connectivity_results()

Functions

analyze(options_or_graph)

@spec analyze(keyword() | Yog.graph()) :: connectivity_results()

Analyzes an undirected graph to find all bridges and articulation points.

Examples

iex> graph = Yog.undirected()
...> |> Yog.add_node(1, nil)
...> |> Yog.add_node(2, nil)
...> |> Yog.add_node(3, nil)
...> |> Yog.add_edge!(from: 1, to: 2, with: nil)
...> |> Yog.add_edge!(from: 2, to: 3, with: nil)
iex> results = Yog.Connectivity.analyze(in: graph)
iex> results.bridges
[{1, 2}, {2, 3}]
iex> results.articulation_points
[2]

connected_components(graph)

@spec connected_components(Yog.graph()) :: [component()]

Finds Connected Components in an undirected graph.

Example

iex> graph = Yog.undirected()
...> |> Yog.add_node(1, "A")
...> |> Yog.add_node(2, "B")
...> |> Yog.add_node(3, "C")
...> |> Yog.add_node(4, "D")
...> |> Yog.add_edge!(from: 1, to: 2, with: 1)
...> |> Yog.add_edge!(from: 3, to: 4, with: 1)
iex> components = Yog.Connectivity.connected_components(graph)
iex> Enum.map(components, &Enum.sort/1) |> Enum.sort()
[[1, 2], [3, 4]]

core_numbers(graph)

@spec core_numbers(Yog.graph()) :: %{required(Yog.node_id()) => integer()}

Calculates all core numbers for all nodes in the graph.

degeneracy(graph)

@spec degeneracy(Yog.graph()) :: integer()

Finds the degeneracy of the graph, which is the maximum core number.

k_core(graph, k)

@spec k_core(Yog.graph(), integer()) :: Yog.graph()

Extracts the k-core of a graph (maximal subgraph with minimum degree k).

Examples

iex> graph = Yog.undirected()
...> |> Yog.add_edge_ensure(1, 2, 1, nil)
...> |> Yog.add_edge_ensure(2, 3, 1, nil)
...> |> Yog.add_edge_ensure(3, 4, 1, nil)
...> |> Yog.add_edge_ensure(4, 1, 1, nil)
iex> core_2 = Yog.Connectivity.k_core(graph, 2)
iex> Yog.node_count(core_2)
4

kosaraju(graph)

@spec kosaraju(Yog.graph()) :: [[Yog.node_id()]]

Finds Strongly Connected Components (SCC) using Kosaraju's Algorithm.

Example

iex> graph = Yog.directed()
...> |> Yog.add_node(1, "A")
...> |> Yog.add_node(2, "B")
...> |> Yog.add_node(3, "C")
...> |> Yog.add_edge!(from: 1, to: 2, with: 1)
...> |> Yog.add_edge!(from: 2, to: 3, with: 1)
...> |> Yog.add_edge!(from: 3, to: 1, with: 1)
iex> sccs = Yog.Connectivity.kosaraju(graph)
iex> hd(sccs) |> Enum.sort()
[1, 2, 3]

scc(graph)

@spec scc(Yog.graph()) :: [[Yog.node_id()]]

Alias for strongly_connected_components/1.

strongly_connected_components(graph)

@spec strongly_connected_components(Yog.graph()) :: [[Yog.node_id()]]

Finds Strongly Connected Components (SCC) using Tarjan's Algorithm.

weakly_connected_components(graph)

@spec weakly_connected_components(Yog.graph()) :: [component()]

Finds Weakly Connected Components in a directed graph.

Example

iex> graph = Yog.directed()
...> |> Yog.add_node(1, "A")
...> |> Yog.add_node(2, "B")
...> |> Yog.add_node(3, "C")
...> |> Yog.add_edge!(from: 1, to: 2, with: 1)
...> |> Yog.add_edge!(from: 3, to: 2, with: 1)
iex> wccs = Yog.Connectivity.weakly_connected_components(graph)
iex> hd(wccs) |> Enum.sort()
[1, 2, 3]