简体   繁体   English

从 NetworkX 图中查找连接组件内的子图

[英]Find Subgraphs inside a Connected Component from a NetworkX Graph

I have built a NetworkX Graph containing 50000 Nodes and about 100 Million edges.我已经构建了一个包含 50000 个节点和大约 1 亿条边的 NetworkX Graph。 I have a list of all connected components of this group using nx.connected_components(G) method.我使用 nx.connected_components(G) 方法列出了该组的所有连接组件。 This method results in me having clusters of nodes such that each node has a path to reach every other node in that cluster.这种方法导致我拥有节点集群,这样每个节点都有一条路径可以到达该集群中的每个其他节点。 Now what I want is, in each of these connected components, I want to find subgraphs/sub-clusters such that each of these subgraphs are connected to each other by exactly one edge.现在我想要的是,在这些连接的组件中的每一个中,我想找到子图/子簇,以便这些子图中的每一个都通过一条边相互连接。 Is there a method in NetworkX that I can use directly or any other way in which I can get this done? NetworkX 中是否有我可以直接使用的方法或任何其他可以完成此操作的方法? Sorry I am very new to graph theory so need a little direction.对不起,我对图论很陌生,所以需要一点指导。

What you want is called minimum spanning three .你想要的是最小跨越三 Using networkx you can do it like this:使用networkx你可以这样做:

import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edges_from([(1,2), (1,3), (2,3), (4,5), (4,6), (5,6)])
nx.draw(nx.minimum_spanning_tree(G), with_labels=True)
plt.show()

However, I'm a little bit in doubt if networkx is able to perform on so many edges according to this benchmark .但是,我有点怀疑networkx是否能够根据此基准测试在如此多的边缘上执行。 I have tested connected components algorithm on igraph , it worked for me as well (and, of course, much faster), so you might also like to look for igraph based solutions.我已经在igraph上测试了connected components算法,它也对我igraph (当然,速度要快得多),因此您可能还想寻找基于igraph的解决方案。

Result结果

在此处输入图片说明

If I understand you correctly, then for each subgraph, you want to find all graph cuts of size 1, ie you want to find all edges, that if taken away partition the graph into two subgraphs.如果我理解正确,那么对于每个子图,您想找到大小为 1 的所有图切割,即您想找到所有边,如果去掉,则将图划分为两个子图。 These edges are called bridges and there are efficient algorithms to find them.这些边被称为,有有效的算法可以找到它们。 The implementation in networkx is accessible via networkx.algorithms.bridges.bridges . networkx 中的实现可以通过networkx.algorithms.bridges.bridges访问。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 完全连接来自networkx中较大图形的子图 - completely connected subgraphs from a larger graph in networkx 继承networkx图并使用nx.connected_component_subgraphs - inheriting networkx Graph and using nx.connected_component_subgraphs 如何在NetworkX中仅绘制前50-100个连接的组件子图; 一次绘制多个子图 - How to graph only top 50-100 connected component subgraphs in NetworkX; drawing multiple subgraphs at once AttributeError:模块“networkx”没有属性“connected_component_subgraphs” - AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs' 如何使用.networkx 查找强连通分量的子图 - How to find subgraphs of strongly connected components using networkx 如何在.networkx 中找到一个图的所有连通子图? - How to find all connected subgraph of a graph in networkx? networkx 库更新 nx.connected_component_subgraphs(G) 后,此错误生成 - after networkx library update nx.connected_component_subgraphs(G), this error genarated Networkx:提取包含给定节点的连通组件(有向图) - Networkx: extract the connected component containing a given node (directed graph) 如何使用networkx从给定图形中提取所有可能的诱导子图 - How can I extract all possible induced subgraphs from a given graph with networkx Python-IGraph / Networkx:在连接的图中查找特定节点的群集 - Python-IGraph / Networkx: Find clusters of specific nodes in connected graph
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM