largest_cliques

largest_cliques#

graph_tool.structure.largest_cliques(g)[git][source]#

Return all the cliques of maximum size of a graph.

Parameters:
gGraph

Graph to be used. Edge directions are ignored.

Returns:
cliqueslist of numpy.ndarray

The vertices of every clique of maximum size.

See also

maximal_cliques

All maximal cliques

clique_number

Size of a largest clique

maximum_weight_clique

Clique of maximum total vertex weight

approx_maximum_clique

Approximate maximum clique

Notes

A clique is a set of vertices every two of which are adjacent, ignoring the edge directions, and the cliques returned are those of size \(\omega(G)\), the clique number. The maximal cliques are enumerated as in clique_number(), in parallel and in a single pass, pruning the branches that cannot reach the size of the largest clique found so far; the time is exponential in the worst case. Every clique is returned with its vertices in increasing order, and the cliques in lexicographic order.

Examples

>>> g = gt.collection.data["karate"]
>>> print(sorted(sorted(c.tolist()) for c in gt.largest_cliques(g)))
[[0, 1, 2, 3, 7], [0, 1, 2, 3, 13]]

The cliques can be highlighted in a drawing of the network:

>>> inc = g.new_vp("bool")
>>> ine = g.new_ep("bool")
>>> for c in gt.largest_cliques(g):
...     inc.a[c] = True
...     for i, u in enumerate(c):
...         for v in c[i + 1:]:
...             ine[g.edge(u, v)] = True
>>> vcolor = g.new_vp("string", vals=np.where(inc.a, "#f28c8e",
...                                           "#cccccc"))
>>> ecolor = g.new_ep("string", vals=np.where(ine.a, "#e41a1c",
...                                           "#999999"))
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=vcolor,
...               edge_color=ecolor, output="largest_cliques-karate.pdf")
<...>
../_images/largest_cliques-karate.png

Largest cliques of Zachary’s karate club network, two cliques of five vertices that share four of them, with their vertices and edges shown in red.#