all_cliques

Contents

all_cliques#

graph_tool.structure.all_cliques(g, min_size=1, max_size=None)[git][source]#

Return an iterator over all cliques of a graph, maximal or not.

Parameters:
gGraph

Graph to be used. Edge directions, self-loops, and parallel edges are ignored.

min_sizeint (optional, default: 1)

Smallest size of the cliques returned.

max_sizeint (optional, default: None)

If given, largest size of the cliques returned.

Returns:
cliquesiterator over numpy.ndarray

The vertices of every clique.

See also

maximal_cliques

Maximal cliques only

largest_cliques

Cliques of maximum size

graph_tool.clustering.motifs

Counts of connected subgraphs

Notes

Unlike maximal_cliques(), which returns only the maximal cliques, every complete subgraph is returned once. The vertices are ordered by degeneracy (smallest-last), and each clique is generated from its first vertex in this order by adding later common neighbors, so that the time is \(O(d)\) per clique vertex, where \(d\) is the degeneracy. The number of cliques can grow exponentially with \(d\).

Examples

>>> g = gt.complete_graph(4)
>>> print(len(list(gt.all_cliques(g))))
15
>>> print(sorted(len(c) for c in gt.all_cliques(g, min_size=3)))
[3, 3, 3, 3, 4]