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

Go to the source code of this file.

Data Structures

struct  NodeData
 

Macros

#define DBL_MAX_EXP   1024
 
#define DEFAULT_PAGE_SIZE   2048
 
#define DEFAULT_NODE_DATA_PAGE_SIZE   1024
 
#define INITIAL_PAGES   128
 

Typedefs

typedef struct NodeData NodeData_t
 

Functions

static void ResizeNodeDataPages (void)
 
static void ResizeCountMintermPages (void)
 
static void ResizeCountNodePages (void)
 
static double SubsetCountMintermAux (DdNode *node, double max, st__table *table)
 
static st__tableSubsetCountMinterm (DdNode *node, int nvars)
 
static int SubsetCountNodesAux (DdNode *node, st__table *table, double max)
 
static int SubsetCountNodes (DdNode *node, st__table *table, int nvars)
 
static void StoreNodes (st__table *storeTable, DdManager *dd, DdNode *node)
 
static DdNodeBuildSubsetBdd (DdManager *dd, DdNode *node, int *size, st__table *visitedTable, int threshold, st__table *storeTable, st__table *approxTable)
 
DdNodeCudd_SubsetHeavyBranch (DdManager *dd, DdNode *f, int numVars, int threshold)
 
DdNodeCudd_SupersetHeavyBranch (DdManager *dd, DdNode *f, int numVars, int threshold)
 
DdNodecuddSubsetHeavyBranch (DdManager *dd, DdNode *f, int numVars, int threshold)
 

Variables

static char rcsid[] DD_UNUSED = "$Id: cuddSubsetHB.c,v 1.37 2009/02/20 02:14:58 fabio Exp $"
 
static int memOut
 
static DdNodezero
 
static DdNodeone
 
static double ** mintermPages
 
static int ** nodePages
 
static int ** lightNodePages
 
static double * currentMintermPage
 
static double max
 
static int * currentNodePage
 
static int * currentLightNodePage
 
static int pageIndex
 
static int page
 
static int pageSize = DEFAULT_PAGE_SIZE
 
static int maxPages
 
static NodeData_tcurrentNodeDataPage
 
static int nodeDataPage
 
static int nodeDataPageIndex
 
static NodeData_t ** nodeDataPages
 
static int nodeDataPageSize = DEFAULT_NODE_DATA_PAGE_SIZE
 
static int maxNodeDataPages
 

Macro Definition Documentation

#define DBL_MAX_EXP   1024

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

FileName [cuddSubsetHB.c]

PackageName [cudd]

Synopsis [Procedure to subset the given BDD by choosing the heavier branches.]

Description [External procedures provided by this module:

Internal procedures included in this module:

Static procedures included in this module:

]

SeeAlso [cuddSubsetSP.c]

Author [Kavita Ravi]

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 74 of file cuddSubsetHB.c.

#define DEFAULT_NODE_DATA_PAGE_SIZE   1024

Definition at line 88 of file cuddSubsetHB.c.

#define DEFAULT_PAGE_SIZE   2048

Definition at line 87 of file cuddSubsetHB.c.

#define INITIAL_PAGES   128

Definition at line 89 of file cuddSubsetHB.c.

Typedef Documentation

typedef struct NodeData NodeData_t

Definition at line 113 of file cuddSubsetHB.c.

Function Documentation

static DdNode * BuildSubsetBdd ( DdManager dd,
DdNode node,
int *  size,
st__table visitedTable,
int  threshold,
st__table storeTable,
st__table approxTable 
)
static

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

Synopsis [Builds the subset BDD using the heavy branch method.]

Description [The procedure carries out the building of the subset BDD starting at the root. Using the three different counts labelling each node, the procedure chooses the heavier branch starting from the root and keeps track of the number of nodes it discards at each step, thus keeping count of the size of the subset BDD dynamically. Once the threshold is satisfied, the procedure then calls ITE to build the BDD.]

SideEffects [None]

SeeAlso []

Definition at line 1158 of file cuddSubsetHB.c.

1166 {
1167 
1168  DdNode *Nv, *Nnv, *N, *topv, *neW;
1169  double minNv, minNnv;
1170  NodeData_t *currNodeQual;
1171  NodeData_t *currNodeQualT;
1172  NodeData_t *currNodeQualE;
1173  DdNode *ThenBranch, *ElseBranch;
1174  unsigned int topid;
1175  char *dummy;
1176 
1177 #ifdef DEBUG
1178  num_calls++;
1179 #endif
1180  /*If the size of the subset is below the threshold, dont do
1181  anything. */
1182  if ((*size) <= threshold) {
1183  /* store nodes below this, so we can recombine if possible */
1184  StoreNodes(storeTable, dd, node);
1185  return(node);
1186  }
1187 
1188  if (Cudd_IsConstant(node))
1189  return(node);
1190 
1191  /* Look up minterm count for this node. */
1192  if (! st__lookup(visitedTable, (const char *)node, (char **)&currNodeQual)) {
1193  fprintf(dd->err,
1194  "Something is wrong, ought to be in node quality table\n");
1195  }
1196 
1197  /* Get children. */
1198  N = Cudd_Regular(node);
1199  Nv = Cudd_T(N);
1200  Nnv = Cudd_E(N);
1201 
1202  /* complement if necessary */
1203  Nv = Cudd_NotCond(Nv, Cudd_IsComplement(node));
1204  Nnv = Cudd_NotCond(Nnv, Cudd_IsComplement(node));
1205 
1206  if (!Cudd_IsConstant(Nv)) {
1207  /* find out minterms and nodes contributed by then child */
1208  if (! st__lookup(visitedTable, (const char *)Nv, (char **)&currNodeQualT)) {
1209  fprintf(dd->out,"Something wrong, couldnt find nodes in node quality table\n");
1211  return(NULL);
1212  }
1213  else {
1214  minNv = *(((NodeData_t *)currNodeQualT)->mintermPointer);
1215  }
1216  } else {
1217  if (Nv == zero) {
1218  minNv = 0;
1219  } else {
1220  minNv = max;
1221  }
1222  }
1223  if (!Cudd_IsConstant(Nnv)) {
1224  /* find out minterms and nodes contributed by else child */
1225  if (! st__lookup(visitedTable, (const char *)Nnv, (char **)&currNodeQualE)) {
1226  fprintf(dd->out,"Something wrong, couldnt find nodes in node quality table\n");
1228  return(NULL);
1229  } else {
1230  minNnv = *(((NodeData_t *)currNodeQualE)->mintermPointer);
1231  }
1232  } else {
1233  if (Nnv == zero) {
1234  minNnv = 0;
1235  } else {
1236  minNnv = max;
1237  }
1238  }
1239 
1240  /* keep track of size of subset by subtracting the number of
1241  * differential nodes contributed by lighter child
1242  */
1243  *size = (*(size)) - (int)*(currNodeQual->lightChildNodesPointer);
1244  if (minNv >= minNnv) { /*SubsetCountNodesAux procedure takes
1245  the Then branch in case of a tie */
1246 
1247  /* recur with the Then branch */
1248  ThenBranch = (DdNode *)BuildSubsetBdd(dd, Nv, size,
1249  visitedTable, threshold, storeTable, approxTable);
1250  if (ThenBranch == NULL) {
1251  return(NULL);
1252  }
1253  cuddRef(ThenBranch);
1254  /* The Else branch is either a node that already exists in the
1255  * subset, or one whose approximation has been computed, or
1256  * Zero.
1257  */
1258  if ( st__lookup(storeTable, (char *)Cudd_Regular(Nnv), &dummy)) {
1259  ElseBranch = Nnv;
1260  cuddRef(ElseBranch);
1261  } else {
1262  if ( st__lookup(approxTable, (char *)Nnv, &dummy)) {
1263  ElseBranch = (DdNode *)dummy;
1264  cuddRef(ElseBranch);
1265  } else {
1266  ElseBranch = zero;
1267  cuddRef(ElseBranch);
1268  }
1269  }
1270 
1271  }
1272  else {
1273  /* recur with the Else branch */
1274  ElseBranch = (DdNode *)BuildSubsetBdd(dd, Nnv, size,
1275  visitedTable, threshold, storeTable, approxTable);
1276  if (ElseBranch == NULL) {
1277  return(NULL);
1278  }
1279  cuddRef(ElseBranch);
1280  /* The Then branch is either a node that already exists in the
1281  * subset, or one whose approximation has been computed, or
1282  * Zero.
1283  */
1284  if ( st__lookup(storeTable, (char *)Cudd_Regular(Nv), &dummy)) {
1285  ThenBranch = Nv;
1286  cuddRef(ThenBranch);
1287  } else {
1288  if ( st__lookup(approxTable, (char *)Nv, &dummy)) {
1289  ThenBranch = (DdNode *)dummy;
1290  cuddRef(ThenBranch);
1291  } else {
1292  ThenBranch = zero;
1293  cuddRef(ThenBranch);
1294  }
1295  }
1296  }
1297 
1298  /* construct the Bdd with the top variable and the two children */
1299  topid = Cudd_NodeReadIndex(N);
1300  topv = Cudd_ReadVars(dd, topid);
1301  cuddRef(topv);
1302  neW = cuddBddIteRecur(dd, topv, ThenBranch, ElseBranch);
1303  if (neW != NULL) {
1304  cuddRef(neW);
1305  }
1306  Cudd_RecursiveDeref(dd, topv);
1307  Cudd_RecursiveDeref(dd, ThenBranch);
1308  Cudd_RecursiveDeref(dd, ElseBranch);
1309 
1310 
1311  if (neW == NULL)
1312  return(NULL);
1313  else {
1314  /* store this node in the store table */
1315  if (! st__lookup(storeTable, (char *)Cudd_Regular(neW), &dummy)) {
1316  cuddRef(neW);
1317  if (! st__insert(storeTable, (char *)Cudd_Regular(neW), NIL(char)))
1318  return (NULL);
1319  }
1320  /* store the approximation for this node */
1321  if (N != Cudd_Regular(neW)) {
1322  if ( st__lookup(approxTable, (char *)node, &dummy)) {
1323  fprintf(dd->err, "This node should not be in the approximated table\n");
1324  } else {
1325  cuddRef(neW);
1326  if (! st__insert(approxTable, (char *)node, (char *)neW))
1327  return(NULL);
1328  }
1329  }
1330  cuddDeref(neW);
1331  return(neW);
1332  }
1333 } /* end of BuildSubsetBdd */
#define cuddRef(n)
Definition: cuddInt.h:584
#define Cudd_T(node)
Definition: cudd.h:440
#define cuddDeref(n)
Definition: cuddInt.h:604
#define Cudd_E(node)
Definition: cudd.h:455
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
static DdNode * zero
Definition: cuddSubsetHB.c:128
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
static void StoreNodes(st__table *storeTable, DdManager *dd, DdNode *node)
#define Cudd_IsConstant(node)
Definition: cudd.h:352
#define Cudd_Regular(node)
Definition: cudd.h:397
FILE * err
Definition: cuddInt.h:442
static DdNode * BuildSubsetBdd(DdManager *dd, DdNode *node, int *size, st__table *visitedTable, int threshold, st__table *storeTable, st__table *approxTable)
DdNode * Cudd_ReadVars(DdManager *dd, int i)
Definition: cuddAPI.c:2407
#define NIL(type)
Definition: avl.h:25
#define Cudd_IsComplement(node)
Definition: cudd.h:425
int * lightChildNodesPointer
Definition: cuddSubsetHB.c:106
FILE * out
Definition: cuddInt.h:441
static double max
Definition: cuddSubsetHB.c:134
static int size
Definition: cuddSign.c:86
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
unsigned int Cudd_NodeReadIndex(DdNode *node)
Definition: cuddAPI.c:2277
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
Cudd_ErrorType errorCode
Definition: cuddInt.h:447
DdNode * cuddBddIteRecur(DdManager *dd, DdNode *f, DdNode *g, DdNode *h)
Definition: cuddBddIte.c:633
DdNode* Cudd_SubsetHeavyBranch ( DdManager dd,
DdNode f,
int  numVars,
int  threshold 
)

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

Synopsis [Extracts a dense subset from a BDD with the heavy branch heuristic.]

Description [Extracts a dense subset from a BDD. This procedure builds a subset by throwing away one of the children of each node, starting from the root, until the result is small enough. The child that is eliminated from the result is the one that contributes the fewer minterms. Returns a pointer to the BDD of the subset if successful. NULL if the procedure runs out of memory. The parameter numVars is the maximum number of variables to be used in minterm calculation and node count calculation. The optimal number should be as close as possible to the size of the support of f. However, it is safe to pass the value returned by Cudd_ReadSize for numVars when the number of variables is under 1023. If numVars is larger than 1023, it will overflow. If a 0 parameter is passed then the procedure will compute a value which will avoid overflow but will cause underflow with 2046 variables or more.]

SideEffects [None]

SeeAlso [Cudd_SubsetShortPaths Cudd_SupersetHeavyBranch Cudd_ReadSize]

Definition at line 209 of file cuddSubsetHB.c.

214 {
215  DdNode *subset;
216 
217  memOut = 0;
218  do {
219  dd->reordered = 0;
220  subset = cuddSubsetHeavyBranch(dd, f, numVars, threshold);
221  } while ((dd->reordered == 1) && (!memOut));
222 
223  return(subset);
224 
225 } /* end of Cudd_SubsetHeavyBranch */
Definition: cudd.h:278
DdNode * cuddSubsetHeavyBranch(DdManager *dd, DdNode *f, int numVars, int threshold)
Definition: cuddSubsetHB.c:305
int reordered
Definition: cuddInt.h:409
static int memOut
Definition: cuddSubsetHB.c:123
DdNode* Cudd_SupersetHeavyBranch ( DdManager dd,
DdNode f,
int  numVars,
int  threshold 
)

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

Synopsis [Extracts a dense superset from a BDD with the heavy branch heuristic.]

Description [Extracts a dense superset from a BDD. The procedure is identical to the subset procedure except for the fact that it receives the complement of the given function. Extracting the subset of the complement function is equivalent to extracting the superset of the function. This procedure builds a superset by throwing away one of the children of each node starting from the root of the complement function, until the result is small enough. The child that is eliminated from the result is the one that contributes the fewer minterms. Returns a pointer to the BDD of the superset if successful. NULL if intermediate result causes the procedure to run out of memory. The parameter numVars is the maximum number of variables to be used in minterm calculation and node count calculation. The optimal number should be as close as possible to the size of the support of f. However, it is safe to pass the value returned by Cudd_ReadSize for numVars when the number of variables is under 1023. If numVars is larger than 1023, it will overflow. If a 0 parameter is passed then the procedure will compute a value which will avoid overflow but will cause underflow with 2046 variables or more.]

SideEffects [None]

SeeAlso [Cudd_SubsetHeavyBranch Cudd_SupersetShortPaths Cudd_ReadSize]

Definition at line 259 of file cuddSubsetHB.c.

264 {
265  DdNode *subset, *g;
266 
267  g = Cudd_Not(f);
268  memOut = 0;
269  do {
270  dd->reordered = 0;
271  subset = cuddSubsetHeavyBranch(dd, g, numVars, threshold);
272  } while ((dd->reordered == 1) && (!memOut));
273 
274  return(Cudd_NotCond(subset, (subset != NULL)));
275 
276 } /* end of Cudd_SupersetHeavyBranch */
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
DdNode * cuddSubsetHeavyBranch(DdManager *dd, DdNode *f, int numVars, int threshold)
Definition: cuddSubsetHB.c:305
int reordered
Definition: cuddInt.h:409
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
static int memOut
Definition: cuddSubsetHB.c:123
DdNode* cuddSubsetHeavyBranch ( DdManager dd,
DdNode f,
int  numVars,
int  threshold 
)

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

Synopsis [The main procedure that returns a subset by choosing the heavier branch in the BDD.]

Description [Here a subset BDD is built by throwing away one of the children. Starting at root, annotate each node with the number of minterms (in terms of the total number of variables specified - numVars), number of nodes taken by the DAG rooted at this node and number of additional nodes taken by the child that has the lesser minterms. The child with the lower number of minterms is thrown away and a dyanmic count of the nodes of the subset is kept. Once the threshold is reached the subset is returned to the calling procedure.]

SideEffects [None]

SeeAlso [Cudd_SubsetHeavyBranch]

Definition at line 305 of file cuddSubsetHB.c.

310 {
311 
312  int i, *size;
313  st__table *visitedTable;
314  int numNodes;
315  NodeData_t *currNodeQual;
316  DdNode *subset;
317  st__table *storeTable, *approxTable;
318  char *key, *value;
319  st__generator *stGen;
320 
321  if (f == NULL) {
322  fprintf(dd->err, "Cannot subset, nil object\n");
324  return(NULL);
325  }
326 
327  one = Cudd_ReadOne(dd);
328  zero = Cudd_Not(one);
329 
330  /* If user does not know numVars value, set it to the maximum
331  * exponent that the pow function can take. The -1 is due to the
332  * discrepancy in the value that pow takes and the value that
333  * log gives.
334  */
335  if (numVars == 0) {
336  /* set default value */
337  numVars = DBL_MAX_EXP - 1;
338  }
339 
340  if (Cudd_IsConstant(f)) {
341  return(f);
342  }
343 
344  max = pow(2.0, (double)numVars);
345 
346  /* Create visited table where structures for node data are allocated and
347  stored in a st__table */
348  visitedTable = SubsetCountMinterm(f, numVars);
349  if ((visitedTable == NULL) || memOut) {
350  (void) fprintf(dd->err, "Out-of-memory; Cannot subset\n");
352  return(0);
353  }
354  numNodes = SubsetCountNodes(f, visitedTable, numVars);
355  if (memOut) {
356  (void) fprintf(dd->err, "Out-of-memory; Cannot subset\n");
358  return(0);
359  }
360 
361  if ( st__lookup(visitedTable, (const char *)f, (char **)&currNodeQual) == 0) {
362  fprintf(dd->err,
363  "Something is wrong, ought to be node quality table\n");
365  }
366 
367  size = ABC_ALLOC(int, 1);
368  if (size == NULL) {
370  return(NULL);
371  }
372  *size = numNodes;
373 
374 #ifdef DEBUG
375  num_calls = 0;
376 #endif
377  /* table to store nodes being created. */
378  storeTable = st__init_table( st__ptrcmp, st__ptrhash);
379  /* insert the constant */
380  cuddRef(one);
381  if ( st__insert(storeTable, (char *)Cudd_ReadOne(dd), NIL(char)) ==
382  st__OUT_OF_MEM) {
383  fprintf(dd->out, "Something wrong, st__table insert failed\n");
384  }
385  /* table to store approximations of nodes */
386  approxTable = st__init_table( st__ptrcmp, st__ptrhash);
387  subset = (DdNode *)BuildSubsetBdd(dd, f, size, visitedTable, threshold,
388  storeTable, approxTable);
389  if (subset != NULL) {
390  cuddRef(subset);
391  }
392 
393  stGen = st__init_gen(approxTable);
394  if (stGen == NULL) {
395  st__free_table(approxTable);
396  return(NULL);
397  }
398  while( st__gen(stGen, (const char **)&key, (char **)&value)) {
399  Cudd_RecursiveDeref(dd, (DdNode *)value);
400  }
401  st__free_gen(stGen); stGen = NULL;
402  st__free_table(approxTable);
403 
404  stGen = st__init_gen(storeTable);
405  if (stGen == NULL) {
406  st__free_table(storeTable);
407  return(NULL);
408  }
409  while( st__gen(stGen, (const char **)&key, (char **)&value)) {
410  Cudd_RecursiveDeref(dd, (DdNode *)key);
411  }
412  st__free_gen(stGen); stGen = NULL;
413  st__free_table(storeTable);
414 
415  for (i = 0; i <= page; i++) {
417  }
419  for (i = 0; i <= page; i++) {
420  ABC_FREE(nodePages[i]);
421  }
423  for (i = 0; i <= page; i++) {
425  }
427  for (i = 0; i <= nodeDataPage; i++) {
429  }
431  st__free_table(visitedTable);
432  ABC_FREE(size);
433 #if 0
434  (void) Cudd_DebugCheck(dd);
435  (void) Cudd_CheckKeys(dd);
436 #endif
437 
438  if (subset != NULL) {
439 #ifdef DD_DEBUG
440  if (!Cudd_bddLeq(dd, subset, f)) {
441  fprintf(dd->err, "Wrong subset\n");
443  return(NULL);
444  }
445 #endif
446  cuddDeref(subset);
447  return(subset);
448  } else {
449  return(NULL);
450  }
451 } /* end of cuddSubsetHeavyBranch */
void st__free_table(st__table *table)
Definition: st.c:81
#define cuddRef(n)
Definition: cuddInt.h:584
static int SubsetCountNodes(DdNode *node, st__table *table, int nvars)
#define cuddDeref(n)
Definition: cuddInt.h:604
static int ** nodePages
Definition: cuddSubsetHB.c:130
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
static int page
Definition: cuddSubsetHB.c:142
static DdNode * zero
Definition: cuddSubsetHB.c:128
void st__free_gen(st__generator *gen)
Definition: st.c:556
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
#define Cudd_IsConstant(node)
Definition: cudd.h:352
static int ** lightNodePages
Definition: cuddSubsetHB.c:131
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
FILE * err
Definition: cuddInt.h:442
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static DdNode * one
Definition: cuddSubsetHB.c:128
static DdNode * BuildSubsetBdd(DdManager *dd, DdNode *node, int *size, st__table *visitedTable, int threshold, st__table *storeTable, st__table *approxTable)
static st__table * SubsetCountMinterm(DdNode *node, int nvars)
Definition: cuddSubsetHB.c:791
#define NIL(type)
Definition: avl.h:25
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
FILE * out
Definition: cuddInt.h:441
Definition: st.h:52
static double max
Definition: cuddSubsetHB.c:134
static double ** mintermPages
Definition: cuddSubsetHB.c:129
int Cudd_DebugCheck(DdManager *table)
Definition: cuddCheck.c:142
static int size
Definition: cuddSign.c:86
st__generator * st__init_gen(st__table *table)
Definition: st.c:486
#define st__OUT_OF_MEM
Definition: st.h:113
static int nodeDataPage
Definition: cuddSubsetHB.c:148
DdNode * Cudd_ReadOne(DdManager *dd)
Definition: cuddAPI.c:987
int Cudd_bddLeq(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:536
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
static NodeData_t ** nodeDataPages
Definition: cuddSubsetHB.c:150
#define ABC_FREE(obj)
Definition: abc_global.h:232
enum keys key
int Cudd_CheckKeys(DdManager *table)
Definition: cuddCheck.c:458
#define DBL_MAX_EXP
Definition: cuddSubsetHB.c:74
int value
static int memOut
Definition: cuddSubsetHB.c:123
Cudd_ErrorType errorCode
Definition: cuddInt.h:447
int st__ptrhash(const char *, int)
Definition: st.c:468
int st__gen(st__generator *gen, const char **key_p, char **value_p)
Definition: st.c:502
static void ResizeCountMintermPages ( void  )
static

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

Synopsis [Resize the number of pages allocated to store the minterm counts. ]

Description [Resize the number of pages allocated to store the minterm counts. The procedure moves the counter to the next page when the end of the page is reached and allocates new pages when necessary.]

SideEffects [Changes the size of minterm pages, page, page index, maximum number of pages freeing stuff in case of memory out. ]

SeeAlso []

Definition at line 533 of file cuddSubsetHB.c.

534 {
535  int i;
536  double **newMintermPages;
537 
538  page++;
539  /* If the current page index is larger than the number of pages
540  * allocated, allocate a new page array. Page numbers are incremented by
541  * INITIAL_PAGES
542  */
543  if (page == maxPages) {
544  newMintermPages = ABC_ALLOC(double *,maxPages + INITIAL_PAGES);
545  if (newMintermPages == NULL) {
546  for (i = 0; i < page; i++) ABC_FREE(mintermPages[i]);
548  memOut = 1;
549  return;
550  } else {
551  for (i = 0; i < maxPages; i++) {
552  newMintermPages[i] = mintermPages[i];
553  }
554  /* Increase total page count */
555  maxPages += INITIAL_PAGES;
557  mintermPages = newMintermPages;
558  }
559  }
560  /* Allocate a new page */
562  if (currentMintermPage == NULL) {
563  for (i = 0; i < page; i++) ABC_FREE(mintermPages[i]);
565  memOut = 1;
566  return;
567  }
568  /* reset page index */
569  pageIndex = 0;
570  return;
571 
572 } /* end of ResizeCountMintermPages */
static double * currentMintermPage
Definition: cuddSubsetHB.c:132
static int page
Definition: cuddSubsetHB.c:142
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int maxPages
Definition: cuddSubsetHB.c:144
static double ** mintermPages
Definition: cuddSubsetHB.c:129
#define INITIAL_PAGES
Definition: cuddSubsetHB.c:89
static int pageIndex
Definition: cuddSubsetHB.c:141
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int pageSize
Definition: cuddSubsetHB.c:143
static int memOut
Definition: cuddSubsetHB.c:123
static void ResizeCountNodePages ( void  )
static

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

Synopsis [Resize the number of pages allocated to store the node counts.]

Description [Resize the number of pages allocated to store the node counts. The procedure moves the counter to the next page when the end of the page is reached and allocates new pages when necessary.]

SideEffects [Changes the size of pages, page, page index, maximum number of pages freeing stuff in case of memory out.]

SeeAlso []

Definition at line 590 of file cuddSubsetHB.c.

591 {
592  int i;
593  int **newNodePages;
594 
595  page++;
596 
597  /* If the current page index is larger than the number of pages
598  * allocated, allocate a new page array. The number of pages is incremented
599  * by INITIAL_PAGES.
600  */
601  if (page == maxPages) {
602  newNodePages = ABC_ALLOC(int *,maxPages + INITIAL_PAGES);
603  if (newNodePages == NULL) {
604  for (i = 0; i < page; i++) ABC_FREE(nodePages[i]);
606  for (i = 0; i < page; i++) ABC_FREE(lightNodePages[i]);
608  memOut = 1;
609  return;
610  } else {
611  for (i = 0; i < maxPages; i++) {
612  newNodePages[i] = nodePages[i];
613  }
615  nodePages = newNodePages;
616  }
617 
618  newNodePages = ABC_ALLOC(int *,maxPages + INITIAL_PAGES);
619  if (newNodePages == NULL) {
620  for (i = 0; i < page; i++) ABC_FREE(nodePages[i]);
622  for (i = 0; i < page; i++) ABC_FREE(lightNodePages[i]);
624  memOut = 1;
625  return;
626  } else {
627  for (i = 0; i < maxPages; i++) {
628  newNodePages[i] = lightNodePages[i];
629  }
631  lightNodePages = newNodePages;
632  }
633  /* Increase total page count */
635  }
636  /* Allocate a new page */
638  if (currentNodePage == NULL) {
639  for (i = 0; i < page; i++) ABC_FREE(nodePages[i]);
641  for (i = 0; i < page; i++) ABC_FREE(lightNodePages[i]);
643  memOut = 1;
644  return;
645  }
646  /* Allocate a new page */
648  if (currentLightNodePage == NULL) {
649  for (i = 0; i <= page; i++) ABC_FREE(nodePages[i]);
651  for (i = 0; i < page; i++) ABC_FREE(lightNodePages[i]);
653  memOut = 1;
654  return;
655  }
656  /* reset page index */
657  pageIndex = 0;
658  return;
659 
660 } /* end of ResizeCountNodePages */
static int ** nodePages
Definition: cuddSubsetHB.c:130
static int page
Definition: cuddSubsetHB.c:142
static int * currentNodePage
Definition: cuddSubsetHB.c:137
static int ** lightNodePages
Definition: cuddSubsetHB.c:131
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int maxPages
Definition: cuddSubsetHB.c:144
static int * currentLightNodePage
Definition: cuddSubsetHB.c:139
#define INITIAL_PAGES
Definition: cuddSubsetHB.c:89
static int pageIndex
Definition: cuddSubsetHB.c:141
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int pageSize
Definition: cuddSubsetHB.c:143
static int memOut
Definition: cuddSubsetHB.c:123
static void ResizeNodeDataPages ( void  )
static

AutomaticStart

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

Synopsis [Resize the number of pages allocated to store the node data.]

Description [Resize the number of pages allocated to store the node data The procedure moves the counter to the next page when the end of the page is reached and allocates new pages when necessary.]

SideEffects [Changes the size of pages, page, page index, maximum number of pages freeing stuff in case of memory out. ]

SeeAlso []

Definition at line 474 of file cuddSubsetHB.c.

475 {
476  int i;
477  NodeData_t **newNodeDataPages;
478 
479  nodeDataPage++;
480  /* If the current page index is larger than the number of pages
481  * allocated, allocate a new page array. Page numbers are incremented by
482  * INITIAL_PAGES
483  */
485  newNodeDataPages = ABC_ALLOC(NodeData_t *,maxNodeDataPages + INITIAL_PAGES);
486  if (newNodeDataPages == NULL) {
487  for (i = 0; i < nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
489  memOut = 1;
490  return;
491  } else {
492  for (i = 0; i < maxNodeDataPages; i++) {
493  newNodeDataPages[i] = nodeDataPages[i];
494  }
495  /* Increase total page count */
496  maxNodeDataPages += INITIAL_PAGES;
498  nodeDataPages = newNodeDataPages;
499  }
500  }
501  /* Allocate a new page */
504  if (currentNodeDataPage == NULL) {
505  for (i = 0; i < nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
507  memOut = 1;
508  return;
509  }
510  /* reset page index */
511  nodeDataPageIndex = 0;
512  return;
513 
514 } /* end of ResizeNodeDataPages */
static int maxNodeDataPages
Definition: cuddSubsetHB.c:153
static NodeData_t * currentNodeDataPage
Definition: cuddSubsetHB.c:146
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int nodeDataPageIndex
Definition: cuddSubsetHB.c:149
#define INITIAL_PAGES
Definition: cuddSubsetHB.c:89
static int nodeDataPage
Definition: cuddSubsetHB.c:148
static NodeData_t ** nodeDataPages
Definition: cuddSubsetHB.c:150
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int memOut
Definition: cuddSubsetHB.c:123
static int nodeDataPageSize
Definition: cuddSubsetHB.c:151
static void StoreNodes ( st__table storeTable,
DdManager dd,
DdNode node 
)
static

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

Synopsis [Procedure to recursively store nodes that are retained in the subset.]

Description [rocedure to recursively store nodes that are retained in the subset.]

SideEffects [None]

SeeAlso [StoreNodes]

Definition at line 1113 of file cuddSubsetHB.c.

1117 {
1118  DdNode *N, *Nt, *Ne;
1119  if (Cudd_IsConstant(dd)) {
1120  return;
1121  }
1122  N = Cudd_Regular(node);
1123  if ( st__lookup(storeTable, (char *)N, NIL(char *))) {
1124  return;
1125  }
1126  cuddRef(N);
1127  if ( st__insert(storeTable, (char *)N, NIL(char)) == st__OUT_OF_MEM) {
1128  fprintf(dd->err,"Something wrong, st__table insert failed\n");
1129  }
1130 
1131  Nt = Cudd_T(N);
1132  Ne = Cudd_E(N);
1133 
1134  StoreNodes(storeTable, dd, Nt);
1135  StoreNodes(storeTable, dd, Ne);
1136  return;
1137 
1138 }
#define cuddRef(n)
Definition: cuddInt.h:584
#define Cudd_T(node)
Definition: cudd.h:440
#define Cudd_E(node)
Definition: cudd.h:455
Definition: cudd.h:278
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
static void StoreNodes(st__table *storeTable, DdManager *dd, DdNode *node)
#define Cudd_IsConstant(node)
Definition: cudd.h:352
#define Cudd_Regular(node)
Definition: cudd.h:397
FILE * err
Definition: cuddInt.h:442
#define NIL(type)
Definition: avl.h:25
#define st__OUT_OF_MEM
Definition: st.h:113
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
static st__table * SubsetCountMinterm ( DdNode node,
int  nvars 
)
static

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

Synopsis [Counts minterms of each node in the DAG]

Description [Counts minterms of each node in the DAG. Similar to the Cudd_CountMinterm procedure except this returns the minterm count for all the nodes in the bdd in an st__table.]

SideEffects [none]

SeeAlso [SubsetCountMintermAux]

Definition at line 791 of file cuddSubsetHB.c.

794 {
795  st__table *table;
796  int i;
797 
798 
799 #ifdef DEBUG
800  num_calls = 0;
801 #endif
802 
803  max = pow(2.0,(double) nvars);
805  if (table == NULL) goto OUT_OF_MEM;
807  mintermPages = ABC_ALLOC(double *,maxPages);
808  if (mintermPages == NULL) {
809  st__free_table(table);
810  goto OUT_OF_MEM;
811  }
812  page = 0;
815  if (currentMintermPage == NULL) {
817  st__free_table(table);
818  goto OUT_OF_MEM;
819  }
820  pageIndex = 0;
823  if (nodeDataPages == NULL) {
824  for (i = 0; i <= page ; i++) ABC_FREE(mintermPages[i]);
826  st__free_table(table);
827  goto OUT_OF_MEM;
828  }
829  nodeDataPage = 0;
832  if (currentNodeDataPage == NULL) {
833  for (i = 0; i <= page ; i++) ABC_FREE(mintermPages[i]);
836  st__free_table(table);
837  goto OUT_OF_MEM;
838  }
839  nodeDataPageIndex = 0;
840 
841  (void) SubsetCountMintermAux(node,max,table);
842  if (memOut) goto OUT_OF_MEM;
843  return(table);
844 
845 OUT_OF_MEM:
846  memOut = 1;
847  return(NULL);
848 
849 } /* end of SubsetCountMinterm */
void st__free_table(st__table *table)
Definition: st.c:81
static int maxNodeDataPages
Definition: cuddSubsetHB.c:153
static double * currentMintermPage
Definition: cuddSubsetHB.c:132
static int page
Definition: cuddSubsetHB.c:142
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
static NodeData_t * currentNodeDataPage
Definition: cuddSubsetHB.c:146
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int nodeDataPageIndex
Definition: cuddSubsetHB.c:149
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
static int maxPages
Definition: cuddSubsetHB.c:144
Definition: st.h:52
static double max
Definition: cuddSubsetHB.c:134
static double ** mintermPages
Definition: cuddSubsetHB.c:129
#define INITIAL_PAGES
Definition: cuddSubsetHB.c:89
static int pageIndex
Definition: cuddSubsetHB.c:141
static int nodeDataPage
Definition: cuddSubsetHB.c:148
static NodeData_t ** nodeDataPages
Definition: cuddSubsetHB.c:150
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int pageSize
Definition: cuddSubsetHB.c:143
static double SubsetCountMintermAux(DdNode *node, double max, st__table *table)
Definition: cuddSubsetHB.c:680
static int memOut
Definition: cuddSubsetHB.c:123
int st__ptrhash(const char *, int)
Definition: st.c:468
static int nodeDataPageSize
Definition: cuddSubsetHB.c:151
static double SubsetCountMintermAux ( DdNode node,
double  max,
st__table table 
)
static

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

Synopsis [Recursively counts minterms of each node in the DAG.]

Description [Recursively counts minterms of each node in the DAG. Similar to the cuddCountMintermAux which recursively counts the number of minterms for the dag rooted at each node in terms of the total number of variables (max). This procedure creates the node data structure and stores the minterm count as part of the node data structure. ]

SideEffects [Creates structures of type node quality and fills the st__table]

SeeAlso [SubsetCountMinterm]

Definition at line 680 of file cuddSubsetHB.c.

684 {
685 
686  DdNode *N,*Nv,*Nnv; /* nodes to store cofactors */
687  double min,*pmin; /* minterm count */
688  double min1, min2; /* minterm count */
689  NodeData_t *dummy;
690  NodeData_t *newEntry;
691  int i;
692 
693 #ifdef DEBUG
694  num_calls++;
695 #endif
696 
697  /* Constant case */
698  if (Cudd_IsConstant(node)) {
699  if (node == zero) {
700  return(0.0);
701  } else {
702  return(max);
703  }
704  } else {
705 
706  /* check if entry for this node exists */
707  if ( st__lookup(table, (const char *)node, (char **)&dummy)) {
708  min = *(dummy->mintermPointer);
709  return(min);
710  }
711 
712  /* Make the node regular to extract cofactors */
713  N = Cudd_Regular(node);
714 
715  /* store the cofactors */
716  Nv = Cudd_T(N);
717  Nnv = Cudd_E(N);
718 
719  Nv = Cudd_NotCond(Nv, Cudd_IsComplement(node));
720  Nnv = Cudd_NotCond(Nnv, Cudd_IsComplement(node));
721 
722  min1 = SubsetCountMintermAux(Nv, max,table)/2.0;
723  if (memOut) return(0.0);
724  min2 = SubsetCountMintermAux(Nnv,max,table)/2.0;
725  if (memOut) return(0.0);
726  min = (min1+min2);
727 
728  /* if page index is at the bottom, then create a new page */
730  if (memOut) {
731  for (i = 0; i <= nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
733  st__free_table(table);
734  return(0.0);
735  }
736 
737  /* point to the correct location in the page */
739  pageIndex++;
740 
741  /* store the minterm count of this node in the page */
742  *pmin = min;
743 
744  /* Note I allocate the struct here. Freeing taken care of later */
746  if (memOut) {
747  for (i = 0; i <= page; i++) ABC_FREE(mintermPages[i]);
749  st__free_table(table);
750  return(0.0);
751  }
752 
754  nodeDataPageIndex++;
755 
756  /* points to the correct location in the page */
757  newEntry->mintermPointer = pmin;
758  /* initialize this field of the Node Quality structure */
759  newEntry->nodesPointer = NULL;
760 
761  /* insert entry for the node in the table */
762  if ( st__insert(table,(char *)node, (char *)newEntry) == st__OUT_OF_MEM) {
763  memOut = 1;
764  for (i = 0; i <= page; i++) ABC_FREE(mintermPages[i]);
766  for (i = 0; i <= nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
768  st__free_table(table);
769  return(0.0);
770  }
771  return(min);
772  }
773 
774 } /* end of SubsetCountMintermAux */
void st__free_table(st__table *table)
Definition: st.c:81
#define Cudd_T(node)
Definition: cudd.h:440
static double * currentMintermPage
Definition: cuddSubsetHB.c:132
#define Cudd_E(node)
Definition: cudd.h:455
double * mintermPointer
Definition: cuddSubsetHB.c:104
Definition: cudd.h:278
static int page
Definition: cuddSubsetHB.c:142
static DdNode * zero
Definition: cuddSubsetHB.c:128
int * nodesPointer
Definition: cuddSubsetHB.c:105
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
#define Cudd_IsConstant(node)
Definition: cudd.h:352
#define Cudd_Regular(node)
Definition: cudd.h:397
static void ResizeCountMintermPages(void)
Definition: cuddSubsetHB.c:533
static NodeData_t * currentNodeDataPage
Definition: cuddSubsetHB.c:146
static int nodeDataPageIndex
Definition: cuddSubsetHB.c:149
#define Cudd_IsComplement(node)
Definition: cudd.h:425
static double max
Definition: cuddSubsetHB.c:134
static void ResizeNodeDataPages(void)
Definition: cuddSubsetHB.c:474
static double ** mintermPages
Definition: cuddSubsetHB.c:129
static int pageIndex
Definition: cuddSubsetHB.c:141
#define st__OUT_OF_MEM
Definition: st.h:113
static int nodeDataPage
Definition: cuddSubsetHB.c:148
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
static NodeData_t ** nodeDataPages
Definition: cuddSubsetHB.c:150
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
static int pageSize
Definition: cuddSubsetHB.c:143
static double SubsetCountMintermAux(DdNode *node, double max, st__table *table)
Definition: cuddSubsetHB.c:680
static int memOut
Definition: cuddSubsetHB.c:123
static int nodeDataPageSize
Definition: cuddSubsetHB.c:151
static int SubsetCountNodes ( DdNode node,
st__table table,
int  nvars 
)
static

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

Synopsis [Counts the nodes under the current node and its lighter child]

Description [Counts the nodes under the current node and its lighter child. Calls a recursive procedure to count the number of nodes of a DAG rooted at a particular node and the number of nodes taken by its lighter child.]

SideEffects [None]

SeeAlso [SubsetCountNodesAux]

Definition at line 1036 of file cuddSubsetHB.c.

1040 {
1041  int num;
1042  int i;
1043 
1044 #ifdef DEBUG
1045  num_calls = 0;
1046 #endif
1047 
1048  max = pow(2.0,(double) nvars);
1050  nodePages = ABC_ALLOC(int *,maxPages);
1051  if (nodePages == NULL) {
1052  goto OUT_OF_MEM;
1053  }
1054 
1056  if (lightNodePages == NULL) {
1057  for (i = 0; i <= page; i++) ABC_FREE(mintermPages[i]);
1059  for (i = 0; i <= nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
1062  goto OUT_OF_MEM;
1063  }
1064 
1065  page = 0;
1067  if (currentNodePage == NULL) {
1068  for (i = 0; i <= page; i++) ABC_FREE(mintermPages[i]);
1070  for (i = 0; i <= nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
1074  goto OUT_OF_MEM;
1075  }
1076 
1078  if (currentLightNodePage == NULL) {
1079  for (i = 0; i <= page; i++) ABC_FREE(mintermPages[i]);
1081  for (i = 0; i <= nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
1086  goto OUT_OF_MEM;
1087  }
1088 
1089  pageIndex = 0;
1090  num = SubsetCountNodesAux(node,table,max);
1091  if (memOut) goto OUT_OF_MEM;
1092  return(num);
1093 
1094 OUT_OF_MEM:
1095  memOut = 1;
1096  return(0);
1097 
1098 } /* end of SubsetCountNodes */
static int ** nodePages
Definition: cuddSubsetHB.c:130
static int page
Definition: cuddSubsetHB.c:142
static int * currentNodePage
Definition: cuddSubsetHB.c:137
static int ** lightNodePages
Definition: cuddSubsetHB.c:131
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int maxPages
Definition: cuddSubsetHB.c:144
static int * currentLightNodePage
Definition: cuddSubsetHB.c:139
static double max
Definition: cuddSubsetHB.c:134
static double ** mintermPages
Definition: cuddSubsetHB.c:129
#define INITIAL_PAGES
Definition: cuddSubsetHB.c:89
static int pageIndex
Definition: cuddSubsetHB.c:141
static int nodeDataPage
Definition: cuddSubsetHB.c:148
static NodeData_t ** nodeDataPages
Definition: cuddSubsetHB.c:150
static int SubsetCountNodesAux(DdNode *node, st__table *table, double max)
Definition: cuddSubsetHB.c:872
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int pageSize
Definition: cuddSubsetHB.c:143
static int memOut
Definition: cuddSubsetHB.c:123
static int SubsetCountNodesAux ( DdNode node,
st__table table,
double  max 
)
static

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

Synopsis [Recursively counts the number of nodes under the dag. Also counts the number of nodes under the lighter child of this node.]

Description [Recursively counts the number of nodes under the dag. Also counts the number of nodes under the lighter child of this node. . Note that the same dag may be the lighter child of two different nodes and have different counts. As with the minterm counts, the node counts are stored in pages to be space efficient and the address for these node counts are stored in an st__table associated to each node. ]

SideEffects [Updates the node data table with node counts]

SeeAlso [SubsetCountNodes]

Definition at line 872 of file cuddSubsetHB.c.

876 {
877  int tval, eval, i;
878  DdNode *N, *Nv, *Nnv;
879  double minNv, minNnv;
880  NodeData_t *dummyN, *dummyNv, *dummyNnv, *dummyNBar;
881  int *pmin, *pminBar, *val;
882 
883  if ((node == NULL) || Cudd_IsConstant(node))
884  return(0);
885 
886  /* if this node has been processed do nothing */
887  if ( st__lookup(table, (const char *)node, (char **)&dummyN) == 1) {
888  val = dummyN->nodesPointer;
889  if (val != NULL)
890  return(0);
891  } else {
892  return(0);
893  }
894 
895  N = Cudd_Regular(node);
896  Nv = Cudd_T(N);
897  Nnv = Cudd_E(N);
898 
899  Nv = Cudd_NotCond(Nv, Cudd_IsComplement(node));
900  Nnv = Cudd_NotCond(Nnv, Cudd_IsComplement(node));
901 
902  /* find the minterm counts for the THEN and ELSE branches */
903  if (Cudd_IsConstant(Nv)) {
904  if (Nv == zero) {
905  minNv = 0.0;
906  } else {
907  minNv = max;
908  }
909  } else {
910  if ( st__lookup(table, (const char *)Nv, (char **)&dummyNv) == 1)
911  minNv = *(dummyNv->mintermPointer);
912  else {
913  return(0);
914  }
915  }
916  if (Cudd_IsConstant(Nnv)) {
917  if (Nnv == zero) {
918  minNnv = 0.0;
919  } else {
920  minNnv = max;
921  }
922  } else {
923  if ( st__lookup(table, (const char *)Nnv, (char **)&dummyNnv) == 1) {
924  minNnv = *(dummyNnv->mintermPointer);
925  }
926  else {
927  return(0);
928  }
929  }
930 
931 
932  /* recur based on which has larger minterm, */
933  if (minNv >= minNnv) {
934  tval = SubsetCountNodesAux(Nv, table, max);
935  if (memOut) return(0);
936  eval = SubsetCountNodesAux(Nnv, table, max);
937  if (memOut) return(0);
938 
939  /* store the node count of the lighter child. */
941  if (memOut) {
942  for (i = 0; i <= page; i++) ABC_FREE(mintermPages[i]);
944  for (i = 0; i <= nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
946  st__free_table(table);
947  return(0);
948  }
950  *pmin = eval; /* Here the ELSE child is lighter */
951  dummyN->lightChildNodesPointer = pmin;
952 
953  } else {
954  eval = SubsetCountNodesAux(Nnv, table, max);
955  if (memOut) return(0);
956  tval = SubsetCountNodesAux(Nv, table, max);
957  if (memOut) return(0);
958 
959  /* store the node count of the lighter child. */
961  if (memOut) {
962  for (i = 0; i <= page; i++) ABC_FREE(mintermPages[i]);
964  for (i = 0; i <= nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
966  st__free_table(table);
967  return(0);
968  }
970  *pmin = tval; /* Here the THEN child is lighter */
971  dummyN->lightChildNodesPointer = pmin;
972 
973  }
974  /* updating the page index for node count storage. */
975  pmin = currentNodePage + pageIndex;
976  *pmin = tval + eval + 1;
977  dummyN->nodesPointer = pmin;
978 
979  /* pageIndex is parallel page index for count_nodes and count_lightNodes */
980  pageIndex++;
981 
982  /* if this node has been reached first, it belongs to a heavier
983  branch. Its complement will be reached later on a lighter branch.
984  Hence the complement has zero node count. */
985 
986  if ( st__lookup(table, (const char *)Cudd_Not(node), (char **)&dummyNBar) == 1) {
987  if (pageIndex == pageSize) ResizeCountNodePages();
988  if (memOut) {
989  for (i = 0; i < page; i++) ABC_FREE(mintermPages[i]);
991  for (i = 0; i < nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
993  st__free_table(table);
994  return(0);
995  }
996  pminBar = currentLightNodePage + pageIndex;
997  *pminBar = 0;
998  dummyNBar->lightChildNodesPointer = pminBar;
999  /* The lighter child has less nodes than the parent.
1000  * So if parent 0 then lighter child zero
1001  */
1002  if (pageIndex == pageSize) ResizeCountNodePages();
1003  if (memOut) {
1004  for (i = 0; i < page; i++) ABC_FREE(mintermPages[i]);
1006  for (i = 0; i < nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
1008  st__free_table(table);
1009  return(0);
1010  }
1011  pminBar = currentNodePage + pageIndex;
1012  *pminBar = 0;
1013  dummyNBar->nodesPointer = pminBar ; /* maybe should point to zero */
1014 
1015  pageIndex++;
1016  }
1017  return(*pmin);
1018 } /*end of SubsetCountNodesAux */
void st__free_table(st__table *table)
Definition: st.c:81
#define Cudd_T(node)
Definition: cudd.h:440
#define Cudd_E(node)
Definition: cudd.h:455
double * mintermPointer
Definition: cuddSubsetHB.c:104
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
static int page
Definition: cuddSubsetHB.c:142
static DdNode * zero
Definition: cuddSubsetHB.c:128
int * nodesPointer
Definition: cuddSubsetHB.c:105
static int * currentNodePage
Definition: cuddSubsetHB.c:137
#define Cudd_IsConstant(node)
Definition: cudd.h:352
#define Cudd_Regular(node)
Definition: cudd.h:397
#define Cudd_IsComplement(node)
Definition: cudd.h:425
int * lightChildNodesPointer
Definition: cuddSubsetHB.c:106
static int * currentLightNodePage
Definition: cuddSubsetHB.c:139
static void ResizeCountNodePages(void)
Definition: cuddSubsetHB.c:590
static double max
Definition: cuddSubsetHB.c:134
static double ** mintermPages
Definition: cuddSubsetHB.c:129
static int pageIndex
Definition: cuddSubsetHB.c:141
static int nodeDataPage
Definition: cuddSubsetHB.c:148
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
static NodeData_t ** nodeDataPages
Definition: cuddSubsetHB.c:150
static int SubsetCountNodesAux(DdNode *node, st__table *table, double max)
Definition: cuddSubsetHB.c:872
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
static int pageSize
Definition: cuddSubsetHB.c:143
static int memOut
Definition: cuddSubsetHB.c:123

Variable Documentation

int* currentLightNodePage
static

Definition at line 139 of file cuddSubsetHB.c.

double* currentMintermPage
static

Definition at line 132 of file cuddSubsetHB.c.

NodeData_t* currentNodeDataPage
static

Definition at line 146 of file cuddSubsetHB.c.

int* currentNodePage
static

Definition at line 137 of file cuddSubsetHB.c.

char rcsid [] DD_UNUSED = "$Id: cuddSubsetHB.c,v 1.37 2009/02/20 02:14:58 fabio Exp $"
static

Definition at line 120 of file cuddSubsetHB.c.

int** lightNodePages
static

Definition at line 131 of file cuddSubsetHB.c.

double max
static

Definition at line 134 of file cuddSubsetHB.c.

int maxNodeDataPages
static

Definition at line 153 of file cuddSubsetHB.c.

int maxPages
static

Definition at line 144 of file cuddSubsetHB.c.

int memOut
static

Definition at line 123 of file cuddSubsetHB.c.

double** mintermPages
static

Definition at line 129 of file cuddSubsetHB.c.

int nodeDataPage
static

Definition at line 148 of file cuddSubsetHB.c.

int nodeDataPageIndex
static

Definition at line 149 of file cuddSubsetHB.c.

NodeData_t** nodeDataPages
static

Definition at line 150 of file cuddSubsetHB.c.

int nodeDataPageSize = DEFAULT_NODE_DATA_PAGE_SIZE
static

Definition at line 151 of file cuddSubsetHB.c.

int** nodePages
static

Definition at line 130 of file cuddSubsetHB.c.

DdNode * one
static

Definition at line 128 of file cuddSubsetHB.c.

int page
static

Definition at line 142 of file cuddSubsetHB.c.

int pageIndex
static

Definition at line 141 of file cuddSubsetHB.c.

int pageSize = DEFAULT_PAGE_SIZE
static

Definition at line 143 of file cuddSubsetHB.c.

DdNode* zero
static

Definition at line 128 of file cuddSubsetHB.c.