2

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);
Skav
  • 346
  • 4
  • 11

1 Answers1

2

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.

Bill
  • 5,263
  • 6
  • 35
  • 50
  • thx, but now I cant complement min vertex cover and all vertices. – Skav Nov 02 '13 at 02:51
  • I think you can manually compute the compliment. If you don't want to do that, you can find the vertex cover on the compliment of your initial graph. That vertex cover will be max independent set for your original graph. – Bill Nov 02 '13 at 02:55