本文簡要介紹
networkx.algorithms.connectivity.edge_kcomponents.EdgeComponentAuxGraph
的用法。用法:
class EdgeComponentAuxGraph
在圖中查找所有k-edge-connected 組件的簡單算法。
構造AuxillaryGraph(可能需要一些時間)允許在任意k 的線性時間內找到k-edge-ccs。
注意:
該實現基於[1]。這個想法是構建一個輔助圖,可以在線性時間內提取k-edge-ccs。輔助圖是在 操作中構造的,其中F是最大流的複雜度。查詢組件需要額外的 操作。該算法對於大型圖來說可能很慢,但它可以處理任意 k 並且適用於有向和無向輸入。
k=1 的無向情況是完全連通的分量。 k=2 的無向情況正好是橋接組件。 k=1 的有向情況是完全強連通分量。
參考:
- 1
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 >>> from networkx.algorithms.connectivity import EdgeComponentAuxGraph >>> # Build an interesting graph with multiple levels of k-edge-ccs >>> paths = [ ... (1, 2, 3, 4, 1, 3, 4, 2), # a 3-edge-cc (a 4 clique) ... (5, 6, 7, 5), # a 2-edge-cc (a 3 clique) ... (1, 5), # combine first two ccs into a 1-edge-cc ... (0,), # add an additional disconnected 1-edge-cc ... ] >>> G = nx.Graph() >>> G.add_nodes_from(it.chain(*paths)) >>> G.add_edges_from(it.chain(*[pairwise(path) for path in paths])) >>> # Constructing the AuxGraph takes about O(n ** 4) >>> aux_graph = EdgeComponentAuxGraph.construct(G) >>> # Once constructed, querying takes O(n) >>> sorted(map(sorted, aux_graph.k_edge_components(k=1))) [[0], [1, 2, 3, 4, 5, 6, 7]] >>> sorted(map(sorted, aux_graph.k_edge_components(k=2))) [[0], [1, 2, 3, 4], [5, 6, 7]] >>> sorted(map(sorted, aux_graph.k_edge_components(k=3))) [[0], [1, 2, 3, 4], [5], [6], [7]] >>> sorted(map(sorted, aux_graph.k_edge_components(k=4))) [[0], [1], [2], [3], [4], [5], [6], [7]]
輔助圖主要用於k-edge-ccs,但它也可以通過優化搜索空間來加速k-edge-subgraphs的查詢。
>>> import itertools as it >>> from networkx.utils import pairwise >>> from networkx.algorithms.connectivity import EdgeComponentAuxGraph >>> paths = [ ... (1, 2, 4, 3, 1, 4), ... ] >>> G = nx.Graph() >>> G.add_nodes_from(it.chain(*paths)) >>> G.add_edges_from(it.chain(*[pairwise(path) for path in paths])) >>> aux_graph = EdgeComponentAuxGraph.construct(G) >>> sorted(map(sorted, aux_graph.k_edge_subgraphs(k=3))) [[1], [2], [3], [4]] >>> sorted(map(sorted, aux_graph.k_edge_components(k=3))) [[1, 4], [2], [3]]
相關用法
- Python NetworkX negative_edge_cycle用法及代碼示例
- Python NetworkX voronoi_cells用法及代碼示例
- Python NetworkX numerical_edge_match用法及代碼示例
- Python NetworkX inverse_line_graph用法及代碼示例
- Python NetworkX LFR_benchmark_graph用法及代碼示例
- Python NetworkX write_graph6用法及代碼示例
- Python NetworkX DiGraph.__contains__用法及代碼示例
- Python NetworkX average_degree_connectivity用法及代碼示例
- Python NetworkX eulerian_circuit用法及代碼示例
- Python NetworkX single_source_dijkstra_path_length用法及代碼示例
- Python NetworkX from_dict_of_dicts用法及代碼示例
- Python NetworkX weisfeiler_lehman_subgraph_hashes用法及代碼示例
- Python NetworkX transitive_closure_dag用法及代碼示例
- Python NetworkX intersection用法及代碼示例
- Python NetworkX MultiGraph.size用法及代碼示例
- Python NetworkX Graph.size用法及代碼示例
- Python NetworkX from_scipy_sparse_array用法及代碼示例
- Python NetworkX local_and_global_consistency用法及代碼示例
- Python NetworkX number_of_selfloops用法及代碼示例
- Python NetworkX single_source_bellman_ford用法及代碼示例
- Python NetworkX all_simple_paths用法及代碼示例
- Python NetworkX Graph.to_undirected用法及代碼示例
- Python NetworkX numeric_assortativity_coefficient用法及代碼示例
- Python NetworkX binomial_graph用法及代碼示例
- Python NetworkX dedensify用法及代碼示例
注:本文由純淨天空篩選整理自networkx.org大神的英文原創作品 networkx.algorithms.connectivity.edge_kcomponents.EdgeComponentAuxGraph。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。