File: ccspy.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 (67 lines) | stat: -rw-r--r-- 1,785 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
62
63
64
65
66
67
function [p, q, r, s] = ccspy (A, bipartite, res)
%CCSPY plot the connected components of a matrix.
%
%   Example:
%       [p, q, r, s] = ccspy (A, bipartite, res)
%
%   If A is square, [p,q,r,s] = ccspy(A) finds a permutation p so that A(p,q)
%   is permuted into block upper triangular form.  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)-1. 
%   The diagonal of A is ignored.
%
%   If A is not square (or for [p,q,r,s] = ccspy(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.
%
%   It then plots the result via cspy, drawing a greenbox around each component.
%   A 3rd input argument (res) controls the resolution (see cspy for a
%   description of the res parameter).
%
%   See also CSPY, CS_DMPERM, DMPERM, CS_SCC, CS_SCC2, CS_DMSPY.

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

if (~issparse (A))
    A = sparse (A) ;
end
[m n] = size (A) ;
if (nargin < 3)
    res = 256 ;
end
if (nargin < 2)
    bipartite = [ ] ;
end
if (isempty (bipartite))
    bipartite = (m ~= n) ;
end

% find the strongly connected components
[p1 q r s] = cs_scc2 (A, bipartite) ;
if (nargout > 0)
    p = p1 ;
end

nb = length (r)-1 ;

% plot the result
S = A (p1,q) ;
if (res == 0)
    spy (S) ;
    e = 1 ;
else
    e = cspy (S,res) ;
end
hold on

title (sprintf ('%d-by-%d, strongly connected commponents: %d\n', m, n, nb)) ;

if (~bipartite)
    plot ([.5 .5 n+.5 n+.5], [.5 .5 n+.5 n+.5], 'r') ;
end

drawboxes (nb, e, r, s) ;

drawbox (1,m+1,1,n+1,'k',1,e) ;
hold off