annotate toolboxes/FullBNT-1.0.7/graph/scc.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [c,v] = scc(a,tol)
Daniel@0 2
Daniel@0 3 % Finds the strongly connected sets of vertices
Daniel@0 4 % in the DI-rected G-raph of A
Daniel@0 5 % c = 0-1 matrix displaying accessibility
Daniel@0 6 % v = displays the equivalent classes
Daniel@0 7 %
Daniel@0 8 % v(i,j) is the j'th member of the i'th equiv class (0 padded)
Daniel@0 9 %
Daniel@0 10 % http://www.math.wsu.edu/math/faculty/tsat/matlab.html
Daniel@0 11
Daniel@0 12 [m,n] = size(a);
Daniel@0 13 if m~=n 'Not a Square Matrix', return, end
Daniel@0 14 b=abs(a); o=ones(size(a)); x=zeros(1,n);
Daniel@0 15 msg='The Matrix is Irreducible !'; v='Connected Directed Graph !';
Daniel@0 16 if (nargin==1) tol=n*eps*norm(a,'inf'); end
Daniel@0 17
Daniel@0 18 % Create a companion matrix
Daniel@0 19 c = b>tol*o;
Daniel@0 20 if (c==o)
Daniel@0 21 % msg, return
Daniel@0 22 v = 1:length(a);
Daniel@0 23 return
Daniel@0 24 end
Daniel@0 25
Daniel@0 26
Daniel@0 27 % Compute accessibility in at most n-step paths
Daniel@0 28 for k=1:n
Daniel@0 29 for j=1:n
Daniel@0 30 for i=1:n
Daniel@0 31 % If index i accesses j, where can you go ?
Daniel@0 32 if c(i,j) > 0 c(i,:) = c(i,:)+c(j,:); end
Daniel@0 33 end
Daniel@0 34 end
Daniel@0 35 end
Daniel@0 36 % Create a 0-1 matrix with the above information
Daniel@0 37 c>zeros(size(a)); c=ans; if (c==o) msg, return, end
Daniel@0 38
Daniel@0 39 % Identify equivalence classes
Daniel@0 40 d=c.*c'+eye(size(a)); d>zeros(size(a)); d=ans;
Daniel@0 41 v=zeros(size(a));
Daniel@0 42 for i=1:n find(d(i,:)); ans(n)=0; v(i,:)=ans; end
Daniel@0 43
Daniel@0 44 % Eliminate displaying of identical rows
Daniel@0 45 i=1;
Daniel@0 46 while(i<n)
Daniel@0 47 for k=i+1:n
Daniel@0 48 if v(k,1) == v(i,1)
Daniel@0 49 v(k,:)=x;
Daniel@0 50 end
Daniel@0 51 end
Daniel@0 52 i=i+1;
Daniel@0 53 end
Daniel@0 54 j=1;
Daniel@0 55 for i=1:n
Daniel@0 56 if v(i,1)>0
Daniel@0 57 h(j,:)=v(i,:);
Daniel@0 58 j=j+1;
Daniel@0 59 end
Daniel@0 60 end
Daniel@0 61 v=h;
Daniel@0 62
Daniel@0 63
Daniel@0 64