[英]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
的解决方案。
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.