%% Maximum Flow with Specified Algorithm
% Create and plot a graph. The weighted edges represent flow capacities.

s = [1 1 2 2 3 3 4];
t = [2 3 3 4 4 5 5];
weights = [10 6 15 5 10 3 8];
G = digraph(s,t,weights);
H = plot(G,'EdgeLabel',G.Edges.Weight);

%
% Find the maximum flow value between node 1 and node 5. Specify 'augmentpath' to use the Ford-Fulkerson algorithm, and use two outputs to return a graph of the nonzero flows.

[mf,GF] = maxflow(G,1,5,'augmentpath')

%
% Highlight and label the graph of nonzero flows.

H.EdgeLabel = {};
highlight(H,GF,'EdgeColor','r','LineWidth',2);
st = GF.Edges.EndNodes;
labeledge(H,st(:,1),st(:,2),GF.Edges.Weight);

% Copyright 2015 The MathWorks, Inc.