Package org.jgrapht.alg.vertexcover
Class GreedyVCImpl<V,E>
- java.lang.Object
-
- org.jgrapht.alg.vertexcover.GreedyVCImpl<V,E>
-
- Type Parameters:
V
- the graph vertex typeE
- the graph edge type
- All Implemented Interfaces:
MinimumVertexCoverAlgorithm<V,E>
,MinimumWeightedVertexCoverAlgorithm<V,E>
public class GreedyVCImpl<V,E> extends java.lang.Object implements MinimumWeightedVertexCoverAlgorithm<V,E>
Greedy algorithm to find a vertex cover for a graph. A vertex cover is a set of vertices that touches all the edges in the graph. The graph's vertex set is a trivial cover. However, a minimal vertex set (or at least an approximation for it) is usually desired. Finding a true minimal vertex cover is an NP-Complete problem. For more on the vertex cover problem, see http://mathworld.wolfram.com/VertexCover.html Note: this class supports pseudo-graphs Runtime: O(|E|*log|V|) This class produces often, but not always, better solutions than the 2-approximation algorithms. Nevertheless, there are instances where the solution is significantly worse. In those cases, consider usingClarksonTwoApproxVCImpl
.- Since:
- Nov 6, 2003
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jgrapht.alg.interfaces.MinimumVertexCoverAlgorithm
MinimumVertexCoverAlgorithm.VertexCover<V>, MinimumVertexCoverAlgorithm.VertexCoverImpl<V>
-
-
Field Summary
Fields Modifier and Type Field Description private static int
vertexCounter
-
Constructor Summary
Constructors Constructor Description GreedyVCImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MinimumVertexCoverAlgorithm.VertexCover<V>
getVertexCover(UndirectedGraph<V,E> graph, java.util.Map<V,java.lang.Double> vertexWeightMap)
Finds a greedy solution to the minimum weighted vertex cover problem.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jgrapht.alg.interfaces.MinimumWeightedVertexCoverAlgorithm
getVertexCover
-
-
-
-
Method Detail
-
getVertexCover
public MinimumVertexCoverAlgorithm.VertexCover<V> getVertexCover(UndirectedGraph<V,E> graph, java.util.Map<V,java.lang.Double> vertexWeightMap)
Finds a greedy solution to the minimum weighted vertex cover problem. At each iteration, the algorithm picks the vertex v with the smallest ratioweight(v)/degree(v)
and adds it to the cover. Next vertex v and all edges incident to it are removed. The process repeats until all vertices are covered. Runtime: O(|E|*log|V|)- Specified by:
getVertexCover
in interfaceMinimumWeightedVertexCoverAlgorithm<V,E>
- Parameters:
graph
- input graphvertexWeightMap
- mapping of vertex weights- Returns:
- greedy solution
-
-