void getActionAndValue(Pair & dval, Pair & aval, int whichPolicy) { // query the whichPolicy policy action and value with the current values of varvals // fprintf(stderr,"querying policy and action diagrams %d\n",whichPolicy); // build an array varass of 1s and 0s over the variables v // with assignments corresponding to the varvals (values for the original variables ov) // then call *(Cudd_V(Cudd_Eval(dd,act, varass))) int *varass = new int[2*nvars]; int i,j,nbv,tmp,nbvals; for (i=0; i<nvars*2; i++) varass[i] = 0; for (i=0; i<novars; i++) { nbv = ov[i].nbvars; nbvals = int(pow(2.0,nbv)); tmp = nbvals-varvals[i]-1; for (j=nbv-1; j>=0; j--) { varass[Cudd_NodeReadIndex(v[ov[i].var1index+j].add_var)] = tmp%2; tmp = tmp/2; } } dval = *(Cudd_V(Cudd_Eval(dd,val[whichPolicy],varass))); aval = *(Cudd_V(Cudd_Eval(dd,act[whichPolicy],varass))); delete [] varass; }
int main(void) { DdManager *manager = Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0); //DdNode *one = DD_ONE(manager); //DdNode *zero = Cudd_Not(one); //DdNode *tmp; //DdNode *f; int p1[] = {1,0,0,0}; // DdNode *v = getVar(manager,0,1); DdNode *p = path(manager,p1,4); printf("Is the new path an evaluation of the bdd? %d\n",Cudd_Eval(manager,p,p1) == DD_ONE(manager)); todot(manager,p,"tuple1000.dot"); printf("Paths to one in p: %f from a total of %f\n", Cudd_CountPathsToNonZero(p), Cudd_CountPath(p)); Cudd_RecursiveDeref(manager,p); printf("This number should be zero: %d\n",Cudd_CheckZeroRef(manager)); return 0; }