trans.m

来自「物流分析工具包。Facility location: Continuous mi」· M 代码 · 共 48 行

M
48
字号
function [F,TC] = trans(C,s,d)
%TRANS Transportation and assignment problems.
%[F,TC] = trans(C,s,d), transportation problem
%       = trans(C),     assignment problem
%     C = m x n matrix of costs
%     s = m-element vector of supplies
%       = [1], default
%     d = n-element vector of demands
%       = [1], default
%     F = m x n matrix of flows
%    TC = total cost
%
% Wrapper for: C(C == 0) = NaN; MCNF(LEV2LIST(C),[s; -d])

% Copyright (c) 1994-2006 by Michael G. Kay
% Matlog Version 9 13-Jan-2006 (http://www.ie.ncsu.edu/kay/matlog)

% Input Error Checking ****************************************************
error(nargchk(1,3,nargin));

[m,n] = size(C);

if nargin < 2 | isempty(s), s = ones(m,1); else s = s(:); end
if nargin < 3 | isempty(d), d = ones(n,1); else d = d(:); end

if sum(s) < sum(d)
   error('Total supply cannot be less than total demand.')
elseif length(s) > m | any(s < 0)
   error('"s" must be an m-element non-negative vector.')
elseif length(d) > n | any(d < 0)
   error('"d" must be an n-element non-negative vector.')
end
% End (Input Error Checking) **********************************************

C(C == 0) = NaN;       % Can have zero costs on arcs
s(isinf(s)) = sum(d);  % MCNF requires finite supplies

if all(isint(s)) & all(isint(d))
   TolInt = 1e-3;
else
   TolInt = [];
end

[F,TC] = mcnf(lev2list(C),[s; -d],...
   'LP',[],'LrgProb',[],'TolInt',TolInt);

F = reshape(F,m,n);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?