#include "util.h"
#include "cuddInt.h"
Go to the source code of this file.
Defines | |
#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 $" |
#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 88 of file cuddInteract.c.
#define LOGBPL 5 |
Definition at line 89 of file cuddInteract.c.
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 233 of file cuddInteract.c.
00235 { 00236 int i,j,k; 00237 int words; 00238 long *interact; 00239 int *support; 00240 DdNode *f; 00241 DdNode *sentinel = &(table->sentinel); 00242 DdNodePtr *nodelist; 00243 int slots; 00244 int n = table->size; 00245 00246 words = ((n * (n-1)) >> (1 + LOGBPL)) + 1; 00247 table->interact = interact = ALLOC(long,words); 00248 if (interact == NULL) { 00249 table->errorCode = CUDD_MEMORY_OUT; 00250 return(0); 00251 } 00252 for (i = 0; i < words; i++) { 00253 interact[i] = 0; 00254 } 00255 00256 support = ALLOC(int,n); 00257 if (support == NULL) { 00258 table->errorCode = CUDD_MEMORY_OUT; 00259 FREE(interact); 00260 return(0); 00261 } 00262 00263 for (i = 0; i < n; i++) { 00264 nodelist = table->subtables[i].nodelist; 00265 slots = table->subtables[i].slots; 00266 for (j = 0; j < slots; j++) { 00267 f = nodelist[j]; 00268 while (f != sentinel) { 00269 /* A node is a root of the DAG if it cannot be 00270 ** reached by nodes above it. If a node was never 00271 ** reached during the previous depth-first searches, 00272 ** then it is a root, and we start a new depth-first 00273 ** search from it. 00274 */ 00275 if (!Cudd_IsComplement(f->next)) { 00276 for (k = 0; k < n; k++) { 00277 support[k] = 0; 00278 } 00279 ddSuppInteract(f,support); 00280 ddClearLocal(f); 00281 ddUpdateInteract(table,support); 00282 } 00283 f = Cudd_Regular(f->next); 00284 } 00285 } 00286 } 00287 ddClearGlobal(table); 00288 00289 FREE(support); 00290 return(1); 00291 00292 } /* end of cuddInitInteract */
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 152 of file cuddInteract.c.
00156 { 00157 int posn, word, bit; 00158 00159 #ifdef DD_DEBUG 00160 assert(x < y); 00161 assert(y < table->size); 00162 assert(x >= 0); 00163 #endif 00164 00165 posn = ((((table->size << 1) - x - 3) * x) >> 1) + y - 1; 00166 word = posn >> LOGBPL; 00167 bit = posn & (BPL-1); 00168 table->interact[word] |= 1L << bit; 00169 00170 } /* end of cuddSetInteract */
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 187 of file cuddInteract.c.
00191 { 00192 int posn, word, bit, result; 00193 00194 if (x > y) { 00195 int tmp = x; 00196 x = y; 00197 y = tmp; 00198 } 00199 #ifdef DD_DEBUG 00200 assert(x < y); 00201 assert(y < table->size); 00202 assert(x >= 0); 00203 #endif 00204 00205 posn = ((((table->size << 1) - x - 3) * x) >> 1) + y - 1; 00206 word = posn >> LOGBPL; 00207 bit = posn & (BPL-1); 00208 result = (table->interact[word] >> bit) & 1L; 00209 return(result); 00210 00211 } /* end of cuddTestInteract */
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 407 of file cuddInteract.c.
00409 { 00410 int i,j; 00411 DdNode *f; 00412 DdNode *sentinel = &(table->sentinel); 00413 DdNodePtr *nodelist; 00414 int slots; 00415 00416 for (i = 0; i < table->size; i++) { 00417 nodelist = table->subtables[i].nodelist; 00418 slots = table->subtables[i].slots; 00419 for (j = 0; j < slots; j++) { 00420 f = nodelist[j]; 00421 while (f != sentinel) { 00422 f->next = Cudd_Regular(f->next); 00423 f = f->next; 00424 } 00425 } 00426 } 00427 00428 } /* end of ddClearGlobal */
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 344 of file cuddInteract.c.
00346 { 00347 if (cuddIsConstant(f) || !Cudd_IsComplement(cuddT(f))) { 00348 return; 00349 } 00350 /* clear visited flag */ 00351 cuddT(f) = Cudd_Regular(cuddT(f)); 00352 ddClearLocal(cuddT(f)); 00353 ddClearLocal(Cudd_Regular(cuddE(f))); 00354 return; 00355 00356 } /* end of ddClearLocal */
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 313 of file cuddInteract.c.
00316 { 00317 if (cuddIsConstant(f) || Cudd_IsComplement(cuddT(f))) { 00318 return; 00319 } 00320 00321 support[f->index] = 1; 00322 ddSuppInteract(cuddT(f),support); 00323 ddSuppInteract(Cudd_Regular(cuddE(f)),support); 00324 /* mark as visited */ 00325 cuddT(f) = Cudd_Complement(cuddT(f)); 00326 f->next = Cudd_Complement(f->next); 00327 return; 00328 00329 } /* end of ddSuppInteract */
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 373 of file cuddInteract.c.
00376 { 00377 int i,j; 00378 int n = table->size; 00379 00380 for (i = 0; i < n-1; i++) { 00381 if (support[i] == 1) { 00382 for (j = i+1; j < n; j++) { 00383 if (support[j] == 1) { 00384 cuddSetInteract(table,i,j); 00385 } 00386 } 00387 } 00388 } 00389 00390 } /* end of ddUpdateInteract */
char rcsid [] DD_UNUSED = "$Id: cuddInteract.c,v 1.12 2004/08/13 18:04:49 fabio Exp $" [static] |
Definition at line 107 of file cuddInteract.c.