Interface VertexCover
-
public interface VertexCover
Minimum weighted vertex cover algorithm.Given a graph \(G=(V,E)\) a vertex cover is a set \(S \subseteq V\) for which for any edge \((u,v) \in E\) at least one of \(u\) or \(v\) are in \(S\). Given a vertex weight function \(w:V \rightarrow R\), the weight of a vertex cover is the weight sum of the vertices in the cover. The minimum vertex cover is the vertex cover with the minimum weight.
Note that finding the actual minimum vertex cover is an NP-hard problem, even for a weight function that assign \(1\) to each vertex. Therefore, algorithms implementing this interface provide an approximation for the actual optimal solution.
Use
newInstance()
to get a default implementation of this interface. A builder obtained vianewBuilder()
may support different options to obtain different implementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
VertexCover.Builder
A builder forVertexCover
algorithms.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description <V,E>
Set<V>computeMinimumVertexCover(Graph<V,E> g, WeightFunction<V> w)
Compute a minimum vertex cover of a graph with respect to a vertex weight function.static <V,E>
booleanisCover(Graph<V,E> g, Collection<V> vertices)
Check whether a set of vertices is a vertex cover of a graph.static VertexCover.Builder
newBuilder()
Create a new vertex cover algorithm builder.static VertexCover
newInstance()
Create a new vertex cover algorithm object.
-
-
-
Method Detail
-
computeMinimumVertexCover
<V,E> Set<V> computeMinimumVertexCover(Graph<V,E> g, WeightFunction<V> w)
Compute a minimum vertex cover of a graph with respect to a vertex weight function.Note that finding the minimum vertex cover is an NP-hard problem, therefore the result of this function is an approximation of the optimal solution.
If
g
isIntGraph
, the returned object isIntSet
. Ifg
isIntGraph
, prefer to passIWeightFunction
asw
to avoid boxing/unboxing.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- a graphw
- a vertex weight function- Returns:
- a minimum vertex cover
-
isCover
static <V,E> boolean isCover(Graph<V,E> g, Collection<V> vertices)
Check whether a set of vertices is a vertex cover of a graph.A set of vertices is a vertex cover of a graph if for every edge in the graph at least one of its vertices is in the set. In addition, the collection of the vertices must not contain duplicates.
- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- a graphvertices
- a collection of vertices that should cover all the edges in the graph- Returns:
true
ifvertices
is a vertex cover ofg
-
newInstance
static VertexCover newInstance()
Create a new vertex cover algorithm object.This is the recommended way to instantiate a new
VertexCover
object. TheVertexCover.Builder
might support different options to obtain different implementations.- Returns:
- a default implementation of
VertexCover
-
newBuilder
static VertexCover.Builder newBuilder()
Create a new vertex cover algorithm builder.Use
newInstance()
for a default implementation.- Returns:
- a new builder that can build
VertexCover
objects
-
-