29
29
% load graphs/max_flow_example.mat
34
% Copyright, Stanford University, 2006-2007
33
% Copyright, Stanford University, 2006-2008
42
% Added full2sparse check
45
% Added additional algname
46
% Fixed transpose option to implement the pretranspose
47
% Fixed documentation bug
50
% Added non-negative edge capacities check
36
% 2006-04-16: Initial version
37
% 2006-05-31: Added full2sparse check
38
% 2007-07-08: Added additional algname
39
% Fixed transpose option to implement the pretranspose
40
% Fixed documentation bug
41
% 2007-07-09: Added non-negative edge capacities check
42
% 2008-09-23: Fixed "check" changing the input (Bug #273796)
53
45
[trans check full2sparse] = get_matlab_bgl_options(varargin{:});
54
if full2sparse && ~issparse(A)
46
if full2sparse && ~issparse(A), A = sparse(A); end
58
48
options = struct('algname', 'push_relabel');
60
options = merge_structs(varargin{1}, options);
64
% the matrix cannot have nonnegative capacities
65
check_matlab_bgl(A,struct('noneg',1));
49
if ~isempty(varargin), options = merge_structs(varargin{1}, options); end
51
% no negative capacities and no diagonal entries allowed
52
if check, check_matlab_bgl(A,struct('noneg',1,'nodiag',1)); end
69
54
% max_flow will transpose the data inside
71
% but that means they are passing the transposed data, so we need to
77
% remove any non-zero diagonals
78
A = A - diag(diag(A));
56
% but ~trans means the input is already transposed, so pre-transpose
57
if ~trans, A = A'; end
85
62
[flowval cut] = max_flow_mex(A,u,v,lower(options.algname));
86
63
elseif nargout >= 3