Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add edge betweenness centrality #799

Merged
merged 12 commits into from
Mar 9, 2023
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ the functions from the explicitly typed based on the data type.
rustworkx.digraph_spring_layout
rustworkx.digraph_num_shortest_paths_unweighted
rustworkx.digraph_betweenness_centrality
rustworkx.digraph_edge_betweenness_centrality
rustworkx.digraph_eigenvector_centrality
rustworkx.digraph_unweighted_average_shortest_path_length
rustworkx.digraph_bfs_search
Expand Down Expand Up @@ -374,6 +375,7 @@ typed API based on the data type.
rustworkx.graph_spring_layout
rustworkx.graph_num_shortest_paths_unweighted
rustworkx.graph_betweenness_centrality
rustworkx.graph_edge_betweenness_centrality
rustworkx.graph_eigenvector_centrality
rustworkx.graph_unweighted_average_shortest_path_length
rustworkx.graph_bfs_search
Expand Down Expand Up @@ -416,6 +418,7 @@ Custom Return Types
rustworkx.AllPairsPathMapping
rustworkx.AllPairsPathLengthMapping
rustworkx.CentralityMapping
rustworkx.EdgeCentralityMapping
rustworkx.Chains
rustworkx.NodeMap
rustworkx.ProductNodeMap
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
features:
- |
Added a new function, :func:`~rustworkx.edge_betweenness_centrality` to compute
edge betweenness centrality of all edges in a :class:`~rustworkx.PyGraph` or
:class:`~rustworkx.PyDiGraph` object. The algorithm used in this function is
based on:
Ulrik Brandes, On Variants of Shortest-Path Betweenness Centrality
and their Generic Computation. Social Networks 30(2):136-145, 2008.
Edge betweenness centrality of an edge :math:`e` is the sum of the
fraction of all-pairs shortest paths that pass through :math`e`

.. math::

c_B(e) =\sum_{s,t \in V} \frac{\sigma(s, t|e)}{\sigma(s, t)}

where :math:`V` is the set of nodes, :math:`\sigma(s, t)` is the
number of shortest :math:`(s, t)`-paths, and :math:`\sigma(s, t|e)` is
the number of those paths passing through edge :math:`e`.
For example, the following computes the edge betweenness centrality for all
edges in a 5x5 grid graph and uses the result to color the edges in a graph
visualization:

.. jupyter-execute::

import rustworkx
from rustworkx.visualization import mpl_draw

graph = rustworkx.generators.grid_graph(5, 5)
btw = rustworkx.edge_betweenness_centrality(graph)
# Color edges in graph visualization with edge betweenness centrality
colors = []
for i in graph.edge_indices():
colors.append(btw[i])
mpl_draw(graph, edge_color=colors)
- |
Added a new function to rustworkx-core ``edge_betweenness_centrality`` to
the ``rustworkx_core:centrality`` module which computes the edge betweenness
centrality of all edges in a given graph.
1 change: 1 addition & 0 deletions rustworkx-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ petgraph = "0.6.2"
rayon = "1.6"
num-traits = "0.2"
priority-queue = "1.2"
rayon-cond = "0.2"

[dependencies.hashbrown]
version = "0.12"
Expand Down
Loading