11
#include "../machine.h"
17
/* NodesToPath converts a vector with node numbers into a path:
18
NODES = [Nn,...,N2,N1] =>
19
PATH = [A1,A2,...,An-1] with Ai = (Ni,Ni+1)
22
void NodesToPath(nodes,p,psize,la,lp,ls)
23
int *nodes,*psize,*la,*lp,*ls;
27
for (i = 1; i <= *psize; i++) {
28
n1 = nodes[*psize-i+1]; n2 = nodes[*psize-i];
30
for (j = lp[n1-1]; j <= lp[n1]-1; j++) {
44
/* prevn2p_ computes a path from node i to node j from a
45
vector describing the previous nodes in path:
46
node i belongs to path if pln[i] > 0
47
pln[i] is then the previous node in the sequence
49
void C2F(prevn2p)(i,j,m,n,la,lp,ls,direct,pln,p,psize)
50
int *i,*j,*m,*n,*la,*lp,*ls,*pln,*psize;
55
if (*i < 0 || *i > *n) {
56
sprintf(str,"Bad internal node number %d",*i);
60
if (*j < 0 || *j > *n) {
61
sprintf(str,"Bad internal node number %d",*j);
65
if ((nodes = (int *)malloc((*m + 1) * sizeof(int))) == NULL) {
66
cerro("Running out of memory");
72
/* the first time, the test must be always verified for dealing with
78
if (k <= 0 || k > *n || nn > *n + 1) {
79
/* there is no path */
85
if ((*p = (int *)malloc(*psize * sizeof(int))) == NULL) {
86
cerro("Running out of memory");
89
NodesToPath(nodes,p,psize,la,lp,ls);
93
/* ns2p_ converts a node set into a path:
94
NODES = [N1,N2,...,Nn] =>
95
PATH = [A1,A2,...,An-1] with Ai = (Ni,Ni+1)
98
void C2F(ns2p)(nodes,nsize,p,psize,la,lp,ls,n)
99
int *nodes,*nsize,*psize,*la,*lp,*ls,*n;
104
if ((*p = (int *)malloc(*psize * sizeof(int))) == NULL) {
105
cerro("Running out of memory");
108
for (i = 1; i <= *psize; i++) {
110
if ((i == 1) && (n1 < 0 || n1 > *n)) {
111
sprintf(str,"Bad internal node number %d",n1);
116
if (n2 < 0 || n2 > *n) {
117
sprintf(str,"Bad internal node number %d",n2);
122
for (j = lp[n1-1]; j <= lp[n1]-1; j++) {
136
/* p2ns_ converts a path into a node set:
137
PATH = [A1,A2,...,An] =>
138
NODES = [N1,N2,...,Nn+1] => with Ai = (Ni,Ni+1)
139
with *nsize = *psize + 1
141
void C2F(p2ns)(p,psize,nodes,nsize,la,lp,ls,direct,m,n)
142
int *p,*psize,*nsize,*la,*lp,*ls,*direct,*m,*n;
145
int ma,a,i,j,k,n1,n2;
147
if ((*nodes = (int *)malloc(*nsize * sizeof(int))) == NULL) {
148
cerro("Running out of memory");
151
if (*direct == 1) ma = *m; else ma = *m / 2;
152
for (i = 1; i <= *psize; i++) {
154
if (a < 0 || a > ma) {
155
sprintf(str,"Bad internal arc number %d",a);
159
/* find nodes n1 and n2 of arc a */
161
for (j = 1; j <= *n; j++) {
162
for (k = lp[j-1]; k <= lp[j]-1; k++)
164
n1 = j; n2 = ls[k-1];
175
if (i == 1) (*nodes)[i-1] = n1;
176
if (i!= 1 && (*nodes)[i-1] != n1) {
182
/* undirected graph */
185
(*nodes)[0] = n1; (*nodes)[1] = n2;
188
if (n1 == (*nodes)[0]) {
189
(*nodes)[0] = (*nodes)[1];
193
else if (n1 == (*nodes)[1]) {
196
else if (n2 == (*nodes)[0]) {
197
(*nodes)[0] = (*nodes)[1];
201
else if (n2 == (*nodes)[1]) {
210
if (n1 == (*nodes)[i-1]) (*nodes)[i] = n2;
211
else if (n2 == (*nodes)[i-1]) (*nodes)[i] = n1;
221
/* edge2st_ computes a spanning tree (root = node 1) from
222
an array alpha of connecting edge numbers */
224
void C2F(edge2st)(n,alpha,tree,treesize)
225
int *n,*alpha,*treesize;
230
if ((*tree = (int *)malloc(*treesize * sizeof(int))) == NULL) {
231
cerro("Running out of memory");
234
for (i = 1; i <= *n - 1; i++) {
239
(*tree)[i-1] = alpha[i];
243
/* prevn2st_ computes a spanning tree (root = node i0) from
244
a vector nodes describing the previous nodes in tree */
246
void C2F(prevn2st)(n,nodes,tree,treesize,la,lp,ls)
247
int *n,*nodes,*treesize,*la,*lp,*ls;
252
if ((*tree = (int *)malloc(*treesize * sizeof(int))) == NULL) {
253
cerro("Running out of memory");
258
for (i = 1; i <= *n; i++) {
260
if (in == 0) continue;
261
/* arc (in,i) belongs to tree */
263
for (j = lp[in-1]; j <= lp[in]-1; j++) {
265
(*tree)[nt++] = la[j-1];
270
if (indic == 0) *treesize=0;