NeoPZ
number.cpp
Go to the documentation of this file.
1 #include <stdint.h>
2 
3 /* @brief Purpose: Number nodes in component of graph for small profile and rms wavefront */
4 int number_ (int64_t *, int64_t *nc, int64_t *snode, int64_t *lstnum, int64_t *, int64_t *adj, int64_t *xadj,
5  int64_t *s, int64_t *q, int64_t *p)
6 //n, nc, snode, lstnum,e2, adj, xadj, s, q, p
7 {
8  /* System generated locals */
9  int64_t i__1, i__2;
10  /* Local variables */
11  static int64_t node, next, prty, i, j, nabor, istop, jstop, istrt, jstrt, nn, addres, maxprt, nbr;
12 
13 /* INPUT: */
14 /* ------ */
15 /* N - Number of nodes in graph */
16 /* NC - Number of nodes in component of graph */
17 /* SNODE - Node of which numbering starts */
18 /* LSTNUM - Count of nodes which have already been numbered */
19 /* E2 - Twice the number of edges in the graph = XADJ(N+1)-1 */
20 /* ADJ - Adjacency list for all nodes in graph */
21 /* - List of length 2E where E is the number of edges in */
22 /* the graph and 2E = XADJ(N+1)-1 */
23 /* XADJ - Index number for ADJ */
24 /* - Nodes adjacent to node I are found in ADJ(I), where */
25 /* J=XADJ(I), XADJ(I)+1, ..., XADJ(I+1)-1 */
26 /* S - List giving the distance of each node in this */
27 /* component */
28 /* Q - List of nodes which are in this component */
29 /* - Also used to store queue of active or preactivnodes */
30 /* P - Undefined */
31 
32 /* OUTPUT: */
33 /* ------- */
34 /* N - Unchanged */
35 /* NC - Unchanged */
36 /* SNODE - Unchanged */
37 /* LSTNUM - Count of numbered nodes (input value incremented by NC) */
38 /* E2 - Unchanged */
39 /* ADJ - Unchanged */
40 /* XADJ - Unchanged */
41 /* S - List of new node numbers */
42 /* - New number for node, I is S(I) */
43 /* Q - Not used */
44 /* P - Not used */
45 
46 /* NOTES: */
47 /* ------ */
48 /* S also serves as a list giving the status of the nodes */
49 /* during the numbering process: */
50 /* S(I) gt 0 indicates node i is postactive */
51 /* S(I) = 0 indicates node i is active */
52 /* S(I) = -1 indicates node i is preactive */
53 /* S(I) = -2 indicates node i is inactive */
54 /* P is used to hold the priorities for each node */
55 
56 /* PROGRAMMER: Scott sloan */
57 /* ----------- */
58 
59 /* LAST MODIFIED: 10 March 1989 Scott Sloan */
60 /* -------------- */
61 /* *********************************************************************** */
62 
63 
64 /* Initialise priorities and status for each node in this component */
65 /* Initial priority = W1*DIST - W2*DEGREE where: */
66 /* W1 = a positive weigth */
67 /* W2 = a positive weigth */
68 /* DEGREE = initial current degree for node */
69 /* DIST = distance of node from end node */
70 
71  /* Parameter adjustments */
72  --p;
73  --s;
74  --xadj;
75  --q;
76  --adj;
77 
78  /* Function Body */
79  i__1 = *nc;
80  for (i = 1; i <= i__1; ++i)
81  {
82  node = q[i];
83  p[node] = s[node] - ((xadj[node + 1] - xadj[node] + 1) << 1);
84  s[node] = -2;
85 /* L10: */
86  }
87 
88 /* Insert starting node in queue and assign it a preactive status */
89 /* NN is the size of queue */
90 
91  nn = 1;
92  q[nn] = *snode;
93  s[*snode] = -1;
94 
95 /* Loop while queue is not empty */
96 
97 L30:
98  if (nn > 0)
99  {
100 
101 /* Scan queue for node with max prioity */
102 
103  addres = 1;
104  maxprt = p[q[1]];
105  i__1 = nn;
106  for (i = 2; i <= i__1; ++i)
107  {
108  prty = p[q[i]];
109  if (prty > maxprt)
110  {
111  addres = i;
112  maxprt = prty;
113  }
114 /* L35: */
115  }
116 
117 /* NEXT is the node to be numbered next */
118 
119  next = q[addres];
120 
121 /* Delete node NEXT from queue */
122 
123  q[addres] = q[nn];
124  --nn;
125  istrt = xadj[next];
126  istop = xadj[next + 1] - 1;
127  if (s[next] == -1)
128  {
129 
130 /* Node NEXT is preactive, examine its neighbours */
131 
132  i__1 = istop;
133  for (i = istrt; i <= i__1; ++i)
134  {
135 
136 /* Decrease current degree of neighbour by -1 */
137 
138  nbr = adj[i];
139  p[nbr] += 2;
140 
141 /* Add neighbour to queue if it is inactive */
142 /* assign it a preactive status */
143 
144  if (s[nbr] == -2)
145  {
146  ++nn;
147  q[nn] = nbr;
148  s[nbr] = -1;
149  }
150 /* L50: */
151  }
152  }
153 /* Store new node number for node NEXT */
154 /* Status for node NEXT is now postactive */
155 
156  ++(*lstnum);
157  s[next] = *lstnum;
158 
159 /* Search for preactive neightbours of node NEXT */
160 
161  i__1 = istop;
162  for (i = istrt; i <= i__1; ++i)
163  {
164  nbr = adj[i];
165  if (s[nbr] == -1)
166  {
167 
168 /* Decrease current degree of preactive neighbour by -1 */
169 /* assign neighbour an active status */
170 
171  p[nbr] += 2;
172  s[nbr] = 0;
173 
174 /* Loop over nodes adjacent to preactive neighbour */
175 
176  jstrt = xadj[nbr];
177  jstop = xadj[nbr + 1] - 1;
178  i__2 = jstop;
179  for (j = jstrt; j <= i__2; ++j)
180  {
181  nabor = adj[j];
182 
183 /* Decrease current degree of adjacent node by -1 */
184 
185  p[nabor] += 2;
186  if (s[nabor] == -2)
187  {
188 
189 /* Insert inactive node in queue with a p reactive status */
190 
191  ++nn;
192  q[nn] = nabor;
193  s[nabor] = -1;
194  }
195 /* L60: */
196  }
197  }
198 /* L80: */
199  }
200  goto L30;
201  }
202  return 0;
203 } /* number_ */
int number_(int64_t *, int64_t *nc, int64_t *snode, int64_t *lstnum, int64_t *, int64_t *adj, int64_t *xadj, int64_t *s, int64_t *q, int64_t *p)
Definition: number.cpp:4