feedback_vertex_set

feedback_vertex_set#

graph_tool.structure.feedback_vertex_set(g, weight=None, fvs=None, exact=False)[git][source]#

Return a set of vertices whose removal leaves the graph without cycles.

Parameters:
gGraph

Graph to be used.

weightVertexPropertyMap (optional, default: None)

Vertex weights. If given, a set with a small total weight is sought.

fvsVertexPropertyMap (optional, default: None)

If provided, the vertices of the set will be marked in this property map.

exactbool (optional, default: False)

If True, a set of minimum weight is returned, which is feasible only for small graphs (see below).

Returns:
fvsVertexPropertyMap

Boolean vertex property map marking the vertices of the feedback vertex set.

See also

feedback_arc_set

Edge counterpart

approx_minimum_vertex_cover

Approximate minimum vertex cover

find_cycle

A single cycle of the graph

Notes

Finding a minimum feedback vertex set is NP-hard, and a greedy heuristic is used instead: the vertices that cannot lie on a cycle of the remaining graph (those without in- or out-edges, or with at most one edge in undirected graphs) are removed repeatedly, and otherwise the vertex with the largest product of in- and out-degrees (or the largest degree, for undirected graphs), divided by its weight, is put in the set and removed. Vertices with self-loops are always in the set. The algorithm runs in time \(O((V + E)\log V)\).

With exact == True, the vertices with self-loops are put in the set, the vertices that cannot lie on a cycle are removed as above, and in every (strongly) connected component of the remaining graph the complement of the induced acyclic subgraph of maximum weight is found by enumerating the subsets of vertices, where a set is acyclic if it has a vertex without out-neighbors in the rest of the set (or with at most one edge to it, for undirected graphs), whose removal leaves an acyclic set. This takes time \(O(2^n n)\) and memory \(O(2^n)\) bits for a component of \(n\) vertices, and a ValueError is raised if a component has more than 24 vertices.

Examples

>>> g = gt.collection.data["celegansneural"]
>>> fvs = gt.feedback_vertex_set(g)
>>> u = gt.GraphView(g, vfilt=fvs.fa == 0)
>>> print(fvs.fa.sum(), gt.is_DAG(u))
96 True
>>> g = gt.random_graph(20, lambda: (3, 3))
>>> print(gt.feedback_vertex_set(g).fa.sum(),
...       gt.feedback_vertex_set(g, exact=True).fa.sum())
11 6