k_edge_components#
- k_edge_components(G, k)[source]#
生成 G 中每个极大 k-边连通分量中的节点。
- 参数:
- GNetworkX 图
- k整数
所需的边连通性
- 返回:
- k_edge_components一个 k-边连通分量的生成器。返回的每个节点集
在图 G 中将具有 k-边连通性。
- 引发:
- NetworkXNotImplemented
如果输入图是多重图。
- ValueError
如果 k 小于 1
另请参阅
local_edge_connectivity()
k_edge_subgraphs()
类似于此函数,但由节点定义的子图也必须具有 k-边连通性。
k_components()
类似于此函数,但使用节点连通性而非边连通性
注释
尝试根据 k 使用最有效的实现。如果 k=1,对于有向图和无向图,这只是简单连通分量。如果 k=2,则基于链分解运行来自 _[1] 的高效桥连通分量算法。否则,使用来自 _[2] 的算法。
参考文献
[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]]