package org.psjava.example.algo;

import org.junit.Assert;
import org.junit.Test;
import org.psjava.algo.graph.flownetwork.EdmondsKarpAlgorithm;
import org.psjava.algo.graph.flownetwork.MaximumFlowAlgorithmResult;
import org.psjava.ds.graph.CapacityEdge;
import org.psjava.ds.graph.MutableCapacityGraph;
import org.psjava.ds.math.Function;
import org.psjava.ds.numbersystrem.IntegerNumberSystem;

/**
 * @implementation {@link EdmondsKarpAlgorithm}
 */
public class EdmondsKarpAlgorithmExample {
	@Test
	public void test() {
		// 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()) {
			flowFunction.get(e);
		}

		Assert.assertEquals(5, flow);
	}
}

@@ -143,16 +143,82 @@
 rithm;%0D%0A
+import org.psjava.algo.graph.flownetwork.FordFulkersonAlgorithm;%0D%0A
 import o
@@ -521,16 +521,67 @@
 rithm%7D%0D%0A
+ * @implementation %7B@link FordFulkersonAlgorithm%7D%0D%0A
  */%0D%0Apub

improve example