abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cuddInteract.c File Reference
#include "misc/util/util_hack.h"
#include "cuddInt.h"

Go to the source code of this file.

Macros

#define BPL   32
 
#define LOGBPL   5
 

Functions

static void ddSuppInteract (DdNode *f, int *support)
 
static void ddClearLocal (DdNode *f)
 
static void ddUpdateInteract (DdManager *table, int *support)
 
static void ddClearGlobal (DdManager *table)
 
void cuddSetInteract (DdManager *table, int x, int y)
 
int cuddTestInteract (DdManager *table, int x, int y)
 
int cuddInitInteract (DdManager *table)
 

Variables

static char rcsid[] DD_UNUSED = "$Id: cuddInteract.c,v 1.12 2004/08/13 18:04:49 fabio Exp $"
 

Macro Definition Documentation

#define BPL   32

CFile***********************************************************************

FileName [cuddInteract.c]

PackageName [cudd]

Synopsis [Functions to manipulate the variable interaction matrix.]

Description [Internal procedures included in this file:

Static procedures included in this file:

The interaction matrix tells whether two variables are both in the support of some function of the DD. The main use of the interaction matrix is in the in-place swapping. Indeed, if two variables do not interact, there is no arc connecting the two layers; therefore, the swap can be performed in constant time, without scanning the subtables. Another use of the interaction matrix is in the computation of the lower bounds for sifting. Finally, the interaction matrix can be used to speed up aggregation checks in symmetric and group sifting.

The computation of the interaction matrix is done with a series of depth-first searches. The searches start from those nodes that have only external references. The matrix is stored as a packed array of bits; since it is symmetric, only the upper triangle is kept in memory. As a final remark, we note that there may be variables that do intercat, but that for a given variable order have no arc connecting their layers when they are adjacent.]

SeeAlso []

Author [Fabio Somenzi]

Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of the University of Colorado nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.]

Definition at line 92 of file cuddInteract.c.

#define LOGBPL   5

Definition at line 93 of file cuddInteract.c.

Function Documentation

int cuddInitInteract ( DdManager table)

Function********************************************************************

Synopsis [Initializes the interaction matrix.]

Description [Initializes the interaction matrix. The interaction matrix is implemented as a bit vector storing the upper triangle of the symmetric interaction matrix. The bit vector is kept in an array of long integers. The computation is based on a series of depth-first searches, one for each root of the DAG. Two flags are needed: The local visited flag uses the LSB of the then pointer. The global visited flag uses the LSB of the next pointer. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso []

Definition at line 237 of file cuddInteract.c.

239 {
240  int i,j,k;
241  ABC_UINT64_T words;
242  long *interact;
243  int *support;
244  DdNode *f;
245  DdNode *sentinel = &(table->sentinel);
246  DdNodePtr *nodelist;
247  int slots;
248  int n = table->size;
249 
250  words = ((n * (n-1)) >> (1 + LOGBPL)) + 1;
251  table->interact = interact = ABC_ALLOC(long,(unsigned)words);
252  if (interact == NULL) {
253  table->errorCode = CUDD_MEMORY_OUT;
254  return(0);
255  }
256  for (i = 0; i < words; i++) {
257  interact[i] = 0;
258  }
259 
260  support = ABC_ALLOC(int,n);
261  if (support == NULL) {
262  table->errorCode = CUDD_MEMORY_OUT;
263  ABC_FREE(interact);
264  return(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  for (k = 0; k < n; k++) {
281  support[k] = 0;
282  }
283  ddSuppInteract(f,support);
284  ddClearLocal(f);
285  ddUpdateInteract(table,support);
286  }
287  f = Cudd_Regular(f->next);
288  }
289  }
290  }
291  ddClearGlobal(table);
292 
293  ABC_FREE(support);
294  return(1);
295 
296 } /* end of cuddInitInteract */
Definition: cudd.h:278
int size
Definition: cuddInt.h:361
#define Cudd_Regular(node)
Definition: cudd.h:397
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
DdSubtable * subtables
Definition: cuddInt.h:365
#define Cudd_IsComplement(node)
Definition: cudd.h:425
DdNode sentinel
Definition: cuddInt.h:344
DdNode * next
Definition: cudd.h:281
long * interact
Definition: cuddInt.h:394
static void ddClearLocal(DdNode *f)
Definition: cuddInteract.c:348
DdNode ** nodelist
Definition: cuddInt.h:327
static void ddSuppInteract(DdNode *f, int *support)
Definition: cuddInteract.c:317
static void ddClearGlobal(DdManager *table)
Definition: cuddInteract.c:411
#define ABC_FREE(obj)
Definition: abc_global.h:232
unsigned int slots
Definition: cuddInt.h:329
static void ddUpdateInteract(DdManager *table, int *support)
Definition: cuddInteract.c:377
Cudd_ErrorType errorCode
Definition: cuddInt.h:447
#define LOGBPL
Definition: cuddInteract.c:93
void cuddSetInteract ( DdManager table,
int  x,
int  y 
)

AutomaticEnd Function********************************************************************

Synopsis [Set interaction matrix entries.]

Description [Given a pair of variables 0 <= x < y < table->size, sets the corresponding bit of the interaction matrix to 1.]

SideEffects [None]

SeeAlso []

Definition at line 156 of file cuddInteract.c.

160 {
161  int posn, word, bit;
162 
163 #ifdef DD_DEBUG
164  assert(x < y);
165  assert(y < table->size);
166  assert(x >= 0);
167 #endif
168 
169  posn = ((((table->size << 1) - x - 3) * x) >> 1) + y - 1;
170  word = posn >> LOGBPL;
171  bit = posn & (BPL-1);
172  table->interact[word] |= 1L << bit;
173 
174 } /* end of cuddSetInteract */
int size
Definition: cuddInt.h:361
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
long * interact
Definition: cuddInt.h:394
static int size
Definition: cuddSign.c:86
#define BPL
Definition: cuddInteract.c:92
#define assert(ex)
Definition: util_old.h:213
#define LOGBPL
Definition: cuddInteract.c:93
int cuddTestInteract ( DdManager table,
int  x,
int  y 
)

Function********************************************************************

Synopsis [Test interaction matrix entries.]

Description [Given a pair of variables 0 <= x < y < table->size, tests whether the corresponding bit of the interaction matrix is 1. Returns the value of the bit.]

SideEffects [None]

SeeAlso []

Definition at line 191 of file cuddInteract.c.

195 {
196  int posn, word, bit, result;
197 
198  if (x > y) {
199  int tmp = x;
200  x = y;
201  y = tmp;
202  }
203 #ifdef DD_DEBUG
204  assert(x < y);
205  assert(y < table->size);
206  assert(x >= 0);
207 #endif
208 
209  posn = ((((table->size << 1) - x - 3) * x) >> 1) + y - 1;
210  word = posn >> LOGBPL;
211  bit = posn & (BPL-1);
212  result = (table->interact[word] >> bit) & 1L;
213  return(result);
214 
215 } /* end of cuddTestInteract */
int size
Definition: cuddInt.h:361
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
long * interact
Definition: cuddInt.h:394
static int size
Definition: cuddSign.c:86
#define BPL
Definition: cuddInteract.c:92
#define assert(ex)
Definition: util_old.h:213
static int result
Definition: cuddGenetic.c:125
#define LOGBPL
Definition: cuddInteract.c:93
static void ddClearGlobal ( DdManager table)
static

Function********************************************************************

Synopsis [Scans the DD and clears the LSB of the next pointers.]

Description [The LSB of the next pointers are used as markers to tell whether a node was reached by at least one DFS. Once the interaction matrix is built, these flags are reset.]

SideEffects [None]

SeeAlso []

Definition at line 411 of file cuddInteract.c.

413 {
414  int i,j;
415  DdNode *f;
416  DdNode *sentinel = &(table->sentinel);
417  DdNodePtr *nodelist;
418  int slots;
419 
420  for (i = 0; i < table->size; i++) {
421  nodelist = table->subtables[i].nodelist;
422  slots = table->subtables[i].slots;
423  for (j = 0; j < slots; j++) {
424  f = nodelist[j];
425  while (f != sentinel) {
426  f->next = Cudd_Regular(f->next);
427  f = f->next;
428  }
429  }
430  }
431 
432 } /* end of ddClearGlobal */
Definition: cudd.h:278
int size
Definition: cuddInt.h:361
#define Cudd_Regular(node)
Definition: cudd.h:397
DdSubtable * subtables
Definition: cuddInt.h:365
DdNode sentinel
Definition: cuddInt.h:344
DdNode * next
Definition: cudd.h:281
DdNode ** nodelist
Definition: cuddInt.h:327
unsigned int slots
Definition: cuddInt.h:329
static void ddClearLocal ( DdNode f)
static

Function********************************************************************

Synopsis [Performs a DFS from f, clearing the LSB of the then pointers.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 348 of file cuddInteract.c.

350 {
351  if (cuddIsConstant(f) || !Cudd_IsComplement(cuddT(f))) {
352  return;
353  }
354  /* clear visited flag */
355  cuddT(f) = Cudd_Regular(cuddT(f));
356  ddClearLocal(cuddT(f));
358  return;
359 
360 } /* end of ddClearLocal */
#define Cudd_Regular(node)
Definition: cudd.h:397
#define Cudd_IsComplement(node)
Definition: cudd.h:425
#define cuddIsConstant(node)
Definition: cuddInt.h:620
static void ddClearLocal(DdNode *f)
Definition: cuddInteract.c:348
#define cuddT(node)
Definition: cuddInt.h:636
#define cuddE(node)
Definition: cuddInt.h:652
static void ddSuppInteract ( DdNode f,
int *  support 
)
static

AutomaticStart

Function********************************************************************

Synopsis [Find the support of f.]

Description [Performs a DFS from f. Uses the LSB of the then pointer as visited flag.]

SideEffects [Accumulates in support the variables on which f depends.]

SeeAlso []

Definition at line 317 of file cuddInteract.c.

320 {
321  if (cuddIsConstant(f) || Cudd_IsComplement(cuddT(f))) {
322  return;
323  }
324 
325  support[f->index] = 1;
326  ddSuppInteract(cuddT(f),support);
327  ddSuppInteract(Cudd_Regular(cuddE(f)),support);
328  /* mark as visited */
329  cuddT(f) = Cudd_Complement(cuddT(f));
330  f->next = Cudd_Complement(f->next);
331  return;
332 
333 } /* end of ddSuppInteract */
#define Cudd_Regular(node)
Definition: cudd.h:397
#define Cudd_IsComplement(node)
Definition: cudd.h:425
DdNode * next
Definition: cudd.h:281
#define cuddIsConstant(node)
Definition: cuddInt.h:620
#define Cudd_Complement(node)
Definition: cudd.h:411
#define cuddT(node)
Definition: cuddInt.h:636
static void ddSuppInteract(DdNode *f, int *support)
Definition: cuddInteract.c:317
DdHalfWord index
Definition: cudd.h:279
#define cuddE(node)
Definition: cuddInt.h:652
static void ddUpdateInteract ( DdManager table,
int *  support 
)
static

Function********************************************************************

Synopsis [Marks as interacting all pairs of variables that appear in support.]

Description [If support[i] == support[j] == 1, sets the (i,j) entry of the interaction matrix to 1.]

SideEffects [None]

SeeAlso []

Definition at line 377 of file cuddInteract.c.

380 {
381  int i,j;
382  int n = table->size;
383 
384  for (i = 0; i < n-1; i++) {
385  if (support[i] == 1) {
386  for (j = i+1; j < n; j++) {
387  if (support[j] == 1) {
388  cuddSetInteract(table,i,j);
389  }
390  }
391  }
392  }
393 
394 } /* end of ddUpdateInteract */
int size
Definition: cuddInt.h:361
void cuddSetInteract(DdManager *table, int x, int y)
Definition: cuddInteract.c:156

Variable Documentation

char rcsid [] DD_UNUSED = "$Id: cuddInteract.c,v 1.12 2004/08/13 18:04:49 fabio Exp $"
static

Definition at line 111 of file cuddInteract.c.