File: cs_scc2.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (61 lines) | stat: -rw-r--r-- 2,070 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function [p, q, r, s] = cs_scc2 (A, bipartite)
%CS_SCC2 cs_scc, or connected components of a bipartite graph.
%   [p,q,r,s] = cs_scc2(A) finds a permutation p so that A(p,q) is permuted into
%   block upper triangular form (if A is square).  In this case, r=s, p=q and
%   the kth diagonal block is given by A (t,t) where t = r(k):r(k)+1. 
%   The diagonal of A is ignored.  Each block is one strongly connected
%   component of A.
%
%   If A is not square (or for [p,q,r,s] = cs_scc2(A,1)), then the connected
%   components of the bipartite graph of A are found.  A(p,q) is permuted into
%   block diagonal form, where the diagonal blocks are rectangular.  The kth
%   block is given by A(r(k):r(k+1)-1,s(k):s(k+1)-1).  A can be rectangular.
%
%   Example:
%       Prob = ssget ('HB/arc130') ; A = Prob.A ; [p q r s] = cs_scc2 (A) ;
%       cspy (A (p,q)) ;
%       Prob = ssget ('HB/wm1') ; A = Prob.A ; [p q r s] = cs_scc2 (A) ;
%       cspy (A (p,q)) ;
%
%   See also CS_DMPERM, DMPERM, CS_SCC, CCSPY.

% CXSparse, Copyright (c) 2006-2022, Timothy A. Davis. All Rights Reserved.
% SPDX-License-Identifier: LGPL-2.1+

[m n] = size (A) ;
if (nargin < 2)
    bipartite = 0 ;
end

if (m ~= n | bipartite)                                                     %#ok

    % find the connected components of [I A ; A' 0]
    S = spaugment (A) ;
    [psym,rsym] = cs_scc (S) ;
    p = psym (find (psym <= m)) ;                                           %#ok
    q = psym (find (psym > m)) - m ;                                        %#ok
    nb = length (rsym) - 1 ;
    r = zeros (1,nb+1) ;
    s = zeros (1,nb+1) ;
    krow = 1 ;
    kcol = 1 ;
    for k = 1:nb
        % find the rows and columns in the kth component
        r (k) = krow ;
        s (k) = kcol ;
        ksym = psym (rsym (k):rsym (k+1)-1) ;
        krow = krow + length (find (ksym <= m)) ;
        kcol = kcol + length (find (ksym >  m)) ;
    end
    r (nb+1) = m+1 ;
    s (nb+1) = n+1 ;

else

    % find the strongly connected components of A
    [p,r] = cs_scc (A) ;
    q = p ;
    s = r ;

end