comparison toolboxes/FullBNT-1.0.7/graph/scc.m @ 0:e9a9cd732c1e tip

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