Digraph cliques?

104 views
Skip to first unread message

Mike Edwards

unread,
Apr 29, 2009, 3:28:47 PM4/29/09
to networkx-discuss
I was wondering if NetworkX has the ability to find cliques in a
digraph? Almost like cliques in an undirected graph, but there would
have to be reciprocal connections between the nodes, per this section
in the Social Network Analysis book:

http://books.google.com/books?id=buiJi6HtGusC&pg=PA75&lpg=PA75&dq=digraph+clique&source=bl&ots=l1QQWhj6Qf&sig=ZAUqXXg9INeRmzV3ChgWz2BI58A&hl=en&ei=36j4SfXCMpfWlQfS5NzBCg&sa=X&oi=book_result&ct=result&resnum=1

Dan Schult

unread,
Apr 29, 2009, 8:58:27 PM4/29/09
to networkx...@googlegroups.com
Here's some code that will do what you ask about. It creates
a new undirected graph that has edges only when edges for
both directions exist in the original directed graph. It then
finds cliques and reports them. Since the cliques are just
lists of nodes, they work for the original graph too.

Dan



def find_directed_cliques(G):
"""
Convert G to an undirected graph with edges
present only if both directions are present in G.
Then find and return cliques.
"""
H=nx.Graph()
for u,v in G.edges():
if u in G[v]:
H.add_edge(u,v)
return nx.find_cliques(H)
Reply all
Reply to author
Forward
0 new messages