5

I'm working with graphs of ~200 nodes and ~3500 edges. 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.

"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()

Is there maybe a way to return a generator of all cliques of length k, instead of all cliques, in order to save memory?

Daenyth
  • 35,856
  • 13
  • 85
  • 124
TobSta
  • 766
  • 2
  • 10
  • 29

1 Answers1

3

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.

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

Maximal 2522

And when the number of edges increases in the graph the difference in results gets wider.

Abdallah Sobehy
  • 2,881
  • 1
  • 15
  • 28