largest_cliques#
- graph_tool.topology.largest_cliques(g)[git][source]#
Return all the cliques of maximum size of a graph.
- Parameters:
- g
Graph Graph to be used. Edge directions are ignored.
- g
- Returns:
- cliques
listofnumpy.ndarray The vertices of every clique of maximum size.
- cliques
See also
maximal_cliquesAll maximal cliques
clique_numberSize of a largest clique
maximum_weight_cliqueClique of maximum total vertex weight
approx_maximum_cliqueApproximate 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 with
maximal_cliques(), and those of sizeclique_number()are kept; the time is exponential in the worst case.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") <...>
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.#