# `Yog.Pathfinding.Brandes`
[🔗](https://github.com/code-shoily/yog_ex/blob/v0.98.5/lib/yog/pathfinding/brandes.ex#L1)

Ulrik Brandes' algorithm for betweenness centrality.

This module provides the core building blocks for computing node and edge
betweenness centrality. The algorithm consists of two phases:
1. **Discovery**: A Dijkstra-like breadth-first search to find shortest paths.
2. **Accumulation**: A back-propagation phase to calculate dependencies.

## Reference

Brandes, U. (2001). A faster algorithm for betweenness centrality.
Journal of Mathematical Sociology, 25(2), 163-177.

# `discovery_result`

```elixir
@type discovery_result() ::
  {[Yog.node_id()], %{required(Yog.node_id()) =&gt; [Yog.node_id()]},
   %{required(Yog.node_id()) =&gt; number()}}
```

# `accumulate_edge_dependencies`

```elixir
@spec accumulate_edge_dependencies(
  [Yog.node_id()],
  %{required(Yog.node_id()) =&gt; [Yog.node_id()]},
  %{
    required(Yog.node_id()) =&gt; number()
  }
) :: %{required({Yog.node_id(), Yog.node_id()}) =&gt; float()}
```

Accumulates edge dependencies for betweenness calculation.

Returns a map of `{u, v}` pairs (where u < v) to their dependency scores.

# `accumulate_node_dependencies`

```elixir
@spec accumulate_node_dependencies(
  [Yog.node_id()],
  %{required(Yog.node_id()) =&gt; [Yog.node_id()]},
  %{
    required(Yog.node_id()) =&gt; number()
  }
) :: %{required(Yog.node_id()) =&gt; float()}
```

Accumulates node dependencies for betweenness calculation.

Returns a map of node IDs to their dependency scores.

# `discovery`

```elixir
@spec discovery(
  Yog.graph(),
  Yog.node_id(),
  weight,
  (weight, weight -&gt; weight),
  (weight, weight -&gt;
     :lt | :eq | :gt)
) ::
  discovery_result()
when weight: var
```

Runs the discovery phase of Brandes' algorithm.

Returns a tuple `{stack, predecessors, sigmas}`:
- `stack`: Nodes in non-decreasing order of distance.
- `predecessors`: A map from node to a list of its predecessors on all shortest paths.
- `sigmas`: A map from node to the number of shortest paths from source to it.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
