Download jar file or use maven. psjava requires Java 1.6 (or above)
<dependency>
<groupId>org.psjava</groupId>
<artifactId>psjava</artifactId>
<version>0.1.19</version>
</dependency>
MutableUndirectedUnweightedGraph<String> graph = MutableUndirectedUnweightedGraph.create(); graph.insertVertex("A"); graph.insertVertex("B"); graph.insertVertex("C"); graph.insertVertex("D"); graph.insertVertex("E"); graph.addEdge("A", "B"); graph.addEdge("D", "C"); int number = NumberOfConnectedComponents.calc(graph); // must be 3. {A,B}, {C,D}, {E}
Copyright 2014 psjava team. View on GitHub