SVF
Macros | Functions | Variables
cuddInteract.c File Reference
#include "CUDD/util.h"
#include "CUDD/cuddInt.h"

Go to the source code of this file.

Macros

#define BPL   32
 
#define LOGBPL   5
 

Functions

static void ddSuppInteract (DdNode *f, char *support)
 
static void ddClearLocal (DdNode *f)
 
static void ddUpdateInteract (DdManager *table, char *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.14 2012/02/05 01:07:19 fabio Exp $"
 

Macro Definition Documentation

◆ BPL

#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 interact, but that for a given variable order have no arc connecting their layers when they are adjacent. For instance, in ite(a,b,c) with the order a<b<c, b and c interact, but are not connected.]

SeeAlso []

Author [Fabio Somenzi]

Copyright [Copyright (c) 1995-2012, 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 89 of file cuddInteract.c.

◆ LOGBPL

#define LOGBPL   5

Definition at line 90 of file cuddInteract.c.

Function Documentation

◆ cuddInitInteract()

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 234 of file cuddInteract.c.

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 */
static void ddUpdateInteract(DdManager *table, char *support)
Definition: cuddInteract.c:374
Definition: cudd.h:270
#define FREE(obj)
Definition: util.h:80
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
static void ddClearLocal(DdNode *f)
Definition: cuddInteract.c:345
DdNode ** nodelist
Definition: cuddInt.h:311
static void ddClearGlobal(DdManager *table)
Definition: cuddInteract.c:410
unsigned int slots
Definition: cuddInt.h:313
Cudd_ErrorType errorCode
Definition: cuddInt.h:425
#define LOGBPL
Definition: cuddInteract.c:90

◆ cuddSetInteract()

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 153 of file cuddInteract.c.

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 */
#define assert(ex)
Definition: util.h:141
int size
Definition: cuddInt.h:345
long * interact
Definition: cuddInt.h:377
#define BPL
Definition: cuddInteract.c:89
#define LOGBPL
Definition: cuddInteract.c:90

◆ cuddTestInteract()

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 188 of file cuddInteract.c.

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 */
#define assert(ex)
Definition: util.h:141
int size
Definition: cuddInt.h:345
long * interact
Definition: cuddInt.h:377
#define BPL
Definition: cuddInteract.c:89
static int result
Definition: cuddGenetic.c:121
#define LOGBPL
Definition: cuddInteract.c:90

◆ ddClearGlobal()

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 410 of file cuddInteract.c.

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 */
Definition: cudd.h:270
int size
Definition: cuddInt.h:345
#define Cudd_Regular(node)
Definition: cudd.h:384
DdSubtable * subtables
Definition: cuddInt.h:349
DdNode sentinel
Definition: cuddInt.h:328
DdNode * next
Definition: cudd.h:273
DdNode ** nodelist
Definition: cuddInt.h:311
unsigned int slots
Definition: cuddInt.h:313

◆ ddClearLocal()

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 345 of file cuddInteract.c.

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 */
#define Cudd_Regular(node)
Definition: cudd.h:384
#define Cudd_IsComplement(node)
Definition: cudd.h:412
#define cuddIsConstant(node)
Definition: cuddInt.h:593
static void ddClearLocal(DdNode *f)
Definition: cuddInteract.c:345
#define cuddT(node)
Definition: cuddInt.h:609
#define cuddE(node)
Definition: cuddInt.h:625

◆ ddSuppInteract()

static void ddSuppInteract ( DdNode f,
char *  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 314 of file cuddInteract.c.

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 */
#define Cudd_Regular(node)
Definition: cudd.h:384
#define Cudd_IsComplement(node)
Definition: cudd.h:412
DdNode * next
Definition: cudd.h:273
static void ddSuppInteract(DdNode *f, char *support)
Definition: cuddInteract.c:314
#define cuddIsConstant(node)
Definition: cuddInt.h:593
#define Cudd_Complement(node)
Definition: cudd.h:398
#define cuddT(node)
Definition: cuddInt.h:609
DdHalfWord index
Definition: cudd.h:271
#define cuddE(node)
Definition: cuddInt.h:625

◆ ddUpdateInteract()

static void ddUpdateInteract ( DdManager table,
char *  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 [Clears support.]

SeeAlso []

Definition at line 374 of file cuddInteract.c.

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 */
int size
Definition: cuddInt.h:345
void cuddSetInteract(DdManager *table, int x, int y)
Definition: cuddInteract.c:153

Variable Documentation

◆ DD_UNUSED

char rcsid [] DD_UNUSED = "$Id: cuddInteract.c,v 1.14 2012/02/05 01:07:19 fabio Exp $"
static

Definition at line 108 of file cuddInteract.c.