/**CFile*********************************************************************** FileName [calInteract.c] PackageName [cal] Synopsis [Functions to manipulate the variable interaction matrix.] Description [ 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 [Original author:Fabio Somenzi. Modified for CAL package
by Rajeev K. Ranjan]
Copyright [ This file was created at the University of Colorado at
Boulder. The University of Colorado at Boulder makes no warranty
about the suitability of this software for any purpose. It is
presented on an AS IS basis.]
******************************************************************************/
#include "calInt.h"
/*---------------------------------------------------------------------------*/
/* Constant declarations */
/*---------------------------------------------------------------------------*/
#if SIZEOF_LONG == 8
#define BPL 64
#define LOGBPL 6
#else
#define BPL 32
#define LOGBPL 5
#endif
/*---------------------------------------------------------------------------*/
/* Stucture declarations */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Type declarations */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Variable declarations */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Macro declarations */
/*---------------------------------------------------------------------------*/
/**AutomaticStart*************************************************************/
/*---------------------------------------------------------------------------*/
/* Static function prototypes */
/*---------------------------------------------------------------------------*/
static void ddSuppInteract(Cal_BddManager_t *bddManager, Cal_Bdd_t f, int *support);
static void ddClearLocal(Cal_Bdd_t f);
static void ddUpdateInteract(Cal_BddManager_t *bddManager, int *support);
/**AutomaticEnd***************************************************************/
/*---------------------------------------------------------------------------*/
/* Definition of exported functions */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Definition of internal functions */
/*---------------------------------------------------------------------------*/
/**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 []
******************************************************************************/
void
CalSetInteract(Cal_BddManager_t *bddManager, int x, int y)
{
int posn, word, bit;
Cal_Assert(x < y);
Cal_Assert(y < bddManager->numVars);
Cal_Assert(x >= 0);
posn = ((((bddManager->numVars << 1) - x - 3) * x) >> 1) + y - 1;
word = posn >> LOGBPL;
bit = posn & (BPL-1);
bddManager->interact[word] |= 1 << bit;
} /* end of CalSetInteract */
/**Function********************************************************************
Synopsis [Test interaction matrix entries.]
Description [Given a pair of variables 0 <= x < y < bddManager->numVars,
tests whether the corresponding bit of the interaction matrix is 1.
Returns the value of the bit.]
SideEffects [None]
SeeAlso []
******************************************************************************/
int
CalTestInteract(Cal_BddManager_t *bddManager, int x, int y)
{
int posn, word, bit, result;
x -= 1;
y -= 1;
if (x > y) {
int tmp = x;
x = y;
y = tmp;
}
Cal_Assert(x < y);
Cal_Assert(y < bddManager->numVars);
Cal_Assert(x >= 0);
posn = ((((bddManager->numVars << 1) - x - 3) * x) >> 1) + y - 1;
word = posn >> LOGBPL;
bit = posn & (BPL-1);
result = (bddManager->interact[word] >> bit) & 1;
return(result);
} /* end of CalTestInteract */
/**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. A local flag (the mark bits)
is used.]
SideEffects [None]
SeeAlso []
******************************************************************************/
int
CalInitInteract(Cal_BddManager_t *bddManager)
{
int i,k;
int words;
long *interact;
int *support;
long numBins;
CalBddNode_t **bins, *bddNode, *nextBddNode;
int n = bddManager->numVars;
words = ((n * (n-1)) >> (1 + LOGBPL)) + 1;
bddManager->interact = interact = Cal_MemAlloc(long, words);
if (interact == NULL) return(0);
for (i = 0; i < words; i++) {
interact[i] = 0;
}
support = Cal_MemAlloc(int, n);
if (support == Cal_Nil(int)) {
Cal_MemFree(interact);
return(0);
}
bins = bddManager->uniqueTable[0]->bins;
numBins = bddManager->uniqueTable[0]->numBins;
for (i=0; i