?? list2incid.m
字號:
function [I,c,u,l] = list2incid(IJCUL,spI)
%LIST2INCID Arc list to node-arc incidence matrix representation.
% [I,c,u,l] = list2incid(IJCUL,spI)
% IJCUL = n x 2-5 matrix arc list [i j c u l], with i and j required and
% c, u, and l optional (just passed through)
% i = n-element vector of arc tails nodes
% j = n-element vector of arc head nodes
% c = n-element vector of arc costs, where n = number of arcs
% u = n-element vector of arc upper bounds
% l = n-element vector of arc lower bounds
% spI = (optional) make I sparse matrix if no. of nodes (m) >= 1/spI
% = 1, always make I sparse
% = 0.05 (default), make I sparse if m >= 20
% = 0, always make I full matrix
% I = m x n node-arc incidence matrix
%
% Transforms: i(k) -> I[i(k),k] = 1
% j(k) -> I[j(k),k] = -sign(j(k)), where
% j(k) > 0 => I[j(k),k] = -1, for directed arc (i(k),j(k))
% j(k) < 0 => I[j(k),k] = 1, for undirected arc (i(k),j(k))
% i(k) = j(k) (self-loop) => I[i(k),k] = I[j(k),k] = 1
%
% Wrapper for I = SPARSE([1:n 1:n]',[i;abs(j)],[ones(n,1);-sign(j)],n,m)';
%
% Examples:
% IJC = [1 2 1
% 3 1 3
% 3 2 2]
% [I,c] = list2incid(IJC) % I = 1 -1 0 c = 1
% -1 0 -1 3
% 0 1 1 2
%
% IJC(2,3) = 0 % Arc (3,1) has 0 weight
% [I,c] = adj2incid(IJC) % I = 1 -1 0 c = 1
% -1 0 -1 0
% 0 1 1 2
%
% IJC = [1 -2 1 % Symmetric arcs
% 3 -1 3
% 3 -2 2]
% [I,c] = adj2incid(IJC) % I = 1 1 0 c = 1
% 1 0 1 0
% 0 1 1 2
%
% See also LIST2ADJ, ADJ2LIST, and ADJ2INCID
% 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,2,nargin))
[n,cIJCUL] = size(IJCUL);
if cIJCUL < 2 || cIJCUL > 5
error('IJCUL must be a 2-5 column matrix.')
end
[i,j,c,u,l] = mat2vec(IJCUL);
jsgn = sign(j); j = abs(j);
minIJ = min(min([i j]));
if isempty(minIJ) || minIJ < 1 || any(~isint(i)) || any(~isint(j))
error('All elements of "i" and "j" must be nonzero integers.')
end
if nargin < 2 || isempty(spI)
spI = 0.05;
elseif length(spI(:)) ~= 1 || spI < 0
error('"spI" must be non-negative scalar.')
end
% End (Input Error Checking) **********************************************
m = max(max([i j]));
jsgn(i==j) = 0; % Self-loop i(k) = j(k) => I[i(k),k] = I[j(k),k] = 1
I = sparse([1:n 1:n]',[i;j],[ones(n,1);-jsgn],n,m)';
if 1 > spI * m, I = full(I); end
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -