61 #define TESTCUDD_VERSION "TestCudd Version #1.0, Release date 3/17/01"
68 static char rcsid[]
DD_UNUSED =
"$Id: testcudd.c,v 1.20 2009/03/08 02:49:02 fabio Exp $";
71 static const char *
onames[] = {
"C",
"M" };
79 static void usage (
char * prog);
104 char *file = (
char *)
"";
152 unsigned int cacheSize, maxMemory;
153 unsigned int nvars,nslots;
176 while ((c =
util_getopt(argc, argv, (
char *)
"CDHMPS:a:bcd:g:hkmn:p:v:x:X:"))
190 (void) mnem_setrecording(0);
249 if ((approach<0) || (approach>17)) {
250 (void) fprintf(stderr,
"Invalid approach: %d \n",approach);
258 for (i = 0; i < argc; i++) {
259 (void) printf(
" %s", argv[i]);
262 (void) fflush(stdout);
266 dd =
Cudd_Init(nvars,0,nslots,cacheSize,maxMemory);
279 x = y = xn = yn_ = NULL;
283 nx = maxnx; ny = maxny;
286 if (pr >= 0) (void) printf(
":name: ");
288 &m, &n, 0, 2, 1, 2, pr);
290 ok =
Cudd_addRead(fp, dd, &M, &x, &y, &xn, &yn_, &nx, &ny,
293 (void) printf(
":name: %s: %d rows %d columns\n", file, m, n);
296 (void) fprintf(stderr,
"Error reading matrix\n");
300 if (nx > maxnx) maxnx = nx;
301 if (ny > maxny) maxny = ny;
306 for (i = maxny - 1; i >= 0; i--) {
309 if (tmpp == NULL)
exit(2);
316 if (xvars == NULL)
exit(2);
317 for (i = 0; i < nx; i++) {
321 if (yvars == NULL)
exit(2);
322 for (i = 0; i < ny; i++) {
327 for (i=0; i < maxnx; i++) {
333 for (i=0; i < maxny; i++) {
342 if (pr>0) (void) printf(
":2: time to read the matrix = %s\n",
352 if (retval == 0)
exit(2);
357 retval =
testXor(dd,C,pr,nx+ny);
358 if (retval == 0)
exit(2);
362 if (retval == 0)
exit(2);
366 if (CP == NULL)
exit(2);
368 if (pr>0) {(void) printf(
"ycube");
Cudd_PrintDebug(dd,ycube,nx+ny,pr);}
374 if (CPr == NULL)
exit(2);
376 if (pr>0) {(void) printf(
":4: CPr");
Cudd_PrintDebug(dd,CPr,nx+ny,pr);}
378 (void) printf(
"CP != CPr!\n");
385 int Nmin =
ddMin(nx,ny);
390 if (f == NULL)
exit(2);
393 (void) printf(
":4: ineq");
397 for (q = 0; q < dd->
size; q++) {
412 (void) printf(
" 1\n");
426 if (ess == NULL)
exit(2);
428 if (pr>0) {(void) printf(
":4: ess");
Cudd_PrintDebug(dd,ess,nx+ny,pr);}
433 if (shortP == NULL)
exit(2);
440 if (largest == NULL)
exit(2);
443 (void) printf(
":5b: largest");
450 if (shortA == NULL)
exit(2);
456 if (pr>0) {(void) printf(
"The value of M along the chosen shortest path is %g\n",
cuddV(constN));}
460 if (shortP == NULL)
exit(2);
486 (void) fprintf(stderr,
"Error reported by Cudd_EnableReorderingReporting\n");
493 (void) fprintf(stderr,
"Error reported by Cudd_DebugCheck\n");
498 (void) fprintf(stderr,
"Error reported by Cudd_CheckKeys\n");
504 (void) fprintf(stderr,
"Error reported by Cudd_ReduceHeap\n");
510 (void) fprintf(stderr,
"Error reported by Cudd_DisableReorderingReporting\n");
517 (void) fprintf(stderr,
"Error reported by Cudd_DebugCheck\n");
522 (void) fprintf(stderr,
"Error reported by Cudd_CheckKeys\n");
537 (void) printf(
"Variable Permutation:");
538 for (i=0; i<
size; i++) {
539 if (i%20 == 0) (void) printf(
"\n");
540 (void) printf(
"%d ", dd->
invperm[i]);
543 (void) printf(
"Inverse Permutation:");
544 for (i=0; i<
size; i++) {
545 if (i%20 == 0) (void) printf(
"\n");
546 (void) printf(
"%d ", dd->
perm[i]);
563 if (blifOrDot == 1) {
571 (void) fprintf(stderr,
"abnormal termination\n");
580 if (pr>0) {(void) printf(
"Clearing the cache... ");}
584 if (pr>0) {(void) printf(
"done\n");}
587 (void) printf(
"Number of variables = %6d\t",dd->
size);
588 (void) printf(
"Number of slots = %6u\n",dd->
slots);
589 (void) printf(
"Number of keys = %6u\t",dd->
keys);
590 (void) printf(
"Number of min dead = %6u\n",dd->
minDead);
593 }
while (multiple && !feof(fp));
613 (void) fprintf(stderr,
614 "%d non-zero DD reference counts after dereferencing\n", retval);
627 if (pr>0) (void) printf(
"total time = %s\n",
630 if (pr >= 0) util_print_cpu_stats(stdout);
656 (void) fprintf(stderr,
"usage: %s [options] [file]\n", prog);
657 (void) fprintf(stderr,
" -C\t\tuse CMU multiplication algorithm\n");
658 (void) fprintf(stderr,
" -D\t\tenable automatic dynamic reordering\n");
659 (void) fprintf(stderr,
" -H\t\tread matrix in Harwell format\n");
660 (void) fprintf(stderr,
" -M\t\tturns off memory allocation recording\n");
661 (void) fprintf(stderr,
" -P\t\tprint BDD heap profile\n");
662 (void) fprintf(stderr,
" -S n\t\tnumber of slots for each subtable\n");
663 (void) fprintf(stderr,
" -X n\t\ttarget maximum memory in bytes\n");
664 (void) fprintf(stderr,
" -a n\t\tchoose reordering approach (0-13)\n");
665 (void) fprintf(stderr,
" \t\t\t0: same as autoMethod\n");
666 (void) fprintf(stderr,
" \t\t\t1: no reordering (default)\n");
667 (void) fprintf(stderr,
" \t\t\t2: random\n");
668 (void) fprintf(stderr,
" \t\t\t3: pivot\n");
669 (void) fprintf(stderr,
" \t\t\t4: sifting\n");
670 (void) fprintf(stderr,
" \t\t\t5: sifting to convergence\n");
671 (void) fprintf(stderr,
" \t\t\t6: symmetric sifting\n");
672 (void) fprintf(stderr,
" \t\t\t7: symmetric sifting to convergence\n");
673 (void) fprintf(stderr,
" \t\t\t8-10: window of size 2-4\n");
674 (void) fprintf(stderr,
" \t\t\t11-13: window of size 2-4 to conv.\n");
675 (void) fprintf(stderr,
" \t\t\t14: group sifting\n");
676 (void) fprintf(stderr,
" \t\t\t15: group sifting to convergence\n");
677 (void) fprintf(stderr,
" \t\t\t16: simulated annealing\n");
678 (void) fprintf(stderr,
" \t\t\t17: genetic algorithm\n");
679 (void) fprintf(stderr,
" -b\t\tuse blif as format for dumps\n");
680 (void) fprintf(stderr,
" -c\t\tclear the cache after each matrix\n");
681 (void) fprintf(stderr,
" -d file\tdump DDs to file\n");
682 (void) fprintf(stderr,
" -g\t\tselect aggregation criterion (0,5,7)\n");
683 (void) fprintf(stderr,
" -h\t\tprints this message\n");
684 (void) fprintf(stderr,
" -k\t\tprint the variable permutation\n");
685 (void) fprintf(stderr,
" -m\t\tread multiple matrices (only with -H)\n");
686 (void) fprintf(stderr,
" -n n\t\tnumber of variables\n");
687 (void) fprintf(stderr,
" -p n\t\tcontrol verbosity\n");
688 (void) fprintf(stderr,
" -v n\t\tinitial variables in the unique table\n");
689 (void) fprintf(stderr,
" -x n\t\tinitial size of the cache\n");
711 if (
strcmp(filename,
"-") == 0) {
712 return mode[0] ==
'r' ? stdin : stdout;
713 }
else if ((fp = fopen(filename, mode)) == NULL) {
742 DdNode *walsh1, *walsh2, *wtw;
753 for (i = N-1; i >= 0; i--) {
759 if (pr>0) {(void) printf(
"walsh1");
Cudd_PrintDebug(dd,walsh1,2*N,pr);}
772 (void) fprintf(stderr,
"Error reported by Cudd_DebugCheck\n");
778 (void) fprintf(stderr,
"Error reported by Cudd_ReduceHeap\n");
784 (void) fprintf(stderr,
"Error reported by Cudd_DebugCheck\n");
797 for (i=0; i < N; i++) {
835 (void) printf(
"Testing iterator on cubes:\n");
837 for (q = 0; q < dd->
size; q++) {
852 (void) printf(
" %g\n",value);
858 (void) printf(
"Testing prime expansion of cubes:\n");
863 (void) printf(
"Testing iterator on primes (CNF):\n");
865 for (q = 0; q < dd->
size; q++) {
880 (void) printf(
" 1\n");
888 (void) printf(
"Testing iterator on nodes:\n");
891 #if SIZEOF_VOID_P == 8
892 (void) printf(
"ID = 0x%lx\tvalue = %-9g\n",
897 (void) printf(
"ID = 0x%x\tvalue = %-9g\n",
903 #if SIZEOF_VOID_P == 8
904 (void) printf(
"ID = 0x%lx\tindex = %u\tr = %u\n",
909 (void) printf(
"ID = 0x%x\tindex = %u\tr = %u\n",
940 DdNode *f1, *f0, *res1, *res2;
946 if (f1 == NULL)
return(0);
958 if (res1 == NULL)
return(0);
1027 if (vars == NULL)
return(0);
1028 for (i = 0; i <
size; i++) {
1035 (void) printf(
"Chosen minterm for Hamming distance test: ");
1039 minterm =
ALLOC(
int,size);
1040 if (minterm == NULL) {
1056 minterm[R->
index] = 0;
1059 minterm[R->
index] = 1;
1067 (void) printf(
"Minimum Hamming distance = %d\n", d);
void Cudd_IterDerefBdd(DdManager *table, DdNode *n)
Cudd_AggregationType groupcheck
double Cudd_AverageDistance(DdManager *dd)
DdNode * Cudd_FindEssential(DdManager *dd, DdNode *f)
DdNode * Cudd_CProjection(DdManager *dd, DdNode *R, DdNode *Y)
static char rcsid[] DD_UNUSED
#define CUDD_UNIQUE_SLOTS
DdNode * Cudd_bddPickOneMinterm(DdManager *dd, DdNode *f, DdNode **vars, int n)
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
int main(int argc, char **argv)
DdNode * Cudd_ShortestPath(DdManager *manager, DdNode *f, int *weight, int *support, int *length)
#define Cudd_ForeachCube(manager, f, gen, cube, value)
DdNode * Cudd_Xgty(DdManager *dd, int N, DdNode **z, DdNode **x, DdNode **y)
DdNode * Cudd_addBddPattern(DdManager *dd, DdNode *f)
#define Cudd_IsConstant(node)
#define Cudd_ForeachPrime(manager, l, u, gen, cube)
DdNode * Cudd_addEvalConst(DdManager *dd, DdNode *f, DdNode *g)
#define Cudd_Regular(node)
int cuddHeapProfile(DdManager *dd)
static int testWalsh(DdManager *dd, int N, int cmu, int approach, int pr)
DdNode * Cudd_addIteConstant(DdManager *dd, DdNode *f, DdNode *g, DdNode *h)
int Cudd_addHarwell(FILE *fp, DdManager *dd, DdNode **E, DdNode ***x, DdNode ***y, DdNode ***xn, DdNode ***yn_, int *nx, int *ny, int *m, int *n, int bx, int sx, int by, int sy, int pr)
DdNode * Cudd_bddIte(DdManager *dd, DdNode *f, DdNode *g, DdNode *h)
static FILE * open_file(char *filename, const char *mode)
word M(word f1, word f2, int n)
int Cudd_ReadSize(DdManager *dd)
DdNode * Cudd_PrioritySelect(DdManager *dd, DdNode *R, DdNode **x, DdNode **y, DdNode **z, DdNode *Pi, int n, DdNode *(*)(DdManager *, int, DdNode **, DdNode **, DdNode **))
DdNode * Cudd_LargestCube(DdManager *manager, DdNode *f, int *length)
static const char * onames[]
DdNode * Cudd_bddIteConstant(DdManager *dd, DdNode *f, DdNode *g, DdNode *h)
#define Cudd_ForeachNode(manager, f, gen, node)
static int testHamming(DdManager *dd, DdNode *f, int pr)
DdNode * Cudd_Cofactor(DdManager *dd, DdNode *f, DdNode *g)
int Cudd_PrintInfo(DdManager *dd, FILE *fp)
void Cudd_SymmProfile(DdManager *table, int lower, int upper)
DdManager * Cudd_Init(unsigned int numVars, unsigned int numVarsZ, unsigned int numSlots, unsigned int cacheSize, unsigned long maxMemory)
DdNode * Cudd_BddToAdd(DdManager *dd, DdNode *B)
int Cudd_DebugCheck(DdManager *table)
int Cudd_addRead(FILE *fp, DdManager *dd, DdNode **E, DdNode ***x, DdNode ***y, DdNode ***xn, DdNode ***yn_, int *nx, int *ny, int *m, int *n, int bx, int sx, int by, int sy)
DdNode * Cudd_bddBooleanDiff(DdManager *manager, DdNode *f, int x)
static int testXor(DdManager *dd, DdNode *f, int pr, int nvars)
int Cudd_PrintDebug(DdManager *dd, DdNode *f, int n, int pr)
int Cudd_bddPrintCover(DdManager *dd, DdNode *l, DdNode *u)
int Cudd_CheckZeroRef(DdManager *manager)
int Cudd_EnableReorderingReporting(DdManager *dd)
int Cudd_bddLeq(DdManager *dd, DdNode *f, DdNode *g)
int cuddCacheProfile(DdManager *table, FILE *fp)
DdNode * Cudd_Inequality(DdManager *dd, int N, int c, DdNode **x, DdNode **y)
int Cudd_DumpBlif(DdManager *dd, int n, DdNode **f, char **inames, char **onames, char *mname, FILE *fp, int mv)
DdNode * Cudd_bddIthVar(DdManager *dd, int i)
int Cudd_CheckKeys(DdManager *table)
DdNode * Cudd_bddXor(DdManager *dd, DdNode *f, DdNode *g)
DdNode * Cudd_addTimesPlus(DdManager *dd, DdNode *A, DdNode *B, DdNode **z, int nz)
static void usage(char *prog)
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
int Cudd_DumpDot(DdManager *dd, int n, DdNode **f, char **inames, char **onames, FILE *fp)
void Cudd_Quit(DdManager *unique)
int Cudd_ReduceHeap(DdManager *table, Cudd_ReorderingType heuristic, int minsize)
void Cudd_AutodynEnable(DdManager *unique, Cudd_ReorderingType method)
DdNode * Cudd_addMatrixMultiply(DdManager *dd, DdNode *A, DdNode *B, DdNode **z, int nz)
int Cudd_MinHammingDist(DdManager *dd, DdNode *f, int *minterm, int upperBound)
DdNode * Cudd_addWalsh(DdManager *dd, DdNode **x, DdNode **y, int n)
static int testIterators(DdManager *dd, DdNode *M, DdNode *C, int pr)
DdNode * cuddUniqueInter(DdManager *unique, int index, DdNode *T, DdNode *E)
int cuddDestroySubtables(DdManager *unique, int n)
int Cudd_DisableReorderingReporting(DdManager *dd)