當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python NetworkX k_edge_components用法及代碼示例

本文簡要介紹 networkx.algorithms.connectivity.edge_kcomponents.k_edge_components 的用法。

用法:

k_edge_components(G, k)

在 G 中的每個最大 k-edge-connected 分量中生成節點。

參數

GNetworkX 圖
k整數

所需的邊連接

返回

k_edge_componentsk-edge-ccs 的生成器。每組返回節點

在圖 G 中將有 k-edge-connectivity。

拋出

NetworkXNotImplemented

如果輸入圖是多重圖。

ValueError:

如果 k 小於 1

注意

嘗試使用基於 k 的最有效的實現。如果 k=1,這對於有向圖是簡單的連通分量,對於無向圖是連通分量。如果在 _[1] 的有效橋接組件算法上 k=2,則基於鏈分解運行。否則,使用 _[2] 中的算法。

參考

1

https://en.wikipedia.org/wiki/Bridge_%28graph_theory%29

2

Wang, Tianhao, et al. (2015) A simple algorithm for finding all k-edge-connected components. http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0136264

例子

>>> import itertools as it
>>> from networkx.utils import pairwise
>>> paths = [
...     (1, 2, 4, 3, 1, 4),
...     (5, 6, 7, 8, 5, 7, 8, 6),
... ]
>>> G = nx.Graph()
>>> G.add_nodes_from(it.chain(*paths))
>>> G.add_edges_from(it.chain(*[pairwise(path) for path in paths]))
>>> # note this returns {1, 4} unlike k_edge_subgraphs
>>> sorted(map(sorted, nx.k_edge_components(G, k=3)))
[[1, 4], [2], [3], [5, 6, 7, 8]]

相關用法


注:本文由純淨天空篩選整理自networkx.org大神的英文原創作品 networkx.algorithms.connectivity.edge_kcomponents.k_edge_components。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。