File: sspage.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: 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 (221 lines) | stat: -rw-r--r-- 5,839 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
function sspage (matrix, index)
%SSPAGE create images for a matrix in SuiteSparse Matrix Collection
%
% Usage:
%      sspage (matrix, index)
%
% matrix: id or name of matrix to create the images for.
% index: the ss_index, from ssget.
%
% Example:
%
%   sspage (267)
%   sspage ('HB/west0479')
%
% See also ssget, cspy, ssgplot.

% SuiteSparseCollection, Copyright (c) 2006-2019, Timothy A Davis.
% All Rights Reserved.
% SPDX-License-Identifier: GPL-2.0+

%-------------------------------------------------------------------------------
% get inputs
%-------------------------------------------------------------------------------

if (nargin < 2)
    index = ssget ;
end

%-------------------------------------------------------------------------------
% get the Problem and its contents
%-------------------------------------------------------------------------------

Problem = ssget (matrix,index) ;
disp (Problem)
fullname = Problem.name ;
s = strfind (fullname, '/') ;
grp = fullname (1:s-1) ;
name = fullname (s+1:end) ;
id = Problem.id ;

% create the primary directory
topdir = sslocation ;
files = [topdir 'files'] ;
if (~exist (files, 'dir'))
    mkdir (files) ;
end

% create the group directory
if (~exist ([files '/' grp], 'dir'))
    mkdir ([files '/' grp]) ;
end

% determine the full path of the problem
fullpath = regexprep ([files '/' fullname], '[\/\\]', '/') ;

ptitle = Problem.title ;

z = 0 ;
if (isfield (Problem, 'Zeros'))
    z = nnz (Problem.Zeros) ;
    Problem = rmfield (Problem, 'Zeros') ;
end

nblocks = index.nblocks (id) ;
ncc = index.ncc (id) ;

has_b = isfield (Problem, 'b') ;
has_x = isfield (Problem, 'x') ;
has_aux = isfield (Problem, 'aux') ;

if (has_b)
    b = Problem.b ;
    Problem = rmfield (Problem, 'b') ;
    if (iscell (b))
	b = sprintf ('cell %d-by-%d\n', size (b)) ;
    elseif (issparse (b))
	b = sprintf ('sparse %d-by-%d\n', size (b)) ;
    else
	b = sprintf ('full %d-by-%d\n', size (b)) ;
    end
end

if (has_x)
    x = Problem.x ;
    Problem = rmfield (Problem, 'x') ;
    if (iscell (x))
	x = sprintf ('cell %d-by-%d\n', size (x)) ;
    elseif (issparse (x))
	x = sprintf ('sparse %d-by-%d\n', size (x)) ;
    else
	x = sprintf ('full %d-by-%d\n', size (x)) ;
    end
end

nodename = [ ] ;
if (has_aux)
    aux = Problem.aux ;
    Problem = rmfield (Problem, 'aux') ;
    auxfields = fields (aux) ;
    has_coord = isfield (aux, 'coord') ;
    has_nodename = isfield (aux, 'nodename') ;
    auxs = cell (1, length (auxfields)) ;
    for k = 1:length(auxfields)
	siz = size (aux.(auxfields{k})) ;
	if (iscell (aux.(auxfields{k})))
	    auxs {k} = sprintf ('cell %d-by-%d\n', siz) ;
	elseif (issparse (aux.(auxfields{k})))
	    auxs {k} = sprintf ('sparse %d-by-%d\n', siz) ;
	else
	    auxs {k} = sprintf ('full %d-by-%d\n', siz) ;
	end
    end
    if (has_coord)
	xyz = aux.coord ;
    end
    if (has_nodename)
	nodename = aux.nodename ;
    end
    clear aux
else
    has_coord = 0 ;
end

kind = Problem.kind ;
if (isfield (Problem, 'notes'))
    notes = Problem.notes ;
else
    notes = '' ;
end

au = Problem.author ;
ed = Problem.ed ;
da = Problem.date ;

m = index.nrows (id) ;
n = index.ncols (id) ;
nz = index.nnz (id) ;
nnzdiag = index.nnzdiag (id) ;

if (strfind (kind, 'graph'))
    bipartite = ~isempty (strfind (kind, 'bipartite')) ;
    directed = ~isempty (regexp (kind, '\<directed', 'once')) ;
else
    bipartite = (m ~= n) ;
    directed = (index.pattern_symmetry (id) < 1) ;
end

%-------------------------------------------------------------------------------
% create the pictures
%-------------------------------------------------------------------------------

A = Problem.A ;
clear Problem

%---------------------------------------------------------------------------
% create the gplot
%---------------------------------------------------------------------------

do_gplot = has_coord ;
if (do_gplot)
    ssgplot (A, xyz, directed, nodename) ;
    print (gcf, '-dpng', '-r128', [fullpath '_gplot.png']) ;
    print (gcf, '-dpng', '-r512', [fullpath '_gplot_big.png']) ;
end

%---------------------------------------------------------------------------
% create the thumbnail picture
%---------------------------------------------------------------------------

cspy (A, 16) ;
print (gcf, '-dpng', '-r12', [fullpath '_thumb.png']) ;

%---------------------------------------------------------------------------
% create the regular picture
%---------------------------------------------------------------------------

cspy (A, 128) ;
print (gcf, '-dpng', '-r64', [fullpath '.png']) ;

%---------------------------------------------------------------------------
% create the dmperm figure, but not for graphs
%---------------------------------------------------------------------------

do_dmspy = (nblocks > 1) ;
if (do_dmspy)
    try
        cs_dmspy (A, 128) ;
        title ('Dulmage-Mendelsohn permutation') ;
    catch
        fprintf ('dmspy failed\n') ;
        delete ([fullpath '_dmperm.png']) ;
        do_dmspy = 0 ;
    end
    print (gcf, '-dpng', '-r64', [fullpath '_dmperm.png']) ;
end

%---------------------------------------------------------------------------
% create the ccspy figure
%---------------------------------------------------------------------------

do_scc = (ncc > 1) ;
if (do_dmspy && m == n && nnzdiag == n)
    % don't do scc for a square matrix with zero-free diagonal
    do_scc = 0 ;
end
if (do_scc)
    try
        ccspy (A, bipartite, 128) ;
        if (bipartite)
            title ('connected components of the bipartite graph') ;
        else
            title ('strongly connected components of the graph') ;
        end
        print (gcf, '-dpng', '-r64', [fullpath '_scc.png']) ;
    catch
        fprintf ('ccspy failed\n') ;
        delete ([fullpath '_cc.png']) ;
        do_scc = 0 ;
    end
end