maximum_weight_clique#
- graph_tool.structure.maximum_weight_clique(g, weight=None, all=False)[git][source]#
Return a clique of maximum total vertex weight.
- Parameters:
- g
Graph Graph to be used. Edge directions are ignored.
- weight
VertexPropertyMap(optional, default:None) Nonnegative vertex weights. If not given, every vertex has weight one, and a maximum clique is returned.
- all
bool(optional, default:False) If
True, all the cliques of maximum weight are returned.
- g
- Returns:
- clique
numpy.ndarrayorlistofnumpy.ndarray The vertices of the clique, or a list with the vertices of every clique of maximum weight, if
all == True.- w
float The total weight.
- clique
See also
largest_cliquesCliques of maximum size
approx_maximum_cliqueApproximate maximum clique
Notes
The clique is found by branch and bound, in which the vertices that can extend the current clique are bounded by a greedy weighted coloring: each color class contributes the smallest residual weight of its vertices, and the vertices covered by classes whose total weight does not exceed the margin to the best clique found need no branching [warren-combinatorial-2006]. With
all == True, only the branches whose bound is smaller than the best weight are pruned, and every clique whose weight equals the best one (up to a relative difference of \(10^{-10}\)) is kept. Vertices of weight zero are ignored, also in the cliques returned. The time is exponential in the worst case.References
[warren-combinatorial-2006]Jeffrey S. Warren and Illya V. Hicks, “Combinatorial branch-and-bound for the maximum weight independent set problem”, Technical report, Texas A&M University (2006).
Examples
>>> g = gt.collection.data["karate"] >>> w = g.degree_property_map("total") >>> c, cw = gt.maximum_weight_clique(g, w) >>> print(sorted(c.tolist()), cw) [0, 1, 2, 3, 13] 46.0 >>> cs, cw = gt.maximum_weight_clique(g, all=True) >>> print(sorted(sorted(c.tolist()) for c in cs), cw) [[0, 1, 2, 3, 7], [0, 1, 2, 3, 13]] 5.0