maximum_weight_clique

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:
gGraph

Graph to be used. Edge directions are ignored.

weightVertexPropertyMap (optional, default: None)

Nonnegative vertex weights. If not given, every vertex has weight one, and a maximum clique is returned.

allbool (optional, default: False)

If True, all the cliques of maximum weight are returned.

Returns:
cliquenumpy.ndarray or list of numpy.ndarray

The vertices of the clique, or a list with the vertices of every clique of maximum weight, if all == True.

wfloat

The total weight.

See also

largest_cliques

Cliques of maximum size

approx_maximum_clique

Approximate 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