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


Python NetworkX k_components用法及代碼示例

本文簡要介紹 networkx.algorithms.connectivity.kcomponents.k_components 的用法。

用法:

k_components(G, flow_func=None)

返回圖 G 的 k-component 結構。

k - 組件是圖 G 的最大子圖,它至少具有節點連接性 k :我們需要至少刪除 k 節點才能將其分解為更多組件。 k - 組件具有固有的層次結構,因為它們在連接性方麵是嵌套的:連接圖可以包含多個 2 組件,每個組件都可以包含一個或多個 3 組件,依此類推。

參數

GNetworkX 圖
flow_func函數

執行底層流計算的函數。默認值 edmonds_karp() 。此函數在具有右尾度分布的稀疏圖中表現更好。 shortest_augmenting_path() 在更密集的圖中表現更好。

返回

k_componentsdict

字典,輸入圖表中的所有連接級別 k 作為鍵,形成級別 k 的 k-component 的節點集列表作為值。

拋出

NetworkXNotImplemented

如果輸入圖是有向的。

注意

Moody 和 White [1](附錄 A)提供了一種識別圖中 k-components 的算法,該算法基於 Kanevsky 算法 [2],用於查找圖中的所有 minimum-size 節點 cut-sets(在 all_node_cuts() 中實現)函數):

  1. 計算輸入圖 G 的節點連通性 k。

  2. 使用 Kanevsky 算法識別當前連接級別的所有k-cutsets。

  3. 基於刪除這些割集生成新的圖組件。割集中的節點屬於誘導割的兩側。

  4. 如果圖既不完整也不平凡,返回1;否則結束。

此實現還使用一些啟發式方法(有關詳細信息,請參閱[3])來加速計算。

參考

1

Moody, J. and D. White (2003). Social cohesion and embeddedness: A hierarchical conception of social groups. American Sociological Review 68(1), 103-28. http://www2.asanet.org/journals/ASRFeb03MoodyWhite.pdf

2

Kanevsky, A. (1993). Finding all minimum-size separating vertex sets in a graph. Networks 23(6), 533-541. http://onlinelibrary.wiley.com/doi/10.1002/net.3230230604/abstract

3

Torrents, J. and F. Ferraro (2015). Structural Cohesion: Visualization and Heuristics for Fast Computation. https://arxiv.org/pdf/1503.04476v1

例子

>>> # Petersen graph has 10 nodes and it is triconnected, thus all
>>> # nodes are in a single component on all three connectivity levels
>>> G = nx.petersen_graph()
>>> k_components = nx.k_components(G)

相關用法


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