82 #define DEFAULT_PAGE_SIZE 2048
83 #define DEFAULT_NODE_DIST_PAGE_SIZE 2048
84 #define MAXSHORTINT ((DdHalfWord) ~0)
89 #define INITIAL_PAGES 128
129 static char rcsid[]
DD_UNUSED =
"$Id: cuddSubsetSP.c,v 1.34 2009/02/19 16:23:19 fabio Exp $";
173 static void CreateTopDist (
st__table *pathTable,
int parentPage,
int parentQueueIndex,
int topLen,
DdNode **childPage,
int childQueueIndex,
int numParents, FILE *fp);
176 static unsigned int AssessPathLength (
unsigned int *pathLengthArray,
int threshold,
int numVars,
unsigned int *excess, FILE *fp);
326 unsigned int *pathLengthArray;
327 unsigned int maxpath, oddLen, evenLen, pathLength, *excess;
341 if (threshold > numVars) {
342 threshold = threshold - numVars;
345 fprintf(dd->
err,
"Cannot partition, nil object\n");
352 pathLengthArray =
ABC_ALLOC(
unsigned int, numVars+1);
353 for (i = 0; i < numVars+1; i++) pathLengthArray[i] = 0;
362 if ((pathTable == NULL) || (
memOut)) {
363 if (pathTable != NULL)
374 if (maxpath != (
unsigned) (numVars + 1)) {
384 (void) fprintf(dd->
out,
"Path length array\n");
385 for (i = 0; i < (numVars+1); i++) {
386 if (pathLengthArray[i])
387 (void) fprintf(dd->
out,
"%d ",i);
389 (void) fprintf(dd->
out,
"\n");
390 for (i = 0; i < (numVars+1); i++) {
391 if (pathLengthArray[i])
392 (void) fprintf(dd->
out,
"%d ",pathLengthArray[i]);
394 (void) fprintf(dd->
out,
"\n");
395 (void) fprintf(dd->
out,
"Maxpath = %d, Thresholdreached = %d\n",
400 if (!
st__lookup(pathTable, (
const char *)N, (
char **)&nodeStat)) {
401 fprintf(dd->
err,
"Something wrong, root node must be in table\n");
419 pathLength = (oddLen <= evenLen) ? oddLen : evenLen;
420 if (pathLength > maxpath) {
421 (void) fprintf(dd->
err,
"All computations are bogus, since root has path length greater than max path length within threshold %u, %u\n", maxpath, pathLength);
439 if (subset != NULL) {
445 (void) fprintf(dd->
out,
"Hits = %d, New==Node = %d, NumCalls = %d\n",
446 hits, thishit, numCalls);
469 if (subset != NULL) {
473 (void) fprintf(dd->
err,
"Wrong partition\n");
480 if (subset != NULL) {
526 if (newNodeDistPages == NULL) {
533 newNodeDistPages[i] = nodeDistPages[i];
538 nodeDistPages = newNodeDistPages;
544 if (currentNodeDistPage == NULL) {
586 if (newQueuePages == NULL) {
593 newQueuePages[i] = queuePages[i];
598 queuePages = newQueuePages;
603 if (currentQueuePage == NULL) {
638 int parentQueueIndex ,
641 int childQueueIndex ,
646 DdNode *N, *Nv, *Nnv, *node, *child, *regChild;
648 int processingDone, childrenCount;
656 if ((queuePages[parentPage] == childPage) && (parentQueueIndex ==
658 fprintf(fp,
"Should not happen that they are equal\n");
661 assert(currentQueuePage == childPage);
672 parentQueueIndex = 0;
675 node = *(queuePages[parentPage] + parentQueueIndex);
686 while (processingDone) {
690 if (processingDone == 2) {
702 if (!
st__lookup(pathTable, (
const char *)regChild, (
char **)&nodeStat)) {
799 assert(queuePages[parentPage] == childPage);
800 assert(parentQueueIndex == childQueueIndex);
803 if (childrenCount != 0) {
807 CreateTopDist(pathTable, parentPage, parentQueueIndex, topLen,
808 childPage, childQueueIndex, childrenCount, fp);
839 unsigned int * pathLengthArray ,
846 unsigned int oddLen, evenLen, pathLength;
856 if (!
st__lookup(pathTable, (
const char *)N, (
char **)&nodeStat)) {
857 fprintf(fp,
"Something wrong, the entry doesn't exist\n");
876 pathLength = (oddLen <= evenLen) ? oddLen : evenLen;
883 while (processingDone != 2) {
884 if (!processingDone) {
902 if (!
st__lookup(pathTable, (
const char *)regChild, (
char **)&nodeStatChild)) {
903 fprintf(fp,
"Something wrong, node in table should have been created in top dist proc.\n");
909 if (!
CreateBotDist(realChild, pathTable, pathLengthArray, fp))
912 fprintf(fp,
"Something wrong, both bot nodeStats should be there\n");
981 if (oddLen < pathLength ) {
983 pathLengthArray[pathLength]--;
985 pathLengthArray[oddLen]++;
988 if (evenLen < pathLength ) {
990 pathLengthArray[pathLength]--;
992 pathLengthArray[evenLen]++;
1021 unsigned int * pathLengthArray ,
1033 int childQueueIndex, parentQueueIndex;
1041 if (nodeDistPages == NULL) {
1047 if (currentNodeDistPage == NULL) {
1057 if (queuePages == NULL) {
1062 if (currentQueuePage == NULL) {
1091 nodeDistPageIndex++;
1100 insertValue =
st__insert(pathTable, (
char *)N, (
char *)nodeStat);
1109 }
else if (insertValue == 1) {
1110 fprintf(fp,
"Something wrong, the entry exists but didnt show up in st__lookup\n");
1126 CreateTopDist(pathTable, parentPage, parentQueueIndex, (
int) topLen,
1127 childPage, childQueueIndex, numParents, fp);
1129 fprintf(fp,
"Out of Memory and cant count path lengths\n");
1139 if (!
CreateBotDist(node, pathTable, pathLengthArray, fp))
return(NULL);
1147 (void) fprintf(fp,
"Out of Memory, cannot allocate pages\n");
1172 unsigned int * pathLengthArray ,
1175 unsigned int * excess ,
1187 while ((i < (
unsigned) numVars+1) && (temp > 0)) {
1188 if (pathLengthArray[i] > 0) {
1190 temp = temp - pathLengthArray[i];
1201 *excess = temp + pathLengthArray[
maxpath];
1205 fprintf(fp,
"Path Length array seems to be all zeroes, check\n");
1263 DdNode *ThenBranch, *ElseBranch, *childBranch;
1264 DdNode *child, *regChild, *regNnv = NULL, *regNv = NULL;
1265 NodeDist_t *nodeStatNv, *nodeStat, *nodeStatNnv;
1266 DdNode *neW, *topv, *regNew;
1269 unsigned int childPathLength, oddLen, evenLen, NnvPathLength = 0, NvPathLength = 0;
1270 unsigned int NvBotDist, NnvBotDist;
1272 int processingDone, thenDone, elseDone;
1283 if (!
st__lookup(pathTable, (
const char *)N, (
char **)&nodeStat)) {
1284 (void) fprintf(dd->
err,
"Something wrong, node must be in table \n");
1341 if (ThenBranch == NULL) {
1352 if (!
st__lookup(pathTable, (
const char *)regNv, (
char **)&nodeStatNv) ) {
1353 (void) fprintf(dd->
err,
"Something wrong, node must be in table\n");
1372 NvPathLength = (oddLen <= evenLen) ? oddLen : evenLen;
1373 NvBotDist = (oddLen <= evenLen) ? nodeStatNv->
oddBotDist:
1385 if (ElseBranch == NULL) {
1396 if (!
st__lookup(pathTable, (
const char *)regNnv, (
char **)&nodeStatNnv) ) {
1397 (void) fprintf(dd->
err,
"Something wrong, node must be in table\n");
1416 NnvPathLength = (oddLen <= evenLen) ? oddLen : evenLen;
1417 NnvBotDist = (oddLen <= evenLen) ? nodeStatNnv->
oddBotDist :
1421 tiebreakChild = (NvBotDist <= NnvBotDist) ? 1 : 0;
1423 while (processingDone != 2) {
1424 if (!processingDone) {
1429 if ((NvPathLength < NnvPathLength) ||
1430 ((NvPathLength == NnvPathLength) && (tiebreakChild == 1))) {
1434 childPathLength = NvPathLength;
1439 childPathLength = NnvPathLength;
1447 childPathLength = NnvPathLength;
1452 childPathLength = NvPathLength;
1459 if (childPathLength > info->
maxpath) {
1463 if (childPathLength < info->
maxpath) {
1492 (void) fprintf(dd->
err,
"OUT of memory\n");
1498 child, info,subsetNodeTable);
1509 (void) fprintf(dd->
err,
"OUT of memory\n");
1518 child, info, subsetNodeTable);
1525 if (childBranch == NULL) {
1527 if (ThenBranch != NULL) {
1531 if (ElseBranch != NULL) {
1541 ThenBranch = childBranch;
1543 ElseBranch = childBranch;
1569 if (!
st__lookup(subsetNodeTable, (
char *)regNew, (
char **)&entry)) {
1571 if (
st__insert(subsetNodeTable, (
char *)regNew,
1573 (void) fprintf(dd->
err,
"Out of memory\n");
static int queuePageIndex
void st__free_table(st__table *table)
static void ResizeNodeDistPages(void)
static int nodeDistPageSize
unsigned short DdHalfWord
static int nodeDistPageIndex
#define DEFAULT_NODE_DIST_PAGE_SIZE
DdNode * cuddSubsetShortPaths(DdManager *dd, DdNode *f, int numVars, int threshold, int hardlimit)
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
static NodeDist_t * currentNodeDistPage
int st__insert(st__table *table, const char *key, char *value)
#define Cudd_IsConstant(node)
#define Cudd_Regular(node)
int st__ptrcmp(const char *, const char *)
#define ABC_ALLOC(type, num)
static char rcsid[] DD_UNUSED
DdNode * Cudd_ReadVars(DdManager *dd, int i)
static DdNode ** currentQueuePage
int Cudd_ReadSize(DdManager *dd)
static void check(int expr)
DdNode * Cudd_bddIteConstant(DdManager *dd, DdNode *f, DdNode *g, DdNode *h)
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
static int CreateBotDist(DdNode *node, st__table *pathTable, unsigned int *pathLengthArray, FILE *fp)
#define Cudd_IsComplement(node)
static DdNode *** queuePages
static void ResizeQueuePages(void)
static int maxNodeDistPages
#define ABC_NAMESPACE_IMPL_END
#define DEFAULT_PAGE_SIZE
int st__foreach(st__table *table, enum st__retval(*func)(char *, char *, char *), char *arg)
#define ABC_NAMESPACE_IMPL_START
static enum st__retval stPathTableDdFree(char *key, char *value, char *arg)
int st__lookup(st__table *table, const char *key, char **value)
static unsigned int AssessPathLength(unsigned int *pathLengthArray, int threshold, int numVars, unsigned int *excess, FILE *fp)
DdNode * Cudd_SubsetShortPaths(DdManager *dd, DdNode *f, int numVars, int threshold, int hardlimit)
DdNode * Cudd_SupersetShortPaths(DdManager *dd, DdNode *f, int numVars, int threshold, int hardlimit)
unsigned int Cudd_NodeReadIndex(DdNode *node)
#define Cudd_NotCond(node, c)
static st__table * CreatePathTable(DdNode *node, unsigned int *pathLengthArray, FILE *fp)
int st__ptrhash(const char *, int)
static NodeDist_t ** nodeDistPages
static void CreateTopDist(st__table *pathTable, int parentPage, int parentQueueIndex, int topLen, DdNode **childPage, int childQueueIndex, int numParents, FILE *fp)
static DdNode * BuildSubsetBdd(DdManager *dd, st__table *pathTable, DdNode *node, struct AssortedInfo *info, st__table *subsetNodeTable)
DdNode * cuddBddIteRecur(DdManager *dd, DdNode *f, DdNode *g, DdNode *h)