Maximum Flow

The Edmond and Karp algorithm computes a maximum flow for directed graph with positive capacities and flows.

// we need a graph, a source and a sink
IMutableVertexAndEdgeListGraph<TVertex,TEdge> graph = ...;
TVertex source = ...;
TVertex sink = ...;

// A function with maps an edge to its capacity
Func<TEdge, double> capacityFunc = (edge => 1);

// A function which takes a vertex and returns the edge connecting to its predecessor in the flow network
TryFunc<TVertex, TEdge> flowPredecessors;

// A function used to create new edges during the execution of the algorithm.  These edges are removed before the computation returns
EdgeFactory<TVertex, TEdge> edgeFactory = (source, target) => new Edge<TVertex>(source,target);

// computing the maximum flow using Edmonds Karp.
double flow = AlgorithmExtensions.MaximumFlowEdmondsKarp<TVertex, TEdge>(
    source, sink,
    out flowPredecessors,

Last edited Aug 12, 2010 at 11:17 PM by rhennig, version 4


thesnark Sep 25, 2014 at 4:48 PM 
I have found the same thing. Latest version of QuickGraph for the MaximumFlowEdmondsKarp gives a 4 where it should be a 5 for the netowrk described This is a show stopper for me :(

ARMENHOV Nov 20, 2011 at 4:30 AM 
Maxflow of network from is 5 , but i get answer 4 from MaximumFlowEdmondsKarp

ARMENHOV Dec 12, 2010 at 5:34 PM 
Last version of MaximumFlowEdmondsKarp dont work correct