find cliques

364 views
Skip to first unread message

rsnowa...@gmail.com

unread,
Aug 7, 2007, 3:29:24 PM8/7/07
to networkx-discuss, r...@umdnj.edu
I am using NX.find_cliques(G) to find the cliques in a graph G, the
graph G contains a few hundred nodes. The returned list of cliques is
great. I want to graph the cliques so I tried
NX.make_max_clique_graph(G). This looks right, but the original labels
of the nodes have been replaced with 1, 2, 3, etc. How can I graph the
return from NX.find_cliques(G) so that the original labels are
retained. It'd be nice to restrict the new graph to include only
cliques with more than N nodes.

Thanks.

R.

Aric Hagberg

unread,
Aug 7, 2007, 4:39:17 PM8/7/07
to networkx...@googlegroups.com

You'll need to write a version of max_clique_graph that does this.
Here is a 5 minute solution that you can modify:

Aric

import networkx
def max_clique_graph(cliques,min_size=3):
"""
Create the maximal clique graph of a graph.
It finds the maximal cliques and treats these as nodes.
The nodes are connected if they have common members in
the original graph. Theory has done a lot with clique
graphs, but I haven't seen much on maximal clique graphs.

"""
G=networkx.Graph()
G.name='max clique graph'

for i in range(len(cliques)):
c=cliques[i]
if len(c)<min_size:
continue
label=' '.join(map(str,c))
G.add_node(label)
for j in range(i,len(cliques)):
other=cliques[j]
if len(other)<min_size:
continue
intersect=[w for w in c if w in other]
if intersect: # Not empty list, make connection
G.add_edge(label,' '.join(map(str,other)))
return G


if __name__ == "__main__":

G=networkx.generators.gnm_random_graph(10,20)
cliques=networkx.find_cliques(G)
H=max_clique_graph(cliques)

rsnowa...@gmail.com

unread,
Aug 8, 2007, 3:24:47 PM8/8/07
to networkx-discuss
Thanks. I see now how I can do this. Thanks for the really useful
program.

How do I cite this in publications?

On Aug 7, 4:39 pm, Aric Hagberg <hagb...@lanl.gov> wrote:

Aric Hagberg

unread,
Aug 8, 2007, 5:56:21 PM8/8/07
to networkx...@googlegroups.com
On Wed, Aug 08, 2007 at 07:24:47PM -0000, rsnowa...@gmail.com wrote:
>
> Thanks. I see now how I can do this. Thanks for the really useful
> program.
>
> How do I cite this in publications?

Right now the best thing to do is cite the web page.
I'll put a note on the web site for the citation information
for future reference.

Aric

Reply all
Reply to author
Forward
0 new messages