简体   繁体   English

在图中查找长度为k的派系

[英]Find cliques of length k in a graph

I'm working with graphs of ~200 nodes and ~3500 edges. 我正在使用~200个节点和~3500个边缘的图形。 I need to find all cliques of this graph. 我需要找到这张图的所有派系。 Using networkx's enumerate_all_cliques() works fine with smaller graphs of up to 100 nodes, but runs out of memory for bigger ones. 使用networkx的enumerate_all_cliques()可以处理最多100个节点的较小图形,但是对于较大的节点,内存不足。

"This algorithm however, hopefully, does not run out of memory since it only keeps candidate sublists in memory and continuously removes exhausted sublists." “但是,希望这个算法不会耗尽内存,因为它只会将候选子列表保留在内存中并不断删除耗尽的子列表。” source code for enumerate_all_cliques() enumerate_all_cliques()的源代码

Is there maybe a way to return a generator of all cliques of length k, instead of all cliques, in order to save memory? 是否有办法返回长度为k的所有派系的生成器,而不是所有派系,以节省内存?

It seems that your priority is to save memory rather than getting all cliques. 看来你的首要任务是节省内存而不是获得所有派系。 In that case the use of networkx.find_cliques(G) is a satisfactory solution as you will get all maximal cliques (largest complete subgraph containing a given node) instead of all cliques. 在这种情况下,使用networkx.find_cliques(G)是一个令人满意的解决方案,因为您将获得所有最大派系(包含给定节点的最大完整子图)而不是所有派系。

I compared the number of lists (subgraphs) of both functions: 我比较了两个函数的列表(子图)的数量:

G = nx.erdos_renyi_graph(300,0.08) print 'All:',len(list(nx.enumerate_all_cliques(G))) print 'Maximal',len(list(nx.find_cliques(G)))

All: 6087 全部:6087

Maximal 2522 最大2522

And when the number of edges increases in the graph the difference in results gets wider. 并且当图中边缘的数量增加时,结果的差异变得更大。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM