Mercurial > octave
annotate libinterp/dldfcn/symrcm.cc @ 27800:5a6a19a4e3da
doc: Use Texinfo non-sentence ending periods in citations.
* geometry.txi, quadcc.cc, rand.cc, sqrtm.cc, symrcm.cc, integral2.m,
integral3.m, quad2d.m, quadgk.m, quadl.m, cubehelix.m, commutation_matrix.m,
condest.m, duplication_matrix.m, normest1.m, qmr.m, cosint.m, gammainc.m,
gammaincinv.m, invhilb.m:
Use Texinfo non-sentence ending periods in citations.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 10 Dec 2019 15:17:01 -0800 |
parents | 00f796120a6d |
children | b442ec6dda5c |
rev | line source |
---|---|
6608 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
3 Copyright (C) 2007-2019 Michael Weitzel |
6608 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
6608 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
6608 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
6608 | 20 |
21 */ | |
22 | |
23 /* | |
24 An implementation of the Reverse Cuthill-McKee algorithm (symrcm) | |
25 | |
26 The implementation of this algorithm is based in the descriptions found in | |
27 | |
28 @INPROCEEDINGS{, | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
29 author = {E. Cuthill and J. McKee}, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
30 title = {Reducing the Bandwidth of Sparse Symmetric Matrices}, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
31 booktitle = {Proceedings of the 24th ACM National Conference}, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
32 publisher = {Brandon Press}, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
33 pages = {157 -- 172}, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
34 location = {New Jersey}, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
35 year = {1969} |
6608 | 36 } |
37 | |
38 @BOOK{, | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
39 author = {Alan George and Joseph W. H. Liu}, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
40 title = {Computer Solution of Large Sparse Positive Definite Systems}, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
41 publisher = {Prentice Hall Series in Computational Mathematics}, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
42 ISBN = {0-13-165274-5}, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
43 year = {1981} |
6608 | 44 } |
45 | |
46 The algorithm represents a heuristic approach to the NP-complete minimum | |
47 bandwidth problem. | |
48 | |
6610 | 49 Written by Michael Weitzel <michael.weitzel@@uni-siegen.de> |
50 <weitzel@@ldknet.org> | |
6608 | 51 */ |
52 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
53 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
54 # include "config.h" |
6608 | 55 #endif |
56 | |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22860
diff
changeset
|
57 #include <algorithm> |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22860
diff
changeset
|
58 |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22860
diff
changeset
|
59 #include "CSparse.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22860
diff
changeset
|
60 #include "boolNDArray.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22860
diff
changeset
|
61 #include "dNDArray.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22860
diff
changeset
|
62 #include "dSparse.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
63 #include "oct-locbuf.h" |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22860
diff
changeset
|
64 #include "oct-sparse.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22860
diff
changeset
|
65 #include "quit.h" |
6608 | 66 |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22860
diff
changeset
|
67 #include "defun-dld.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22860
diff
changeset
|
68 #include "errwarn.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22860
diff
changeset
|
69 #include "ov.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22860
diff
changeset
|
70 #include "ovl.h" |
6608 | 71 |
72 // A node struct for the Cuthill-McKee algorithm | |
73 struct CMK_Node | |
74 { | |
75 // the node's id (matrix row index) | |
76 octave_idx_type id; | |
77 // the node's degree | |
78 octave_idx_type deg; | |
79 // minimal distance to the root of the spanning tree | |
80 octave_idx_type dist; | |
81 }; | |
82 | |
83 // A simple queue. | |
84 // Queues Q have a fixed maximum size N (rows,cols of the matrix) and are | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
85 // stored in an array. qh and qt point to queue head and tail. |
6608 | 86 |
87 // Enqueue operation (adds a node "o" at the tail) | |
6959 | 88 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
89 inline static void |
6959 | 90 Q_enq (CMK_Node *Q, octave_idx_type N, octave_idx_type& qt, const CMK_Node& o) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
91 { |
6959 | 92 Q[qt] = o; |
93 qt = (qt + 1) % (N + 1); | |
94 } | |
6608 | 95 |
96 // Dequeue operation (removes a node from the head) | |
6959 | 97 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
98 inline static CMK_Node |
6959 | 99 Q_deq (CMK_Node * Q, octave_idx_type N, octave_idx_type& qh) |
100 { | |
101 CMK_Node r = Q[qh]; | |
102 qh = (qh + 1) % (N + 1); | |
103 return r; | |
104 } | |
6608 | 105 |
106 // Predicate (queue empty) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
107 #define Q_empty(Q, N, qh, qt) ((qh) == (qt)) |
6608 | 108 |
109 // A simple, array-based binary heap (used as a priority queue for nodes) | |
110 | |
111 // the left descendant of entry i | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
112 #define LEFT(i) (((i) << 1) + 1) // = (2*(i)+1) |
6608 | 113 // the right descendant of entry i |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
114 #define RIGHT(i) (((i) << 1) + 2) // = (2*(i)+2) |
6608 | 115 // the parent of entry i |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
116 #define PARENT(i) (((i) - 1) >> 1) // = floor(((i)-1)/2) |
6608 | 117 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
118 // Builds a min-heap (the root contains the smallest element). A is an array |
6608 | 119 // with the graph's nodes, i is a starting position, size is the length of A. |
6959 | 120 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
121 static void |
6959 | 122 H_heapify_min (CMK_Node *A, octave_idx_type i, octave_idx_type size) |
123 { | |
124 octave_idx_type j = i; | |
125 for (;;) | |
126 { | |
127 octave_idx_type l = LEFT(j); | |
128 octave_idx_type r = RIGHT(j); | |
129 | |
130 octave_idx_type smallest; | |
131 if (l < size && A[l].deg < A[j].deg) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
132 smallest = l; |
6959 | 133 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
134 smallest = j; |
6959 | 135 |
136 if (r < size && A[r].deg < A[smallest].deg) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
137 smallest = r; |
6959 | 138 |
139 if (smallest != j) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
140 { |
14862
bbdc822be2b9
smyrcm.cc: use std::swap instead of custom swap code.
Rik <octave@nomad.inbox5.com>
parents:
14854
diff
changeset
|
141 std::swap (A[j], A[smallest]); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
142 j = smallest; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
143 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
144 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
145 break; |
6959 | 146 } |
147 } | |
6608 | 148 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
149 // Heap operation insert. Running time is O(log(n)) |
6959 | 150 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
151 static void |
6959 | 152 H_insert (CMK_Node *H, octave_idx_type& h, const CMK_Node& o) |
153 { | |
154 octave_idx_type i = h++; | |
155 | |
156 H[i] = o; | |
157 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
158 if (i == 0) |
6959 | 159 return; |
160 do | |
161 { | |
162 octave_idx_type p = PARENT(i); | |
163 if (H[i].deg < H[p].deg) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
164 { |
14862
bbdc822be2b9
smyrcm.cc: use std::swap instead of custom swap code.
Rik <octave@nomad.inbox5.com>
parents:
14854
diff
changeset
|
165 std::swap (H[i], H[p]); |
6959 | 166 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
167 i = p; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
168 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
169 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
170 break; |
6959 | 171 } |
172 while (i > 0); | |
173 } | |
6608 | 174 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
175 // Heap operation remove-min. Removes the smalles element in O(1) and |
6608 | 176 // reorganizes the heap optionally in O(log(n)) |
6959 | 177 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
178 inline static CMK_Node |
6959 | 179 H_remove_min (CMK_Node *H, octave_idx_type& h, int reorg/*=1*/) |
180 { | |
181 CMK_Node r = H[0]; | |
182 H[0] = H[--h]; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
183 if (reorg) |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
184 H_heapify_min (H, 0, h); |
6959 | 185 return r; |
186 } | |
6608 | 187 |
188 // Predicate (heap empty) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
189 #define H_empty(H, h) ((h) == 0) |
6608 | 190 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
191 // Helper function for the Cuthill-McKee algorithm. Tries to determine a |
6608 | 192 // pseudo-peripheral node of the graph as starting node. |
6959 | 193 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
194 static octave_idx_type |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
195 find_starting_node (octave_idx_type N, const octave_idx_type *ridx, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
196 const octave_idx_type *cidx, const octave_idx_type *ridx2, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
197 const octave_idx_type *cidx2, octave_idx_type *D, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
198 octave_idx_type start) |
6959 | 199 { |
200 CMK_Node w; | |
201 | |
202 OCTAVE_LOCAL_BUFFER (CMK_Node, Q, N+1); | |
203 boolNDArray btmp (dim_vector (1, N), false); | |
204 bool *visit = btmp.fortran_vec (); | |
205 | |
206 octave_idx_type qh = 0; | |
207 octave_idx_type qt = 0; | |
208 CMK_Node x; | |
209 x.id = start; | |
210 x.deg = D[start]; | |
211 x.dist = 0; | |
212 Q_enq (Q, N, qt, x); | |
213 visit[start] = true; | |
214 | |
215 // distance level | |
216 octave_idx_type level = 0; | |
217 // current largest "eccentricity" | |
218 octave_idx_type max_dist = 0; | |
219 | |
220 for (;;) | |
221 { | |
222 while (! Q_empty (Q, N, qh, qt)) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
223 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
224 CMK_Node v = Q_deq (Q, N, qh); |
6959 | 225 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
226 if (v.dist > x.dist || (v.id != x.id && v.deg > x.deg)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
227 x = v; |
6959 | 228 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
229 octave_idx_type i = v.id; |
6959 | 230 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
231 // add all unvisited neighbors to the queue |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
232 octave_idx_type j1 = cidx[i]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
233 octave_idx_type j2 = cidx2[i]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
234 while (j1 < cidx[i+1] || j2 < cidx2[i+1]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
235 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
236 octave_quit (); |
6959 | 237 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
238 if (j1 == cidx[i+1]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
239 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
240 octave_idx_type r2 = ridx2[j2++]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
241 if (! visit[r2]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
242 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
243 // the distance of node j is dist(i)+1 |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
244 w.id = r2; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
245 w.deg = D[r2]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
246 w.dist = v.dist+1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
247 Q_enq (Q, N, qt, w); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
248 visit[r2] = true; |
6959 | 249 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
250 if (w.dist > level) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
251 level = w.dist; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
252 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
253 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
254 else if (j2 == cidx2[i+1]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
255 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
256 octave_idx_type r1 = ridx[j1++]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
257 if (! visit[r1]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
258 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
259 // the distance of node j is dist(i)+1 |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
260 w.id = r1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
261 w.deg = D[r1]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
262 w.dist = v.dist+1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
263 Q_enq (Q, N, qt, w); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
264 visit[r1] = true; |
6959 | 265 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
266 if (w.dist > level) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
267 level = w.dist; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
268 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
269 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
270 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
271 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
272 octave_idx_type r1 = ridx[j1]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
273 octave_idx_type r2 = ridx2[j2]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
274 if (r1 <= r2) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
275 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
276 if (! visit[r1]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
277 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
278 w.id = r1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
279 w.deg = D[r1]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
280 w.dist = v.dist+1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
281 Q_enq (Q, N, qt, w); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
282 visit[r1] = true; |
6959 | 283 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
284 if (w.dist > level) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
285 level = w.dist; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
286 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
287 j1++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
288 if (r1 == r2) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
289 j2++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
290 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
291 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
292 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
293 if (! visit[r2]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
294 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
295 w.id = r2; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
296 w.deg = D[r2]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
297 w.dist = v.dist+1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
298 Q_enq (Q, N, qt, w); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
299 visit[r2] = true; |
6959 | 300 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
301 if (w.dist > level) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
302 level = w.dist; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
303 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
304 j2++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
305 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
306 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
307 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
308 } // finish of BFS |
6959 | 309 |
310 if (max_dist < x.dist) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
311 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
312 max_dist = x.dist; |
6959 | 313 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
314 for (octave_idx_type i = 0; i < N; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
315 visit[i] = false; |
6959 | 316 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
317 visit[x.id] = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
318 x.dist = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
319 qt = qh = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
320 Q_enq (Q, N, qt, x); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
321 } |
6959 | 322 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
323 break; |
6959 | 324 } |
325 return x.id; | |
326 } | |
6608 | 327 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
328 // Calculates the node's degrees. This means counting the nonzero elements |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
329 // in the symmetric matrix' rows. This works for non-symmetric matrices |
6608 | 330 // as well. |
6959 | 331 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
332 static octave_idx_type |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
333 calc_degrees (octave_idx_type N, const octave_idx_type *ridx, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
334 const octave_idx_type *cidx, octave_idx_type *D) |
6959 | 335 { |
336 octave_idx_type max_deg = 0; | |
337 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
338 for (octave_idx_type i = 0; i < N; i++) |
6959 | 339 D[i] = 0; |
340 | |
341 for (octave_idx_type j = 0; j < N; j++) | |
342 { | |
343 for (octave_idx_type i = cidx[j]; i < cidx[j+1]; i++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
344 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
345 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
346 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
347 octave_idx_type k = ridx[i]; |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
348 // there is a nonzero element (k,j) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
349 D[k]++; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
350 if (D[k] > max_deg) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
351 max_deg = D[k]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
352 // if there is no element (j,k) there is one in |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
353 // the symmetric matrix: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
354 if (k != j) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
355 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
356 bool found = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
357 for (octave_idx_type l = cidx[k]; l < cidx[k + 1]; l++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
358 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
359 octave_quit (); |
6959 | 360 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
361 if (ridx[l] == j) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
362 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
363 found = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
364 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
365 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
366 else if (ridx[l] > j) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
367 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
368 } |
6959 | 369 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
370 if (! found) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
371 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
372 // A(j,k) == 0 |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
373 D[j]++; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
374 if (D[j] > max_deg) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
375 max_deg = D[j]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
376 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
377 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
378 } |
6959 | 379 } |
380 return max_deg; | |
381 } | |
6608 | 382 |
383 // Transpose of the structure of a square sparse matrix | |
6959 | 384 |
6608 | 385 static void |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
386 transpose (octave_idx_type N, const octave_idx_type *ridx, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
387 const octave_idx_type *cidx, octave_idx_type *ridx2, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
388 octave_idx_type *cidx2) |
6959 | 389 { |
390 octave_idx_type nz = cidx[N]; | |
391 | |
392 OCTAVE_LOCAL_BUFFER (octave_idx_type, w, N + 1); | |
393 for (octave_idx_type i = 0; i < N; i++) | |
394 w[i] = 0; | |
395 for (octave_idx_type i = 0; i < nz; i++) | |
396 w[ridx[i]]++; | |
397 nz = 0; | |
398 for (octave_idx_type i = 0; i < N; i++) | |
399 { | |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
400 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
401 |
6959 | 402 cidx2[i] = nz; |
403 nz += w[i]; | |
404 w[i] = cidx2[i]; | |
405 } | |
406 cidx2[N] = nz; | |
407 w[N] = nz; | |
408 | |
409 for (octave_idx_type j = 0; j < N; j++) | |
410 for (octave_idx_type k = cidx[j]; k < cidx[j + 1]; k++) | |
411 { | |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
412 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
413 |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14862
diff
changeset
|
414 octave_idx_type q = w[ridx[k]]++; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
415 ridx2[q] = j; |
6959 | 416 } |
417 } | |
6608 | 418 |
419 // An implementation of the Cuthill-McKee algorithm. | |
420 DEFUN_DLD (symrcm, args, , | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
421 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
422 @deftypefn {} {@var{p} =} symrcm (@var{S}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
423 Return the symmetric reverse @nospell{Cuthill-McKee} permutation of @var{S}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
424 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
425 @var{p} is a permutation vector such that |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
426 @code{@var{S}(@var{p}, @var{p})} tends to have its diagonal elements closer |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
427 to the diagonal than @var{S}. This is a good preordering for LU or |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
428 Cholesky@tie{}factorization of matrices that come from ``long, skinny'' |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
429 problems. It works for both symmetric and asymmetric @var{S}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
430 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
431 The algorithm represents a heuristic approach to the NP-complete bandwidth |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
432 minimization problem. The implementation is based in the descriptions found |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
433 in |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
434 |
25032
a1e391e33004
doc: grammarcheck documentation again ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
435 @nospell{E. Cuthill, J. McKee}. |
a1e391e33004
doc: grammarcheck documentation again ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
436 @cite{Reducing the Bandwidth of Sparse Symmetric Matrices}. |
a1e391e33004
doc: grammarcheck documentation again ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
437 Proceedings of the 24th @nospell{ACM} National Conference, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
438 157--172 1969, Brandon Press, New Jersey. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
439 |
27800
5a6a19a4e3da
doc: Use Texinfo non-sentence ending periods in citations.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
440 @nospell{A. George, J.W.H. Liu}. @cite{Computer Solution of Large Sparse |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
441 Positive Definite Systems}, Prentice Hall Series in Computational |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
442 Mathematics, ISBN 0-13-165274-5, 1981. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
443 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
444 @seealso{colperm, colamd, symamd} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
445 @end deftypefn */) |
6608 | 446 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20790
diff
changeset
|
447 if (args.length () != 1) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
448 print_usage (); |
6608 | 449 |
6959 | 450 octave_value arg = args(0); |
6608 | 451 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
452 // the parameter of the matrix is converted into a sparse matrix |
6608 | 453 //(if necessary) |
454 octave_idx_type *cidx; | |
455 octave_idx_type *ridx; | |
456 SparseMatrix Ar; | |
457 SparseComplexMatrix Ac; | |
458 | |
23582
0cc2011d800e
maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
459 if (arg.isreal ()) |
6608 | 460 { |
6959 | 461 Ar = arg.sparse_matrix_value (); |
6608 | 462 // Note cidx/ridx are const, so use xridx and xcidx... |
463 cidx = Ar.xcidx (); | |
464 ridx = Ar.xridx (); | |
465 } | |
466 else | |
467 { | |
6959 | 468 Ac = arg.sparse_complex_matrix_value (); |
6608 | 469 cidx = Ac.xcidx (); |
470 ridx = Ac.xridx (); | |
471 } | |
472 | |
473 octave_idx_type nr = arg.rows (); | |
474 octave_idx_type nc = arg.columns (); | |
475 | |
476 if (nr != nc) | |
21110
3d0d84305600
Use err_square_matrix_required more widely.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
477 err_square_matrix_required ("symrcm", "S"); |
6608 | 478 |
479 if (nr == 0 && nc == 0) | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
480 return ovl (NDArray (dim_vector (1, 0))); |
6959 | 481 |
6608 | 482 // sizes of the heaps |
483 octave_idx_type s = 0; | |
6959 | 484 |
6608 | 485 // head- and tail-indices for the queue |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
486 octave_idx_type qt = 0; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
487 octave_idx_type qh = 0; |
6608 | 488 CMK_Node v, w; |
489 // dimension of the matrix | |
6959 | 490 octave_idx_type N = nr; |
491 | |
6608 | 492 OCTAVE_LOCAL_BUFFER (octave_idx_type, cidx2, N + 1); |
493 OCTAVE_LOCAL_BUFFER (octave_idx_type, ridx2, cidx[N]); | |
494 transpose (N, ridx, cidx, ridx2, cidx2); | |
495 | |
496 // the permutation vector | |
497 NDArray P (dim_vector (1, N)); | |
498 | |
499 // compute the node degrees | |
6959 | 500 OCTAVE_LOCAL_BUFFER (octave_idx_type, D, N); |
501 octave_idx_type max_deg = calc_degrees (N, ridx, cidx, D); | |
6608 | 502 |
503 // if none of the nodes has a degree > 0 (a matrix of zeros) | |
504 // the return value corresponds to the identity permutation | |
505 if (max_deg == 0) | |
506 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
507 for (octave_idx_type i = 0; i < N; i++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
508 P(i) = i; |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
509 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
510 return ovl (P); |
6608 | 511 } |
512 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
513 // a heap for the a node's neighbors. The number of neighbors is |
6608 | 514 // limited by the maximum degree max_deg: |
6959 | 515 OCTAVE_LOCAL_BUFFER (CMK_Node, S, max_deg); |
6608 | 516 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
517 // a queue for the BFS. The array is always one element larger than |
6608 | 518 // the number of entries that are stored. |
6959 | 519 OCTAVE_LOCAL_BUFFER (CMK_Node, Q, N+1); |
6608 | 520 |
521 // a counter (for building the permutation) | |
6959 | 522 octave_idx_type c = -1; |
6608 | 523 |
6959 | 524 // upper bound for the bandwidth (=quality of solution) |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
525 // initialize the bandwidth of the graph with 0. B contains the |
6608 | 526 // the maximum of the theoretical lower limits of the subgraphs |
527 // bandwidths. | |
6959 | 528 octave_idx_type B = 0; |
6608 | 529 |
530 // mark all nodes as unvisited; with the exception of the nodes | |
531 // that have degree==0 and build a CC of the graph. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
532 |
6608 | 533 boolNDArray btmp (dim_vector (1, N), false); |
534 bool *visit = btmp.fortran_vec (); | |
535 | |
536 do | |
537 { | |
538 // locate an unvisited starting node of the graph | |
6959 | 539 octave_idx_type i; |
6608 | 540 for (i = 0; i < N; i++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
541 if (! visit[i]) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
542 break; |
6608 | 543 |
544 // locate a probably better starting node | |
545 v.id = find_starting_node (N, ridx, cidx, ridx2, cidx2, D, i); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
546 |
6608 | 547 // mark the node as visited and enqueue it (a starting node |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
548 // for the BFS). Since the node will be a root of a spanning |
6608 | 549 // tree, its dist is 0. |
550 v.deg = D[v.id]; | |
551 v.dist = 0; | |
552 visit[v.id] = true; | |
6959 | 553 Q_enq (Q, N, qt, v); |
6608 | 554 |
6959 | 555 // lower bound for the bandwidth of a subgraph |
6608 | 556 // keep a "level" in the spanning tree (= min. distance to the |
557 // root) for determining the bandwidth of the computed | |
558 // permutation P | |
6959 | 559 octave_idx_type Bsub = 0; |
6608 | 560 // min. dist. to the root is 0 |
6959 | 561 octave_idx_type level = 0; |
6608 | 562 // the root is the first/only node on level 0 |
6959 | 563 octave_idx_type level_N = 1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
564 |
6677 | 565 while (! Q_empty (Q, N, qh, qt)) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
566 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
567 v = Q_deq (Q, N, qh); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
568 i = v.id; |
6608 | 569 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
570 c++; |
6608 | 571 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
572 // for computing the inverse permutation P where |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
573 // A(inv(P),inv(P)) or P'*A*P is banded |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
574 // P(i) = c; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
575 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
576 // for computing permutation P where |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
577 // A(P(i),P(j)) or P*A*P' is banded |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
578 P(c) = i; |
6608 | 579 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
580 // put all unvisited neighbors j of node i on the heap |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
581 s = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
582 octave_idx_type j1 = cidx[i]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
583 octave_idx_type j2 = cidx2[i]; |
6608 | 584 |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
585 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
586 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
587 while (j1 < cidx[i+1] || j2 < cidx2[i+1]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
588 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
589 octave_quit (); |
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
590 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
591 if (j1 == cidx[i+1]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
592 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
593 octave_idx_type r2 = ridx2[j2++]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
594 if (! visit[r2]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
595 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
596 // the distance of node j is dist(i)+1 |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
597 w.id = r2; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
598 w.deg = D[r2]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
599 w.dist = v.dist+1; |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
600 H_insert (S, s, w); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
601 visit[r2] = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
602 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
603 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
604 else if (j2 == cidx2[i+1]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
605 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
606 octave_idx_type r1 = ridx[j1++]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
607 if (! visit[r1]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
608 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
609 w.id = r1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
610 w.deg = D[r1]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
611 w.dist = v.dist+1; |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
612 H_insert (S, s, w); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
613 visit[r1] = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
614 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
615 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
616 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
617 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
618 octave_idx_type r1 = ridx[j1]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
619 octave_idx_type r2 = ridx2[j2]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
620 if (r1 <= r2) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
621 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
622 if (! visit[r1]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
623 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
624 w.id = r1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
625 w.deg = D[r1]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
626 w.dist = v.dist+1; |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
627 H_insert (S, s, w); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
628 visit[r1] = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
629 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
630 j1++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
631 if (r1 == r2) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
632 j2++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
633 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
634 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
635 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
636 if (! visit[r2]) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
637 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
638 w.id = r2; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
639 w.deg = D[r2]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
640 w.dist = v.dist+1; |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
641 H_insert (S, s, w); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
642 visit[r2] = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
643 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
644 j2++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
645 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
646 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
647 } |
6608 | 648 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
649 // add the neighbors to the queue (sorted by node degree) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
650 while (! H_empty (S, s)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
651 { |
22860
0b1e25cc4457
eliminate use of OCTAVE_QUIT macro in C++ sources
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
652 octave_quit (); |
6608 | 653 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
654 // locate a neighbor of i with minimal degree in O(log(N)) |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
655 v = H_remove_min (S, s, 1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
656 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
657 // entered the BFS a new level? |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
658 if (v.dist > level) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
659 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
660 // adjustment of bandwith: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
661 // "[...] the minimum bandwidth that |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
662 // can be obtained [...] is the |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
663 // maximum number of nodes per level" |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
664 if (Bsub < level_N) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
665 Bsub = level_N; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
666 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
667 level = v.dist; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
668 // v is the first node on the new level |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
669 level_N = 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
670 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
671 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
672 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
673 // there is no new level but another node on |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
674 // this level: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
675 level_N++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
676 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
677 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
678 // enqueue v in O(1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
679 Q_enq (Q, N, qt, v); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
680 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
681 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
682 // synchronize the bandwidth with level_N once again: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
683 if (Bsub < level_N) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
684 Bsub = level_N; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
685 } |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
686 // finish of BFS. If there are still unvisited nodes in the graph |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
687 // then it is split into CCs. The computed bandwidth is the maximum |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
688 // of all subgraphs. Update: |
6608 | 689 if (Bsub > B) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9066
diff
changeset
|
690 B = Bsub; |
6608 | 691 } |
692 // are there any nodes left? | |
693 while (c+1 < N); | |
694 | |
695 // compute the reverse-ordering | |
696 s = N / 2 - 1; | |
6959 | 697 for (octave_idx_type i = 0, j = N - 1; i <= s; i++, j--) |
14862
bbdc822be2b9
smyrcm.cc: use std::swap instead of custom swap code.
Rik <octave@nomad.inbox5.com>
parents:
14854
diff
changeset
|
698 std::swap (P.elem (i), P.elem (j)); |
6608 | 699 |
700 // increment all indices, since Octave is not C | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
701 return ovl (P+1); |
6608 | 702 } |