www.gusucode.com > bioinfo 案例源码程序 matlab代码 > bioinfo/CalculateMaximumFlowExample.m
%% Calculate Maximum Flow % This example shows how to calculate the maximum flow in a directed graph. % Copyright 2015 The MathWorks, Inc. %% % Create a directed graph with six nodes and eight edges. cm = sparse([1 1 2 2 3 3 4 5],[2 3 4 5 4 5 6 6],... [2 3 3 1 1 1 2 3],6,6) %% % Calculate the maximum flow in the graph from node 1 to node 6. [M,F,K] = graphmaxflow(cm,1,6) %% % Notice that K is a two-row matrix because there are two possible % solutions to the minimum cut problem. %% % View the graph with the original capacities. h = view(biograph(cm,[],'ShowWeights','on')) %% % View the graph with the calculated maximum flows. view(biograph(F,[],'ShowWeights','on')) %% % Show one solution to the minimum cut problem in the original graph. set(h.Nodes(K(1,:)),'Color',[1 0 0])