find_cliques(G, nodes=None)
For each node n, a maximal clique for n is a largest complete subgraph containing n. The largest maximal clique is sometimes called the maximum clique.
This function returns an iterator over cliques, each of which is a list of nodes. It is an iterative implementation, so should not suffer from recursion depth issues.
This function accepts a list of nodes
and only the maximal cliques containing all of these nodes
are returned. It can considerably speed up the running time if some specific cliques are desired.
To obtain a list of all maximal cliques, use :None:None:`list(find_cliques(G))`
. However, be aware that in the worst-case, the length of this list can be exponential in the number of nodes in the graph. This function avoids storing all cliques in memory by only keeping current candidate node lists in memory during its search.
This implementation is based on the algorithm published by Bron and Kerbosch (1973) , as adapted by Tomita, Tanaka and Takahashi (2006) and discussed in Cazals and Karande (2008) . It essentially unrolls the recursion used in the references to avoid issues of recursion stack depth (for a recursive implementation, see find_cliques_recursive
).
This algorithm ignores self-loops and parallel edges, since cliques are not conventionally defined with such edges.
An undirected graph.
If provided, only yield maximal cliques containing all nodes in nodes
. If nodes
isn't a clique itself, a ValueError is raised.
If nodes
is not a clique.
An iterator over maximal cliques, each of which is a list of nodes in G
. If nodes
is provided, only the maximal cliques containing all the nodes in nodes
are returned. The order of cliques is arbitrary.
Returns all maximal cliques in an undirected graph.
find_cliques_recursive
A recursive version of the same algorithm.
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.algorithms.clique.node_clique_number
networkx.algorithms.clique.find_cliques_recursive
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them