SVF
cuddInteract.c
Go to the documentation of this file.
1 
78 #include "CUDD/util.h"
79 #include "CUDD/cuddInt.h"
80 
81 /*---------------------------------------------------------------------------*/
82 /* Constant declarations */
83 /*---------------------------------------------------------------------------*/
84 
85 #if SIZEOF_LONG == 8
86 #define BPL 64
87 #define LOGBPL 6
88 #else
89 #define BPL 32
90 #define LOGBPL 5
91 #endif
92 
93 /*---------------------------------------------------------------------------*/
94 /* Stucture declarations */
95 /*---------------------------------------------------------------------------*/
96 
97 
98 /*---------------------------------------------------------------------------*/
99 /* Type declarations */
100 /*---------------------------------------------------------------------------*/
101 
102 
103 /*---------------------------------------------------------------------------*/
104 /* Variable declarations */
105 /*---------------------------------------------------------------------------*/
106 
107 #ifndef lint
108 static char rcsid[] DD_UNUSED = "$Id: cuddInteract.c,v 1.14 2012/02/05 01:07:19 fabio Exp $";
109 #endif
110 
111 /*---------------------------------------------------------------------------*/
112 /* Macro declarations */
113 /*---------------------------------------------------------------------------*/
114 
115 
118 /*---------------------------------------------------------------------------*/
119 /* Static function prototypes */
120 /*---------------------------------------------------------------------------*/
121 
122 static void ddSuppInteract (DdNode *f, char *support);
123 static void ddClearLocal (DdNode *f);
124 static void ddUpdateInteract (DdManager *table, char *support);
125 static void ddClearGlobal (DdManager *table);
126 
130 /*---------------------------------------------------------------------------*/
131 /* Definition of exported functions */
132 /*---------------------------------------------------------------------------*/
133 
134 
135 /*---------------------------------------------------------------------------*/
136 /* Definition of internal functions */
137 /*---------------------------------------------------------------------------*/
138 
139 
152 void
154  DdManager * table,
155  int x,
156  int y)
157 {
158  int posn, word, bit;
159 
160 #ifdef DD_DEBUG
161  assert(x < y);
162  assert(y < table->size);
163  assert(x >= 0);
164 #endif
165 
166  posn = ((((table->size << 1) - x - 3) * x) >> 1) + y - 1;
167  word = posn >> LOGBPL;
168  bit = posn & (BPL-1);
169  table->interact[word] |= 1L << bit;
170 
171 } /* end of cuddSetInteract */
172 
173 
187 int
189  DdManager * table,
190  int x,
191  int y)
192 {
193  int posn, word, bit, result;
194 
195  if (x > y) {
196  int tmp = x;
197  x = y;
198  y = tmp;
199  }
200 #ifdef DD_DEBUG
201  assert(x < y);
202  assert(y < table->size);
203  assert(x >= 0);
204 #endif
205 
206  posn = ((((table->size << 1) - x - 3) * x) >> 1) + y - 1;
207  word = posn >> LOGBPL;
208  bit = posn & (BPL-1);
209  result = (table->interact[word] >> bit) & 1L;
210  return(result);
211 
212 } /* end of cuddTestInteract */
213 
214 
233 int
235  DdManager * table)
236 {
237  int i,j;
238  unsigned long words;
239  long *interact;
240  char *support;
241  DdNode *f;
242  DdNode *sentinel = &(table->sentinel);
243  DdNodePtr *nodelist;
244  int slots;
245  unsigned long n = (unsigned long) table->size;
246 
247  words = ((n * (n-1)) >> (1 + LOGBPL)) + 1;
248  table->interact = interact = ALLOC(long,words);
249  if (interact == NULL) {
250  table->errorCode = CUDD_MEMORY_OUT;
251  return(0);
252  }
253  for (i = 0; i < words; i++) {
254  interact[i] = 0;
255  }
256 
257  support = ALLOC(char,n);
258  if (support == NULL) {
259  table->errorCode = CUDD_MEMORY_OUT;
260  FREE(interact);
261  return(0);
262  }
263  for (i = 0; i < n; i++) {
264  support[i] = 0;
265  }
266 
267  for (i = 0; i < n; i++) {
268  nodelist = table->subtables[i].nodelist;
269  slots = table->subtables[i].slots;
270  for (j = 0; j < slots; j++) {
271  f = nodelist[j];
272  while (f != sentinel) {
273  /* A node is a root of the DAG if it cannot be
274  ** reached by nodes above it. If a node was never
275  ** reached during the previous depth-first searches,
276  ** then it is a root, and we start a new depth-first
277  ** search from it.
278  */
279  if (!Cudd_IsComplement(f->next)) {
280  ddSuppInteract(f,support);
281  ddClearLocal(f);
282  ddUpdateInteract(table,support);
283  }
284  f = Cudd_Regular(f->next);
285  }
286  }
287  }
288  ddClearGlobal(table);
289 
290  FREE(support);
291  return(1);
292 
293 } /* end of cuddInitInteract */
294 
295 
296 /*---------------------------------------------------------------------------*/
297 /* Definition of static functions */
298 /*---------------------------------------------------------------------------*/
299 
300 
313 static void
315  DdNode * f,
316  char * support)
317 {
318  if (cuddIsConstant(f) || Cudd_IsComplement(cuddT(f))) {
319  return;
320  }
321 
322  support[f->index] = 1;
323  ddSuppInteract(cuddT(f),support);
324  ddSuppInteract(Cudd_Regular(cuddE(f)),support);
325  /* mark as visited */
326  cuddT(f) = Cudd_Complement(cuddT(f));
327  f->next = Cudd_Complement(f->next);
328  return;
329 
330 } /* end of ddSuppInteract */
331 
332 
344 static void
346  DdNode * f)
347 {
348  if (cuddIsConstant(f) || !Cudd_IsComplement(cuddT(f))) {
349  return;
350  }
351  /* clear visited flag */
352  cuddT(f) = Cudd_Regular(cuddT(f));
353  ddClearLocal(cuddT(f));
355  return;
356 
357 } /* end of ddClearLocal */
358 
359 
373 static void
375  DdManager * table,
376  char * support)
377 {
378  int i,j;
379  int n = table->size;
380 
381  for (i = 0; i < n-1; i++) {
382  if (support[i] == 1) {
383  support[i] = 0;
384  for (j = i+1; j < n; j++) {
385  if (support[j] == 1) {
386  cuddSetInteract(table,i,j);
387  }
388  }
389  }
390  }
391  support[n-1] = 0;
392 
393 } /* end of ddUpdateInteract */
394 
395 
409 static void
411  DdManager * table)
412 {
413  int i,j;
414  DdNode *f;
415  DdNode *sentinel = &(table->sentinel);
416  DdNodePtr *nodelist;
417  int slots;
418 
419  for (i = 0; i < table->size; i++) {
420  nodelist = table->subtables[i].nodelist;
421  slots = table->subtables[i].slots;
422  for (j = 0; j < slots; j++) {
423  f = nodelist[j];
424  while (f != sentinel) {
425  f->next = Cudd_Regular(f->next);
426  f = f->next;
427  }
428  }
429  }
430 
431 } /* end of ddClearGlobal */
432 
static void ddUpdateInteract(DdManager *table, char *support)
Definition: cuddInteract.c:374
Definition: cudd.h:270
#define FREE(obj)
Definition: util.h:80
static char rcsid [] DD_UNUSED
Definition: cuddInteract.c:108
#define assert(ex)
Definition: util.h:141
int size
Definition: cuddInt.h:345
#define Cudd_Regular(node)
Definition: cudd.h:384
DdSubtable * subtables
Definition: cuddInt.h:349
#define Cudd_IsComplement(node)
Definition: cudd.h:412
DdNode sentinel
Definition: cuddInt.h:328
#define ALLOC(type, num)
Definition: util.h:76
DdNode * next
Definition: cudd.h:273
static void ddSuppInteract(DdNode *f, char *support)
Definition: cuddInteract.c:314
long * interact
Definition: cuddInt.h:377
#define cuddIsConstant(node)
Definition: cuddInt.h:593
static void ddClearLocal(DdNode *f)
Definition: cuddInteract.c:345
DdNode ** nodelist
Definition: cuddInt.h:311
int cuddInitInteract(DdManager *table)
Definition: cuddInteract.c:234
#define Cudd_Complement(node)
Definition: cudd.h:398
#define cuddT(node)
Definition: cuddInt.h:609
static void ddClearGlobal(DdManager *table)
Definition: cuddInteract.c:410
#define BPL
Definition: cuddInteract.c:89
void cuddSetInteract(DdManager *table, int x, int y)
Definition: cuddInteract.c:153
DdHalfWord index
Definition: cudd.h:271
unsigned int slots
Definition: cuddInt.h:313
#define cuddE(node)
Definition: cuddInt.h:625
int cuddTestInteract(DdManager *table, int x, int y)
Definition: cuddInteract.c:188
static int result
Definition: cuddGenetic.c:121
Cudd_ErrorType errorCode
Definition: cuddInt.h:425
#define LOGBPL
Definition: cuddInteract.c:90