Class RecursiveExactVCImpl<V,E>
java.lang.Object
org.jgrapht.alg.vertexcover.RecursiveExactVCImpl<V,E>
- Type Parameters:
V- the graph vertex typeE- the graph edge type
- All Implemented Interfaces:
VertexCoverAlgorithm<V>
Finds a minimum vertex cover in a undirected graph. The implementation relies on a recursive
algorithm. At each recursive step, the algorithm picks a unvisited vertex v and distinguishes two
cases: either v has to be added to the vertex cover or all of its neighbors.
In pseudo code, the algorithm (simplified) looks like this:
$VC(G)$:
if $V = \emptyset$ then return $\emptyset$
Choose an arbitrary node $v \in G$
$G1 := (V − v, \left{ e \in E | v \not \in e \right})$
$G2 := (V − v − N(v), \left{ e \in E | e \cap (N(v) \cup v)= \empty \right})$
if $|v \cup VC(G1)| \leq |N(v) \cup VC(G2)|$ then
return $v \cup VC(G1)$
else
return $N(v) \cup VC(G2)$
To speed up the implementation, memoization and a bounding procedure are used. The current
implementation solves instances with 150-250 vertices efficiently to optimality.
TODO JK: determine runtime complexity and add it to class description. TODO JK: run this class
through a performance profiler-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classHelper class which represents a vertex cover as a space efficient BitSetNested classes/interfaces inherited from interface VertexCoverAlgorithm
VertexCoverAlgorithm.VertexCover<V>, VertexCoverAlgorithm.VertexCoverImpl<V> -
Field Summary
FieldsModifier and TypeFieldDescriptionInput graphprivate Map<BitSet, RecursiveExactVCImpl<V, E>.BitSetCover> Map for memoizationprivate intNumber of vertices in the graphprivate NeighborCache<V, E> Neighbor cache TODO JK: It might be worth trying to replace the neighbors index by a bitset view.private doubleMaximum weight of the vertex cover.Mapping of a vertex to its index in the list of verticesOrdered list of vertices which will be iteratively considered to be included in a matchingprivate booleanIndicates whether we are solving a weighted or unweighted version of the problem -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate RecursiveExactVCImpl<V,E>.BitSetCover calculateCoverRecursively(int indexNextCandidate, BitSet visited, double accumulatedWeight) private doubleCalculates a cheap upper bound on the optimum solution.Computes a vertex cover.private doublegetWeight(Collection<V> vertices) Returns the weight of a collection of vertices.
-
Field Details
-
graph
-
n
private int nNumber of vertices in the graph -
neighborCache
Neighbor cache TODO JK: It might be worth trying to replace the neighbors index by a bitset view. As such, all operations can be simplified to bitset operations, which may improve the algorithm's performance. -
memo
Map for memoization -
vertices
-
vertexIDDictionary
-
upperBoundOnVertexCoverWeight
private double upperBoundOnVertexCoverWeightMaximum weight of the vertex cover. In case there is no weight assigned to the vertices, the weight of the cover equals the cover's cardinality. -
weighted
private boolean weightedIndicates whether we are solving a weighted or unweighted version of the problem -
vertexWeightMap
-
-
Constructor Details
-
RecursiveExactVCImpl
-
RecursiveExactVCImpl
-
-
Method Details
-
getVertexCover
Description copied from interface:VertexCoverAlgorithmComputes a vertex cover.- Specified by:
getVertexCoverin interfaceVertexCoverAlgorithm<V>- Returns:
- a vertex cover
-
calculateCoverRecursively
private RecursiveExactVCImpl<V,E>.BitSetCover calculateCoverRecursively(int indexNextCandidate, BitSet visited, double accumulatedWeight) -
getWeight
Returns the weight of a collection of vertices. In case of the unweighted vertex cover problem, the return value is the cardinality of the collection. In case of the weighted version, the return value is the sum of the weights of the vertices- Parameters:
vertices- vertices- Returns:
- the total weight of the vertices in the collection.
-
calculateUpperBound
private double calculateUpperBound()Calculates a cheap upper bound on the optimum solution. Currently, we return the best solution found by either the greedy heuristic, or Clarkson's 2-approximation. Neither of these 2 algorithms dominates the other. //TODO JK: Are there better bounding procedures?
-