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>
// Construct a graph with capacities. MutableCapacityGraph<String, Integer> capacityGraph = MutableCapacityGraph.create(); capacityGraph.insertVertex("A"); capacityGraph.insertVertex("B"); capacityGraph.insertVertex("C"); capacityGraph.insertVertex("D"); capacityGraph.addEdge("A", "B", 4); capacityGraph.addEdge("A", "C", 2); capacityGraph.addEdge("B", "C", 1); capacityGraph.addEdge("B", "D", 4); capacityGraph.addEdge("C", "D", 1); MaximumFlowAlgorithmResult<Integer, CapacityEdge<String, Integer>> result = EdmondsKarpAlgorithm.getInstance().calc(capacityGraph, "A", "D", IntegerNumberSystem.getInstance()); // Maximum flow is 5. int flow = result.calcTotalFlow(); // Also, you can obtain the flows in each edges by retrieved flow function. Function<CapacityEdge<String, Integer>, Integer> flowFunction = result.calcFlowFunction(); for (CapacityEdge<String, Integer> e : capacityGraph.getEdges("A")) { flowFunction.get(e); }
Copyright 2014 psjava team. View on GitHub