/* NAME {* bdd\_setvarnum *} SECTION {* kernel *} SHORT {* set the number of used bdd variables *} PROTO {* int bdd_setvarnum(int num) *} DESCR {* This function is used to define the number of variables used in the bdd package. It may be called more than one time, but only to increase the number of variables. The argument {\tt num} is the number of variables to use. *} RETURN {* Zero on succes, otherwise a negative error code. *} ALSO {* bdd\_ithvar, bdd\_varnum, bdd\_extvarnum *} */ int bdd_setvarnum(int num) { int bdv; int oldbddvarnum = bddvarnum; bdd_disable_reorder(); if (num < 1 || num > MAXVAR) { bdd_error(BDD_RANGE); return bddfalse; } if (num < bddvarnum) return bdd_error(BDD_DECVNUM); if (num == bddvarnum) return 0; if (bddvarset == NULL) { if ((bddvarset=(BDD*)malloc(sizeof(BDD)*num*2)) == NULL) return bdd_error(BDD_MEMORY); if ((bddlevel2var=(int*)malloc(sizeof(int)*(num+1))) == NULL) { free(bddvarset); return bdd_error(BDD_MEMORY); } if ((bddvar2level=(int*)malloc(sizeof(int)*(num+1))) == NULL) { free(bddvarset); free(bddlevel2var); return bdd_error(BDD_MEMORY); } } else { if ((bddvarset=(BDD*)realloc(bddvarset,sizeof(BDD)*num*2)) == NULL) return bdd_error(BDD_MEMORY); if ((bddlevel2var=(int*)realloc(bddlevel2var,sizeof(int)*(num+1))) == NULL) { free(bddvarset); return bdd_error(BDD_MEMORY); } if ((bddvar2level=(int*)realloc(bddvar2level,sizeof(int)*(num+1))) == NULL) { free(bddvarset); free(bddlevel2var); return bdd_error(BDD_MEMORY); } } if (bddrefstack != NULL) free(bddrefstack); bddrefstack = bddrefstacktop = (int*)malloc(sizeof(int)*(num*2+4)); for(bdv=bddvarnum ; bddvarnum < num; bddvarnum++) { bddvarset[bddvarnum*2] = PUSHREF( bdd_makenode(bddvarnum, 0, 1) ); bddvarset[bddvarnum*2+1] = bdd_makenode(bddvarnum, 1, 0); POPREF(1); if (bdderrorcond) { bddvarnum = bdv; return -bdderrorcond; } bddnodes[bddvarset[bddvarnum*2]].refcou = MAXREF; bddnodes[bddvarset[bddvarnum*2+1]].refcou = MAXREF; bddlevel2var[bddvarnum] = bddvarnum; bddvar2level[bddvarnum] = bddvarnum; } LEVEL(0) = num; LEVEL(1) = num; bddvar2level[num] = num; bddlevel2var[num] = num; bdd_pairs_resize(oldbddvarnum, bddvarnum); bdd_operator_varresize(); bdd_enable_reorder(); return 0; }
/* NAME {* bdd\_setvarnum *} SECTION {* kernel *} SHORT {* set the number of used bdd variables *} PROTO {* int bdd_setvarnum(int num) *} DESCR {* This function is used to define the number of variables used in the bdd package. It may be called more than one time, but only to increase the number of variables. The argument {\tt num} is the number of variables to use. *} RETURN {* Zero on succes, otherwise a negative error code. *} ALSO {* bdd\_ithvar, bdd\_varnum, bdd\_extvarnum *} */ int bdd_setvarnum(int num) { int bdv; int oldbddvarnum = bddvarnum; BUDDY_PROLOGUE; ADD_ARG1(T_INT,num); bdd_disable_reorder(); if (num < 1 || num > MAXVAR) { bdd_error(BDD_RANGE); RETURN(bddfalse); } if (num < bddvarnum) RETURN(bdd_error(BDD_DECVNUM)); if (num == bddvarnum) RETURN(0); if (bddvarset == NULL) { if ((bddvarset=(BDD*)malloc(sizeof(BDD)*num*2)) == NULL) RETURN(bdd_error(BDD_MEMORY)); if ((bddlevel2var=(int*)malloc(sizeof(int)*(num+1))) == NULL) { free(bddvarset); RETURN(bdd_error(BDD_MEMORY)); } if ((bddvar2level=(int*)malloc(sizeof(int)*(num+1))) == NULL) { free(bddvarset); free(bddlevel2var); RETURN(bdd_error(BDD_MEMORY)); } } else { if ((bddvarset=(BDD*)realloc(bddvarset,sizeof(BDD)*num*2)) == NULL) RETURN(bdd_error(BDD_MEMORY)); if ((bddlevel2var=(int*)realloc(bddlevel2var,sizeof(int)*(num+1))) == NULL) { free(bddvarset); RETURN(bdd_error(BDD_MEMORY)); } if ((bddvar2level=(int*)realloc(bddvar2level,sizeof(int)*(num+1))) == NULL) { free(bddvarset); free(bddlevel2var); RETURN(bdd_error(BDD_MEMORY)); } } if (bddrefstack != NULL) free(bddrefstack); bddrefstack = bddrefstacktop = (int*)malloc(sizeof(int)*(num*2+4)); for(bdv=bddvarnum ; bddvarnum < num; bddvarnum++) { bddvarset[bddvarnum*2] = PUSHREF( bdd_makenode(bddvarnum, 0, 1) ); bddvarset[bddvarnum*2+1] = bdd_makenode(bddvarnum, 1, 0); POPREF(1); if (bdderrorcond) { bddvarnum = bdv; RETURN(-bdderrorcond); } SETMAXREF(bddvarset[bddvarnum*2]); SETMAXREF(bddvarset[bddvarnum*2+1]); bddlevel2var[bddvarnum] = bddvarnum; bddvar2level[bddvarnum] = bddvarnum; } SETLEVEL(0, num); SETLEVEL(1, num); bddvar2level[num] = num; bddlevel2var[num] = num; bdd_pairs_resize(oldbddvarnum, bddvarnum); bdd_operator_varresize(); bdd_enable_reorder(); RETURN(0); }