00001
00050 #include "util_hack.h"
00051 #include "cuddInt.h"
00052
00053
00054
00055
00056
00057 #if SIZEOF_LONG == 8
00058 #define BPL 64
00059 #define LOGBPL 6
00060 #else
00061 #define BPL 32
00062 #define LOGBPL 5
00063 #endif
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 #ifndef lint
00080 static char rcsid[] DD_UNUSED = "$Id: cuddInteract.c,v 1.1.1.1 2003/02/24 22:23:52 wjiang Exp $";
00081 #endif
00082
00083
00084
00085
00086
00087
00090
00091
00092
00093
00094 static void ddSuppInteract ARGS((DdNode *f, int *support));
00095 static void ddClearLocal ARGS((DdNode *f));
00096 static void ddUpdateInteract ARGS((DdManager *table, int *support));
00097 static void ddClearGlobal ARGS((DdManager *table));
00098
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00124 void
00125 cuddSetInteract(
00126 DdManager * table,
00127 int x,
00128 int y)
00129 {
00130 int posn, word, bit;
00131
00132 #ifdef DD_DEBUG
00133 assert(x < y);
00134 assert(y < table->size);
00135 assert(x >= 0);
00136 #endif
00137
00138 posn = ((((table->size << 1) - x - 3) * x) >> 1) + y - 1;
00139 word = posn >> LOGBPL;
00140 bit = posn & (BPL-1);
00141 table->interact[word] |= 1L << bit;
00142
00143 }
00144
00145
00159 int
00160 cuddTestInteract(
00161 DdManager * table,
00162 int x,
00163 int y)
00164 {
00165 int posn, word, bit, result;
00166
00167 if (x > y) {
00168 int tmp = x;
00169 x = y;
00170 y = tmp;
00171 }
00172 #ifdef DD_DEBUG
00173 assert(x < y);
00174 assert(y < table->size);
00175 assert(x >= 0);
00176 #endif
00177
00178 posn = ((((table->size << 1) - x - 3) * x) >> 1) + y - 1;
00179 word = posn >> LOGBPL;
00180 bit = posn & (BPL-1);
00181 result = (table->interact[word] >> bit) & 1L;
00182 return(result);
00183
00184 }
00185
00186
00205 int
00206 cuddInitInteract(
00207 DdManager * table)
00208 {
00209 int i,j,k;
00210 int words;
00211 long *interact;
00212 int *support;
00213 DdNode *f;
00214 DdNode *sentinel = &(table->sentinel);
00215 DdNodePtr *nodelist;
00216 int slots;
00217 int n = table->size;
00218
00219 words = ((n * (n-1)) >> (1 + LOGBPL)) + 1;
00220 table->interact = interact = ALLOC(long,words);
00221 if (interact == NULL) {
00222 table->errorCode = CUDD_MEMORY_OUT;
00223 return(0);
00224 }
00225 for (i = 0; i < words; i++) {
00226 interact[i] = 0;
00227 }
00228
00229 support = ALLOC(int,n);
00230 if (support == NULL) {
00231 table->errorCode = CUDD_MEMORY_OUT;
00232 FREE(interact);
00233 return(0);
00234 }
00235
00236 for (i = 0; i < n; i++) {
00237 nodelist = table->subtables[i].nodelist;
00238 slots = table->subtables[i].slots;
00239 for (j = 0; j < slots; j++) {
00240 f = nodelist[j];
00241 while (f != sentinel) {
00242
00243
00244
00245
00246
00247
00248 if (!Cudd_IsComplement(f->next)) {
00249 for (k = 0; k < n; k++) {
00250 support[k] = 0;
00251 }
00252 ddSuppInteract(f,support);
00253 ddClearLocal(f);
00254 ddUpdateInteract(table,support);
00255 }
00256 f = Cudd_Regular(f->next);
00257 }
00258 }
00259 }
00260 ddClearGlobal(table);
00261
00262 FREE(support);
00263 return(1);
00264
00265 }
00266
00267
00268
00269
00270
00271
00272
00285 static void
00286 ddSuppInteract(
00287 DdNode * f,
00288 int * support)
00289 {
00290 if (cuddIsConstant(f) || Cudd_IsComplement(cuddT(f))) {
00291 return;
00292 }
00293
00294 support[f->index] = 1;
00295 ddSuppInteract(cuddT(f),support);
00296 ddSuppInteract(Cudd_Regular(cuddE(f)),support);
00297
00298 cuddT(f) = Cudd_Complement(cuddT(f));
00299 f->next = Cudd_Complement(f->next);
00300 return;
00301
00302 }
00303
00304
00316 static void
00317 ddClearLocal(
00318 DdNode * f)
00319 {
00320 if (cuddIsConstant(f) || !Cudd_IsComplement(cuddT(f))) {
00321 return;
00322 }
00323
00324 cuddT(f) = Cudd_Regular(cuddT(f));
00325 ddClearLocal(cuddT(f));
00326 ddClearLocal(Cudd_Regular(cuddE(f)));
00327 return;
00328
00329 }
00330
00331
00345 static void
00346 ddUpdateInteract(
00347 DdManager * table,
00348 int * support)
00349 {
00350 int i,j;
00351 int n = table->size;
00352
00353 for (i = 0; i < n-1; i++) {
00354 if (support[i] == 1) {
00355 for (j = i+1; j < n; j++) {
00356 if (support[j] == 1) {
00357 cuddSetInteract(table,i,j);
00358 }
00359 }
00360 }
00361 }
00362
00363 }
00364
00365
00379 static void
00380 ddClearGlobal(
00381 DdManager * table)
00382 {
00383 int i,j;
00384 DdNode *f;
00385 DdNode *sentinel = &(table->sentinel);
00386 DdNodePtr *nodelist;
00387 int slots;
00388
00389 for (i = 0; i < table->size; i++) {
00390 nodelist = table->subtables[i].nodelist;
00391 slots = table->subtables[i].slots;
00392 for (j = 0; j < slots; j++) {
00393 f = nodelist[j];
00394 while (f != sentinel) {
00395 f->next = Cudd_Regular(f->next);
00396 f = f->next;
00397 }
00398 }
00399 }
00400
00401 }
00402