/**Function************************************************************* Synopsis [Writes reached state BDD into a BLIF file.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Llb_ManDumpReached( DdManager * ddG, DdNode * bReached, char * pModel, char * pFileName ) { FILE * pFile; Vec_Ptr_t * vNamesIn, * vNamesOut; char * pName; int i, nDigits; // reorder the BDD Cudd_ReduceHeap( ddG, CUDD_REORDER_SYMM_SIFT, 1 ); // create input names nDigits = Extra_Base10Log( Cudd_ReadSize(ddG) ); vNamesIn = Vec_PtrAlloc( Cudd_ReadSize(ddG) ); for ( i = 0; i < Cudd_ReadSize(ddG); i++ ) { pName = Llb_ManGetDummyName( "ff", i, nDigits ); Vec_PtrPush( vNamesIn, Extra_UtilStrsav(pName) ); } // create output names vNamesOut = Vec_PtrAlloc( 1 ); Vec_PtrPush( vNamesOut, Extra_UtilStrsav("Reached") ); // write the file pFile = fopen( pFileName, "wb" ); Cudd_DumpBlif( ddG, 1, &bReached, (char **)Vec_PtrArray(vNamesIn), (char **)Vec_PtrArray(vNamesOut), pModel, pFile, 0 ); fclose( pFile ); // cleanup Vec_PtrForEachEntry( char *, vNamesIn, pName, i ) ABC_FREE( pName ); Vec_PtrForEachEntry( char *, vNamesOut, pName, i ) ABC_FREE( pName ); Vec_PtrFree( vNamesIn ); Vec_PtrFree( vNamesOut ); }
/**Function************************************************************* Synopsis [Extracts sequential DCs of the network.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Abc_NtkExtractSequentialDcs( Abc_Ntk_t * pNtk, int fVerbose ) { int fReorder = 1; DdManager * dd; DdNode * bRelation, * bInitial, * bUnreach; // remove EXDC network if present if ( pNtk->pExdc ) { Abc_NtkDelete( pNtk->pExdc ); pNtk->pExdc = NULL; } // compute the global BDDs of the latches dd = Abc_NtkBuildGlobalBdds( pNtk, 10000000, 1, 1, fVerbose ); if ( dd == NULL ) return 0; if ( fVerbose ) printf( "Shared BDD size = %6d nodes.\n", Cudd_ReadKeys(dd) - Cudd_ReadDead(dd) ); // create the transition relation (dereferenced global BDDs) bRelation = Abc_NtkTransitionRelation( dd, pNtk, fVerbose ); Cudd_Ref( bRelation ); // create the initial state and the variable map bInitial = Abc_NtkInitStateAndVarMap( dd, pNtk, fVerbose ); Cudd_Ref( bInitial ); // compute the unreachable states bUnreach = Abc_NtkComputeUnreachable( dd, pNtk, bRelation, bInitial, fVerbose ); Cudd_Ref( bUnreach ); Cudd_RecursiveDeref( dd, bRelation ); Cudd_RecursiveDeref( dd, bInitial ); // reorder and disable reordering if ( fReorder ) { if ( fVerbose ) fprintf( stdout, "BDD nodes in the unreachable states before reordering %d.\n", Cudd_DagSize(bUnreach) ); Cudd_ReduceHeap( dd, CUDD_REORDER_SYMM_SIFT, 1 ); Cudd_AutodynDisable( dd ); if ( fVerbose ) fprintf( stdout, "BDD nodes in the unreachable states after reordering %d.\n", Cudd_DagSize(bUnreach) ); } // allocate ZDD variables Cudd_zddVarsFromBddVars( dd, 2 ); // create the EXDC network representing the unreachable states if ( pNtk->pExdc ) Abc_NtkDelete( pNtk->pExdc ); pNtk->pExdc = Abc_NtkConstructExdc( dd, pNtk, bUnreach ); Cudd_RecursiveDeref( dd, bUnreach ); Extra_StopManager( dd ); // pNtk->pManGlob = NULL; // make sure that everything is okay if ( pNtk->pExdc && !Abc_NtkCheck( pNtk->pExdc ) ) { printf( "Abc_NtkExtractSequentialDcs: The network check has failed.\n" ); Abc_NtkDelete( pNtk->pExdc ); return 0; } return 1; }
BddBuilder::BddBuilder(){ __pddWireHead = __pddWireTail = NULL; __pddOutputWireHead = __pddOutputWireTail = NULL; __pddOutputNodes = NULL; __pddGateHead = __pddGateTail = NULL; __pddInputNodes = NULL; __pddManager = Cudd_Init(0, 0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS , 0); Cudd_ReduceHeap(__pddManager,CUDD_REORDER_RANDOM_PIVOT,0); Cudd_AutodynEnable(__pddManager,CUDD_REORDER_RANDOM_PIVOT); __Vcc = Cudd_ReadOne(__pddManager); __GND = Cudd_ReadLogicZero(__pddManager); char * name_vcc = new char[4]; char * name_gnd = new char[4]; sprintf(name_vcc, "Vcc"); sprintf(name_gnd, "GND"); __VccWire = new DdWire(__pddManager, name_vcc, 0, 0); __GNDWire = new DdWire(__pddManager, name_gnd, 0, 0); __VccWire->setDdNode(__Vcc); __GNDWire->setDdNode(__GND); Cudd_Ref(__Vcc); Cudd_Ref(__GND); if(__pddManager == NULL){ perror("DdManager initializing error."); } //__inputWireCnt = 2; // Vcc & GND __inputWireCnt = -1; __outputWireCnt = -1; __pddInputWireHead = __VccWire; __VccWire->setInputListNext(__GNDWire); __pddInputWireTail = __GNDWire; }
/**Function******************************************************************** Synopsis [Main function for testcudd.] Description [] SideEffects [None] SeeAlso [] ******************************************************************************/ int main(int argc, char **argv) { FILE *fp; /* pointer to input file */ char *file = (char *) ""; /* input file name */ FILE *dfp = NULL; /* pointer to dump file */ char *dfile; /* file for DD dump */ DdNode *dfunc[2]; /* addresses of the functions to be dumped */ DdManager *dd; /* pointer to DD manager */ DdNode *_true; /* fast access to constant function */ DdNode *M; DdNode **x; /* pointers to variables */ DdNode **y; /* pointers to variables */ DdNode **xn; /* complements of row variables */ DdNode **yn_; /* complements of column variables */ DdNode **xvars; DdNode **yvars; DdNode *C; /* result of converting from ADD to BDD */ DdNode *ess; /* cube of essential variables */ DdNode *shortP; /* BDD cube of shortest path */ DdNode *largest; /* BDD of largest cube */ DdNode *shortA; /* ADD cube of shortest path */ DdNode *constN; /* value returned by evaluation of ADD */ DdNode *ycube; /* cube of the negated y vars for c-proj */ DdNode *CP; /* C-Projection of C */ DdNode *CPr; /* C-Selection of C */ int length; /* length of the shortest path */ int nx; /* number of variables */ int ny; int maxnx; int maxny; int m; int n; int N; int cmu; /* use CMU multiplication */ int pr; /* verbose printout level */ int harwell; int multiple; /* read multiple matrices */ int ok; int c; /* variable to read in options */ int approach; /* reordering approach */ int autodyn; /* automatic reordering */ int groupcheck; /* option for group sifting */ int profile; /* print heap profile if != 0 */ int keepperm; /* keep track of permutation */ int clearcache; /* clear the cache after each matrix */ int blifOrDot; /* dump format: 0 -> dot, 1 -> blif, ... */ int retval; /* return value */ int i; /* loop index */ long startTime; /* initial time */ long lapTime; int size; unsigned int cacheSize, maxMemory; unsigned int nvars,nslots; startTime = util_cpu_time(); approach = CUDD_REORDER_NONE; autodyn = 0; pr = 0; harwell = 0; multiple = 0; profile = 0; keepperm = 0; cmu = 0; N = 4; nvars = 4; cacheSize = 127; maxMemory = 0; nslots = CUDD_UNIQUE_SLOTS; clearcache = 0; groupcheck = CUDD_GROUP_CHECK7; dfile = NULL; blifOrDot = 0; /* dot format */ /* Parse command line. */ while ((c = util_getopt(argc, argv, (char *) "CDHMPS:a:bcd:g:hkmn:p:v:x:X:")) != EOF) { switch(c) { case 'C': cmu = 1; break; case 'D': autodyn = 1; break; case 'H': harwell = 1; break; case 'M': #ifdef MNEMOSYNE (void) mnem_setrecording(0); #endif break; case 'P': profile = 1; break; case 'S': nslots = atoi(util_optarg); break; case 'X': maxMemory = atoi(util_optarg); break; case 'a': approach = atoi(util_optarg); break; case 'b': blifOrDot = 1; /* blif format */ break; case 'c': clearcache = 1; break; case 'd': dfile = util_optarg; break; case 'g': groupcheck = atoi(util_optarg); break; case 'k': keepperm = 1; break; case 'm': multiple = 1; break; case 'n': N = atoi(util_optarg); break; case 'p': pr = atoi(util_optarg); break; case 'v': nvars = atoi(util_optarg); break; case 'x': cacheSize = atoi(util_optarg); break; case 'h': default: usage(argv[0]); break; } } if (argc - util_optind == 0) { file = (char *) "-"; } else if (argc - util_optind == 1) { file = argv[util_optind]; } else { usage(argv[0]); } if ((approach<0) || (approach>17)) { (void) fprintf(stderr,"Invalid approach: %d \n",approach); usage(argv[0]); } if (pr >= 0) { (void) printf("# %s\n", TESTCUDD_VERSION); /* Echo command line and arguments. */ (void) printf("#"); for (i = 0; i < argc; i++) { (void) printf(" %s", argv[i]); } (void) printf("\n"); (void) fflush(stdout); } /* Initialize manager and provide easy reference to terminals. */ dd = Cudd_Init(nvars,0,nslots,cacheSize,maxMemory); _true = DD_TRUE(dd); dd->groupcheck = (Cudd_AggregationType) groupcheck; if (autodyn) Cudd_AutodynEnable(dd,CUDD_REORDER_SAME); /* Open input file. */ fp = open_file(file, "r"); /* Open dump file if requested */ if (dfile != NULL) { dfp = open_file(dfile, "w"); } x = y = xn = yn_ = NULL; do { /* We want to start anew for every matrix. */ maxnx = maxny = 0; nx = maxnx; ny = maxny; if (pr>0) lapTime = util_cpu_time(); if (harwell) { if (pr >= 0) (void) printf(":name: "); ok = Cudd_addHarwell(fp, dd, &M, &x, &y, &xn, &yn_, &nx, &ny, &m, &n, 0, 2, 1, 2, pr); } else { ok = Cudd_addRead(fp, dd, &M, &x, &y, &xn, &yn_, &nx, &ny, &m, &n, 0, 2, 1, 2); if (pr >= 0) (void) printf(":name: %s: %d rows %d columns\n", file, m, n); } if (!ok) { (void) fprintf(stderr, "Error reading matrix\n"); exit(1); } if (nx > maxnx) maxnx = nx; if (ny > maxny) maxny = ny; /* Build cube of negated y's. */ ycube = DD_TRUE(dd); Cudd_Ref(ycube); for (i = maxny - 1; i >= 0; i--) { DdNode *tmpp; tmpp = Cudd_bddAnd(dd,Cudd_Not(dd->vars[y[i]->index]),ycube); if (tmpp == NULL) exit(2); Cudd_Ref(tmpp); Cudd_RecursiveDeref(dd,ycube); ycube = tmpp; } /* Initialize vectors of BDD variables used by priority func. */ xvars = ALLOC(DdNode *, nx); if (xvars == NULL) exit(2); for (i = 0; i < nx; i++) { xvars[i] = dd->vars[x[i]->index]; } yvars = ALLOC(DdNode *, ny); if (yvars == NULL) exit(2); for (i = 0; i < ny; i++) { yvars[i] = dd->vars[y[i]->index]; } /* Clean up */ for (i=0; i < maxnx; i++) { Cudd_RecursiveDeref(dd, x[i]); Cudd_RecursiveDeref(dd, xn[i]); } FREE(x); FREE(xn); for (i=0; i < maxny; i++) { Cudd_RecursiveDeref(dd, y[i]); Cudd_RecursiveDeref(dd, yn_[i]); } FREE(y); FREE(yn_); if (pr>0) {(void) printf(":1: M"); Cudd_PrintDebug(dd,M,nx+ny,pr);} if (pr>0) (void) printf(":2: time to read the matrix = %s\n", util_print_time(util_cpu_time() - lapTime)); C = Cudd_addBddPattern(dd, M); if (C == 0) exit(2); Cudd_Ref(C); if (pr>0) {(void) printf(":3: C"); Cudd_PrintDebug(dd,C,nx+ny,pr);} /* Test iterators. */ retval = testIterators(dd,M,C,pr); if (retval == 0) exit(2); cuddCacheProfile(dd,stdout); /* Test XOR */ retval = testXor(dd,C,pr,nx+ny); if (retval == 0) exit(2); /* Test Hamming distance functions. */ retval = testHamming(dd,C,pr); if (retval == 0) exit(2); /* Test selection functions. */ CP = Cudd_CProjection(dd,C,ycube); if (CP == NULL) exit(2); Cudd_Ref(CP); if (pr>0) {(void) printf("ycube"); Cudd_PrintDebug(dd,ycube,nx+ny,pr);} if (pr>0) {(void) printf("CP"); Cudd_PrintDebug(dd,CP,nx+ny,pr);} if (nx == ny) { CPr = Cudd_PrioritySelect(dd,C,xvars,yvars,(DdNode **)NULL, (DdNode *)NULL,ny,Cudd_Xgty); if (CPr == NULL) exit(2); Cudd_Ref(CPr); if (pr>0) {(void) printf(":4: CPr"); Cudd_PrintDebug(dd,CPr,nx+ny,pr);} if (CP != CPr) { (void) printf("CP != CPr!\n"); } Cudd_RecursiveDeref(dd, CPr); } FREE(xvars); FREE(yvars); Cudd_RecursiveDeref(dd, CP); Cudd_RecursiveDeref(dd, ycube); /* Test functions for essential variables. */ ess = Cudd_FindEssential(dd,C); if (ess == NULL) exit(2); Cudd_Ref(ess); if (pr>0) {(void) printf(":4: ess"); Cudd_PrintDebug(dd,ess,nx+ny,pr);} Cudd_RecursiveDeref(dd, ess); /* Test functions for shortest paths. */ shortP = Cudd_ShortestPath(dd, M, NULL, NULL, &length); if (shortP == NULL) exit(2); Cudd_Ref(shortP); if (pr>0) { (void) printf(":5: shortP"); Cudd_PrintDebug(dd,shortP,nx+ny,pr); } /* Test functions for largest cubes. */ largest = Cudd_LargestCube(dd, Cudd_Not(C), &length); if (largest == NULL) exit(2); Cudd_Ref(largest); if (pr>0) { (void) printf(":5b: largest"); Cudd_PrintDebug(dd,largest,nx+ny,pr); } Cudd_RecursiveDeref(dd, largest); /* Test Cudd_addEvalConst and Cudd_addIteConstant. */ shortA = Cudd_BddToAdd(dd,shortP); if (shortA == NULL) exit(2); Cudd_Ref(shortA); Cudd_RecursiveDeref(dd, shortP); constN = Cudd_addEvalConst(dd,shortA,M); if (constN == DD_NON_CONSTANT) exit(2); if (Cudd_addIteConstant(dd,shortA,M,constN) != constN) exit(2); if (pr>0) {(void) printf("The value of M along the chosen shortest path is %g\n", cuddV(constN));} Cudd_RecursiveDeref(dd, shortA); shortP = Cudd_ShortestPath(dd, C, NULL, NULL, &length); if (shortP == NULL) exit(2); Cudd_Ref(shortP); if (pr>0) { (void) printf(":6: shortP"); Cudd_PrintDebug(dd,shortP,nx+ny,pr); } /* Test Cudd_bddIteConstant and Cudd_bddLeq. */ if (!Cudd_bddLeq(dd,shortP,C)) exit(2); if (Cudd_bddIteConstant(dd,Cudd_Not(shortP),_true,C) != _true) exit(2); Cudd_RecursiveDeref(dd, shortP); if (profile) { retval = cuddHeapProfile(dd); } size = dd->size; if (pr>0) { (void) printf("Average distance: %g\n", Cudd_AverageDistance(dd)); } /* Reorder if so requested. */ if (approach != CUDD_REORDER_NONE) { #ifndef DD_STATS retval = Cudd_EnableReorderingReporting(dd); if (retval == 0) { (void) fprintf(stderr,"Error reported by Cudd_EnableReorderingReporting\n"); exit(3); } #endif #ifdef DD_DEBUG retval = Cudd_DebugCheck(dd); if (retval != 0) { (void) fprintf(stderr,"Error reported by Cudd_DebugCheck\n"); exit(3); } retval = Cudd_CheckKeys(dd); if (retval != 0) { (void) fprintf(stderr,"Error reported by Cudd_CheckKeys\n"); exit(3); } #endif retval = Cudd_ReduceHeap(dd,(Cudd_ReorderingType)approach,5); if (retval == 0) { (void) fprintf(stderr,"Error reported by Cudd_ReduceHeap\n"); exit(3); } #ifndef DD_STATS retval = Cudd_DisableReorderingReporting(dd); if (retval == 0) { (void) fprintf(stderr,"Error reported by Cudd_DisableReorderingReporting\n"); exit(3); } #endif #ifdef DD_DEBUG retval = Cudd_DebugCheck(dd); if (retval != 0) { (void) fprintf(stderr,"Error reported by Cudd_DebugCheck\n"); exit(3); } retval = Cudd_CheckKeys(dd); if (retval != 0) { (void) fprintf(stderr,"Error reported by Cudd_CheckKeys\n"); exit(3); } #endif if (approach == CUDD_REORDER_SYMM_SIFT || approach == CUDD_REORDER_SYMM_SIFT_CONV) { Cudd_SymmProfile(dd,0,dd->size-1); } if (pr>0) { (void) printf("Average distance: %g\n", Cudd_AverageDistance(dd)); } if (keepperm) { /* Print variable permutation. */ (void) printf("Variable Permutation:"); for (i=0; i<size; i++) { if (i%20 == 0) (void) printf("\n"); (void) printf("%d ", dd->invperm[i]); } (void) printf("\n"); (void) printf("Inverse Permutation:"); for (i=0; i<size; i++) { if (i%20 == 0) (void) printf("\n"); (void) printf("%d ", dd->perm[i]); } (void) printf("\n"); } if (pr>0) {(void) printf("M"); Cudd_PrintDebug(dd,M,nx+ny,pr);} if (profile) { retval = cuddHeapProfile(dd); } } /* Dump DDs of C and M if so requested. */ if (dfile != NULL) { dfunc[0] = C; dfunc[1] = M; if (blifOrDot == 1) { /* Only dump C because blif cannot handle ADDs */ retval = Cudd_DumpBlif(dd,1,dfunc,NULL,(char **)onames, NULL,dfp); } else { retval = Cudd_DumpDot(dd,2,dfunc,NULL,(char **)onames,dfp); } if (retval != 1) { (void) fprintf(stderr,"abnormal termination\n"); exit(2); } } Cudd_RecursiveDeref(dd, C); Cudd_RecursiveDeref(dd, M); if (clearcache) { if (pr>0) {(void) printf("Clearing the cache... ");} for (i = dd->cacheSlots - 1; i>=0; i--) { dd->cache[i].data = NIL(DdNode); } if (pr>0) {(void) printf("done\n");} } if (pr>0) { (void) printf("Number of variables = %6d\t",dd->size); (void) printf("Number of slots = %6d\n",dd->slots); (void) printf("Number of keys = %6d\t",dd->keys); (void) printf("Number of min dead = %6d\n",dd->minDead); } } while (multiple && !feof(fp)); fclose(fp); if (dfile != NULL) { fclose(dfp); } /* Second phase: experiment with Walsh matrices. */ if (!testWalsh(dd,N,cmu,approach,pr)) { exit(2); } /* Check variable destruction. */ assert(cuddDestroySubtables(dd,3)); assert(Cudd_DebugCheck(dd) == 0); assert(Cudd_CheckKeys(dd) == 0); retval = Cudd_CheckZeroRef(dd); ok = retval != 0; /* ok == 0 means O.K. */ if (retval != 0) { (void) fprintf(stderr, "%d non-zero DD reference counts after dereferencing\n", retval); } if (pr >= 0) { (void) Cudd_PrintInfo(dd,stdout); } Cudd_Quit(dd); #ifdef MNEMOSYNE mnem_writestats(); #endif if (pr>0) (void) printf("total time = %s\n", util_print_time(util_cpu_time() - startTime)); if (pr >= 0) util_print_cpu_stats(stdout); exit(ok); /* NOTREACHED */ } /* end of main */
/**Function******************************************************************** Synopsis [Tests Walsh matrix multiplication.] Description [Tests Walsh matrix multiplication. Return 1 if successful; 0 otherwise.] SideEffects [May create new variables in the manager.] SeeAlso [] ******************************************************************************/ static int testWalsh( DdManager *dd /* manager */, int N /* number of variables */, int cmu /* use CMU approach to matrix multiplication */, int approach /* reordering approach */, int pr /* verbosity level */) { DdNode *walsh1, *walsh2, *wtw; DdNode **x, **v, **z; int i, retval; DdNode *_true = DD_TRUE(dd); DdNode *_false = DD_FALSE(dd); if (N > 3) { x = ALLOC(DdNode *,N); v = ALLOC(DdNode *,N); z = ALLOC(DdNode *,N); for (i = N-1; i >= 0; i--) { Cudd_Ref(x[i]=cuddUniqueInter(dd,3*i,_true,_false)); Cudd_Ref(v[i]=cuddUniqueInter(dd,3*i+1,_true,_false)); Cudd_Ref(z[i]=cuddUniqueInter(dd,3*i+2,_true,_false)); } Cudd_Ref(walsh1 = Cudd_addWalsh(dd,v,z,N)); if (pr>0) {(void) printf("walsh1"); Cudd_PrintDebug(dd,walsh1,2*N,pr);} Cudd_Ref(walsh2 = Cudd_addWalsh(dd,x,v,N)); if (cmu) { Cudd_Ref(wtw = Cudd_addTimesPlus(dd,walsh2,walsh1,v,N)); } else { Cudd_Ref(wtw = Cudd_addMatrixMultiply(dd,walsh2,walsh1,v,N)); } if (pr>0) {(void) printf("wtw"); Cudd_PrintDebug(dd,wtw,2*N,pr);} if (approach != CUDD_REORDER_NONE) { #ifdef DD_DEBUG retval = Cudd_DebugCheck(dd); if (retval != 0) { (void) fprintf(stderr,"Error reported by Cudd_DebugCheck\n"); return(0); } #endif retval = Cudd_ReduceHeap(dd,(Cudd_ReorderingType)approach,5); if (retval == 0) { (void) fprintf(stderr,"Error reported by Cudd_ReduceHeap\n"); return(0); } #ifdef DD_DEBUG retval = Cudd_DebugCheck(dd); if (retval != 0) { (void) fprintf(stderr,"Error reported by Cudd_DebugCheck\n"); return(0); } #endif if (approach == CUDD_REORDER_SYMM_SIFT || approach == CUDD_REORDER_SYMM_SIFT_CONV) { Cudd_SymmProfile(dd,0,dd->size-1); } } /* Clean up. */ Cudd_RecursiveDeref(dd, wtw); Cudd_RecursiveDeref(dd, walsh1); Cudd_RecursiveDeref(dd, walsh2); for (i=0; i < N; i++) { Cudd_RecursiveDeref(dd, x[i]); Cudd_RecursiveDeref(dd, v[i]); Cudd_RecursiveDeref(dd, z[i]); } FREE(x); FREE(v); FREE(z); }
int main(int argc, char** argv) { unsigned int i; Biddy_Boolean complete; Biddy_Edge tmp; Biddy_Edge r1,r2; unsigned int n1,n2; char *userinput; #ifdef USA_YES unsigned int usaSize = 0; unsigned int **usaEdge; unsigned int *usaOrder; char *usaCodes; Biddy_Edge *usaState; Biddy_Edge *usaGraph; #endif #ifdef EUROPE_YES unsigned int europeSize = 0; unsigned int **europeEdge; unsigned int *europeOrder; char *europeCodes; Biddy_Edge *europeState; Biddy_Edge *europeGraph; #endif setbuf(stdout, NULL); #ifdef USA_YES setDataUSA(&usaSize,&usaEdge,&usaOrder,&usaCodes); #endif #ifdef EUROPE_YES setDataEurope(&europeSize,&europeEdge,&europeOrder,&europeCodes); #endif #ifdef USE_BIDDY /* There is only one unique table in Biddy */ /* There are three caches in Biddy */ /* Unique table grows over the time */ /* The max number of variables is hardcoded in biddyInt. h */ /* biddyVariableTable.usaSize = BIDDYVARMAX = 2048 */ /* The following constants are hardcoded in biddyMain.c */ /* biddyIteCache.usaSize = MEDIUM_TABLE = 262143 */ /* biddyEACache.usaSize = SMALL_TABLE = 65535 */ /* biddyRCCache.usaSize = SMALL_TABLE = 65535 */ /* DEFAULT INIT CALL: Biddy_Init() */ Biddy_Init(); #endif #ifdef USE_CUDD /* In CUDD each variable has its own subtable in the unique table */ /* There is only one cache in CUDD */ /* Subtables grow over the time, you can set limit for fast unique table growth */ /* Cudd_SetLooseUpTo(manager,1048576) */ /* Cache can grow over the time, you can set the max usaSize */ /* Cudd_SetMaxCacheHard(manager,262144) */ /* These two constants are hardcoded in v3.0.0 */ /* CUDD_UNIQUE_SLOTS = 256 (default initial usaSize of each subtable) */ /* CUDD_CACHE_SLOTS = 262144 (default initial usaSize of cache table) */ /* DEFAULT INIT CALL: Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0) */ manager = Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0); Cudd_SetMaxCacheHard(manager,262144); #endif #ifdef USA_YES usaGraph = (Biddy_Edge *) malloc(usaSize*sizeof(Biddy_Edge *)); usaState = (Biddy_Edge *) malloc(usaSize*sizeof(Biddy_Edge *)); #endif #ifdef EUROPE_YES europeGraph = (Biddy_Edge *) malloc(europeSize*sizeof(Biddy_Edge *)); europeState = (Biddy_Edge *) malloc(europeSize*sizeof(Biddy_Edge *)); #endif i = 0; complete = FALSE; while (!complete) { complete = TRUE; tmp = Biddy_AddVariable(); #ifdef USA_YES if (i < usaSize) { usaState[usaOrder[i]] = tmp; } complete = complete && (i >= (usaSize-1)); #endif #ifdef EUROPE_YES if (i < europeSize) { europeState[europeOrder[i]] = tmp; } complete = complete && (i >= (europeSize-1)); #endif i++; } #ifdef USA_YES createGraph(usaSize,usaEdge,usaState,usaGraph); #endif #ifdef EUROPE_YES createGraph(europeSize,europeEdge,europeState,europeGraph); #endif #ifdef USE_BIDDY Biddy_Clean(); #endif r1 = Biddy_GetConstantZero(); r2 = Biddy_GetConstantZero(); #ifdef USE_CUDD Cudd_Ref(r1); Cudd_Ref(r2); #endif #ifdef USA_YES if (!CALCULATE_KERNELS) { /* CALCULATING INDEPENDENCE SETS FOR USA */ #ifdef USE_CUDD Cudd_RecursiveDeref(manager,r1); #endif r1 = calculateIndependence(usaSize,usaState,usaGraph); } else { /* CALCULATING KERNELS (MAXIMUM INDEPENDENCE SETS) FOR USA */ #ifdef USE_CUDD Cudd_RecursiveDeref(manager,r1); #endif r1 = calculateKernels(usaSize,usaState,usaGraph); } #ifdef USE_BIDDY Biddy_AddPersistentFormula((Biddy_String)"usa",r1); Biddy_Clean(); #endif #ifdef USE_CUDD for (i=0; i<usaSize; i++) { Cudd_RecursiveDeref(manager,usaGraph[i]); } #endif #endif #ifdef EUROPE_YES if (!CALCULATE_KERNELS) { /* CALCULATING INDEPENDENCE SETS FOR EUROPE */ #ifdef USE_CUDD Cudd_RecursiveDeref(manager,r2); #endif r2 = calculateIndependence(europeSize,europeState,europeGraph); } else { /* CALCULATING KERNELS (MAXIMUM INDEPENDENCE SETS) FOR EUROPE */ #ifdef USE_CUDD Cudd_RecursiveDeref(manager,r2); #endif r2 = calculateKernels(europeSize,europeState,europeGraph); } #ifdef USE_BIDDY Biddy_AddPersistentFormula((Biddy_String)"europe",r2); Biddy_Clean(); #endif #ifdef USE_CUDD for (i=0; i<europeSize; i++) { Cudd_RecursiveDeref(manager,europeGraph[i]); } #endif #endif userinput = strdup("..."); while (userinput[0] != 'x') { /* We have problems with passing stdout in the case you compile this file */ /* with MINGW and use biddy.dll generated with Visual Studio. */ /* In such cases, please, use Biddy_PrintInfo(NULL) */ if (userinput[0] == 'r') Biddy_PrintInfo(stdout); /* SIFTING */ #ifdef USE_BIDDY #ifdef CONVERGE if (userinput[0] == 's') Biddy_PurgeAndReorder(NULL,TRUE); #ifdef USA_YES if (userinput[0] == 'u') Biddy_PurgeAndReorder(r1,TRUE); #endif #ifdef EUROPE_YES if (userinput[0] == 'e') Biddy_PurgeAndReorder(r2,TRUE); #endif #else if (userinput[0] == 's') Biddy_PurgeAndReorder(NULL,FALSE); #ifdef USA_YES if (userinput[0] == 'u') Biddy_PurgeAndReorder(r1,FALSE); #endif #ifdef EUROPE_YES if (userinput[0] == 'e') Biddy_PurgeAndReorder(r2,FALSE); #endif #endif #endif #ifdef USE_CUDD #ifdef CONVERGE if (userinput[0] == 's') Cudd_ReduceHeap(manager,CUDD_REORDER_SIFT_CONVERGE,0); #else if (userinput[0] == 's') Cudd_ReduceHeap(manager,CUDD_REORDER_SIFT,0); #endif #endif n1 = Biddy_VariableNumber(r1); n2 = Biddy_VariableNumber(r2); if ((userinput[0] == 's') #ifdef USA_YES || (userinput[0] == 'u') #endif #ifdef EUROPE_YES || (userinput[0] == 'e') #endif ) { #ifdef CONVERGE printf("(CONVERGING SIFTING"); #ifdef USE_BIDDY if (userinput[0] == 'u') { printf(" ON FUNCTION FOR USA"); } if (userinput[0] == 'e') { printf(" ON FUNCTION FOR EUROPE"); } #endif printf(") "); #else printf("(SIFTING"); #ifdef USE_BIDDY if (userinput[0] == 'u') { printf(" ON FUNCTION FOR USA"); } if (userinput[0] == 'e') { printf(" ON FUNCTION FOR EUROPE"); } #endif printf(") "); #endif } printf("Resulting function r1/r2 depends on %u/%u variables.\n",n1,n2); printf("Resulting function r1/r2 has %.0f/%.0f minterms.\n",Biddy_CountMinterm(r1,n1),Biddy_CountMinterm(r2,n2)); #ifdef USE_BIDDY printf("BDD for resulting function r1/r2 has %u/%u nodes (%u/%u nodes if using complement edges).\n", Biddy_NodeNumberPlain(r1),Biddy_NodeNumberPlain(r2),Biddy_NodeNumber(r1),Biddy_NodeNumber(r2)); #endif #ifdef USE_CUDD printf("BDD for resulting function r1/r2 has %u/%u nodes (using complement edges).\n",Biddy_NodeNumber(r1),Biddy_NodeNumber(r2)); #endif #ifdef USE_BIDDY printf("Variable swaps performed so far: %u\n",Biddy_NodeTableSwapNumber()); #endif #ifdef USE_CUDD printf("Variable swaps performed so far: %.0f\n",Cudd_ReadSwapSteps(manager)); #endif #ifdef USA_YES printf("Order for USA: "); writeOrder(r1,usaCodes,usaOrder,usaSize); #endif #ifdef EUROPE_YES printf("Order for Europe: "); writeOrder(r2,europeCodes,europeOrder,europeSize); #endif #ifdef USE_BIDDY printf("E[x]it or [r]eport or "); #ifdef CONVERGE printf("Converging sifting "); #else printf("Sifting "); #endif #if (defined USA_YES) || (defined EUROPE_YES) printf("on [s]ystem or Sifting on function for"); #ifdef USA_YES printf(" [u]SA"); #endif #ifdef EUROPE_YES printf(" [e]urope"); #endif #endif printf(": "); if (!scanf("%s",userinput)) printf("ERROR\n"); #endif #ifdef USE_CUDD printf("E[x]it or [r]eport or "); #ifdef CONVERGE printf("Converging sifting "); #else printf("Sifting "); #endif printf("on [s]ystem: "); if (!scanf("%s",userinput)) printf("ERROR\n"); #endif } free(userinput); /* EXIT */ #ifdef USE_BIDDY Biddy_Exit(); #endif #ifdef USE_CUDD Cudd_RecursiveDeref(manager,r1); Cudd_RecursiveDeref(manager,r2); printf("CUDD: nodes with non-zero reference counts: %d\n",Cudd_CheckZeroRef(manager)); Cudd_Quit(manager); #endif return 0; }
void reorderc(int method) { Cudd_ReduceHeap(mgr,method,0); }
/**Function******************************************************************** Synopsis [Applies reordering to the DDs.] Description [Explicitly applies reordering to the DDs. Returns 1 if successful; 0 otherwise.] SideEffects [None] SeeAlso [] *****************************************************************************/ static int reorder( BnetNetwork * net, DdManager * dd /* DD Manager */, NtrOptions * option) { #ifdef DD_DEBUG st_table *mintermTable; /* minterm counts for each output */ #endif int result; /* return value from functions */ (void) printf("Number of inputs = %d\n",net->ninputs); /* Perform the final reordering */ if (option->reordering != CUDD_REORDER_NONE) { #ifdef DD_DEBUG result = Cudd_DebugCheck(dd); if (result != 0) { (void) fprintf(stderr,"Error reported by Cudd_DebugCheck\n"); return(0); } result = Cudd_CheckKeys(dd); if (result != 0) { (void) fprintf(stderr,"Error reported by Cudd_CheckKeys\n"); return(0); } mintermTable = checkMinterms(net,dd,NULL); if (mintermTable == NULL) exit(2); #endif dd->siftMaxVar = 1000000; dd->siftMaxSwap = 1000000000; result = Cudd_ReduceHeap(dd,option->reordering,1); if (result == 0) return(0); #ifdef DD_DEBUG result = Cudd_DebugCheck(dd); if (result != 0) { (void) fprintf(stderr,"Error reported by Cudd_DebugCheck\n"); return(0); } result = Cudd_CheckKeys(dd); if (result != 0) { (void) fprintf(stderr,"Error reported by Cudd_CheckKeys\n"); return(0); } mintermTable = checkMinterms(net,dd,mintermTable); #endif /* Print symmetry stats if pertinent */ if (dd->tree == NULL && (option->reordering == CUDD_REORDER_SYMM_SIFT || option->reordering == CUDD_REORDER_SYMM_SIFT_CONV)) Cudd_SymmProfile(dd,0,dd->size - 1); } if (option->gaOnOff) { result = Cudd_ReduceHeap(dd,CUDD_REORDER_GENETIC,1); if (result == 0) { (void) printf("Something went wrong in cuddGa\n"); return(0); } } return(1); } /* end of reorder */