You can use org.jgrapht.alg.VertexCovers
to find the min vertex cover of the graph. The compliment of that set will give your max independent set.
JGraphT - maximum independent set
Question
I have this code for making the undirected graph:
UndirectedGraph g = new SimpleGraph(DefaultEdge.class);
g.addVertex("1");
g.addVertex("2");
g.addVertex("3");
g.addVertex("4");
g.addEdge("1", "3");
g.addEdge("1", "4");
g.addEdge("2", "4");
g.addEdge("3", "4");
How can I find the maximum independent set of this graph using JGraphT library?
Closed
I have added this code
Set vertices = g.vertexSet();
Set covers = VertexCovers.findGreedyCover(g);
Set difference = new HashSet(vertices);
difference.removeAll(covers);
System.out.println(difference);
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow