00001
00032 #include "util_hack.h"
00033 #define CUDD_MAIN
00034 #include "cuddInt.h"
00035 #undef CUDD_MAIN
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #ifndef lint
00057 static char rcsid[] DD_UNUSED = "$Id: cuddInit.c,v 1.1.1.1 2003/02/24 22:23:52 wjiang Exp $";
00058 #endif
00059
00060
00061
00062
00063
00064
00067
00068
00069
00070
00071
00075
00076
00077
00078
00095 DdManager *
00096 Cudd_Init(
00097 unsigned int numVars ,
00098 unsigned int numVarsZ ,
00099 unsigned int numSlots ,
00100 unsigned int cacheSize ,
00101 unsigned long maxMemory )
00102 {
00103 DdManager *unique;
00104 int i,result;
00105 DdNode *one, *zero;
00106 unsigned int maxCacheSize;
00107 unsigned int looseUpTo;
00108 extern void (*MMoutOfMemory)(long);
00109 void (*saveHandler)(long);
00110
00111 if (maxMemory == 0) {
00112 maxMemory = getSoftDataLimit();
00113 }
00114 looseUpTo = (unsigned int) ((maxMemory / sizeof(DdNode)) /
00115 DD_MAX_LOOSE_FRACTION);
00116 unique = cuddInitTable(numVars,numVarsZ,numSlots,looseUpTo);
00117 unique->maxmem = (unsigned) maxMemory / 10 * 9;
00118 if (unique == NULL) return(NULL);
00119 maxCacheSize = (unsigned int) ((maxMemory / sizeof(DdCache)) /
00120 DD_MAX_CACHE_FRACTION);
00121 result = cuddInitCache(unique,cacheSize,maxCacheSize);
00122 if (result == 0) return(NULL);
00123
00124 saveHandler = MMoutOfMemory;
00125 MMoutOfMemory = Cudd_OutOfMem;
00126 unique->stash = ALLOC(char,(maxMemory / DD_STASH_FRACTION) + 4);
00127 MMoutOfMemory = saveHandler;
00128 if (unique->stash == NULL) {
00129 (void) fprintf(unique->err,"Unable to set aside memory\n");
00130 }
00131
00132
00133 unique->one = cuddUniqueConst(unique,1.0);
00134 if (unique->one == NULL) return(0);
00135 cuddRef(unique->one);
00136 unique->zero = cuddUniqueConst(unique,0.0);
00137 if (unique->zero == NULL) return(0);
00138 cuddRef(unique->zero);
00139 #ifdef HAVE_IEEE_754
00140 if (DD_PLUS_INF_VAL != DD_PLUS_INF_VAL * 3 ||
00141 DD_PLUS_INF_VAL != DD_PLUS_INF_VAL / 3) {
00142 (void) fprintf(unique->err,"Warning: Crippled infinite values\n");
00143 (void) fprintf(unique->err,"Recompile without -DHAVE_IEEE_754\n");
00144 }
00145 #endif
00146 unique->plusinfinity = cuddUniqueConst(unique,DD_PLUS_INF_VAL);
00147 if (unique->plusinfinity == NULL) return(0);
00148 cuddRef(unique->plusinfinity);
00149 unique->minusinfinity = cuddUniqueConst(unique,DD_MINUS_INF_VAL);
00150 if (unique->minusinfinity == NULL) return(0);
00151 cuddRef(unique->minusinfinity);
00152 unique->background = unique->zero;
00153
00154
00155 one = unique->one;
00156 zero = Cudd_Not(one);
00157
00158 unique->vars = ALLOC(DdNodePtr,unique->maxSize);
00159 if (unique->vars == NULL) {
00160 unique->errorCode = CUDD_MEMORY_OUT;
00161 return(NULL);
00162 }
00163 for (i = 0; i < unique->size; i++) {
00164 unique->vars[i] = cuddUniqueInter(unique,i,one,zero);
00165 if (unique->vars[i] == NULL) return(0);
00166 cuddRef(unique->vars[i]);
00167 }
00168
00169 if (unique->sizeZ)
00170 cuddZddInitUniv(unique);
00171
00172 unique->memused += sizeof(DdNode *) * unique->maxSize;
00173
00174 return(unique);
00175
00176 }
00177
00178
00192 void
00193 Cudd_Quit(
00194 DdManager * unique)
00195 {
00196 if (unique->stash != NULL) FREE(unique->stash);
00197 cuddFreeTable(unique);
00198
00199 }
00200
00201
00202
00203
00204
00205
00206
00219 int
00220 cuddZddInitUniv(
00221 DdManager * zdd)
00222 {
00223 DdNode *p, *res;
00224 int i;
00225
00226 zdd->univ = ALLOC(DdNodePtr, zdd->sizeZ);
00227 if (zdd->univ == NULL) {
00228 zdd->errorCode = CUDD_MEMORY_OUT;
00229 return(0);
00230 }
00231
00232 res = DD_ONE(zdd);
00233 cuddRef(res);
00234 for (i = zdd->sizeZ - 1; i >= 0; i--) {
00235 unsigned int index = zdd->invpermZ[i];
00236 p = res;
00237 res = cuddUniqueInterZdd(zdd, index, p, p);
00238 if (res == NULL) {
00239 Cudd_RecursiveDerefZdd(zdd,p);
00240 FREE(zdd->univ);
00241 return(0);
00242 }
00243 cuddRef(res);
00244 cuddDeref(p);
00245 zdd->univ[i] = res;
00246 }
00247
00248 #ifdef DD_VERBOSE
00249 cuddZddP(zdd, zdd->univ[0]);
00250 #endif
00251
00252 return(1);
00253
00254 }
00255
00256
00268 void
00269 cuddZddFreeUniv(
00270 DdManager * zdd)
00271 {
00272 if (zdd->univ) {
00273 Cudd_RecursiveDerefZdd(zdd, zdd->univ[0]);
00274 FREE(zdd->univ);
00275 }
00276
00277 }
00278
00279
00280
00281
00282
00283