void createVars(array_t * vars, YAP_Term t,DdManager * mgr, array_t * bVar2mVar,int create_dot, char inames[1000][20]) /* adds the boolean variables to the BDD and returns an array_t containing them (array_t is defined in the util library of glu) returns also the names of the variables to be used to save the ADD in dot format */ { YAP_Term varTerm,probTerm; int varIndex,nVal,i,b; variable v; char numberVar[10],numberBit[10]; double p; b=0; while(YAP_IsPairTerm(t)) { varTerm=YAP_HeadOfTerm(t); varIndex=YAP_IntOfTerm(YAP_HeadOfTerm(varTerm)); varTerm=YAP_TailOfTerm(varTerm); nVal=YAP_IntOfTerm(YAP_HeadOfTerm(varTerm)); varTerm=YAP_TailOfTerm(varTerm); probTerm=YAP_HeadOfTerm(varTerm); v.nVal=nVal; v.nBit=(int)ceil(log(nVal)/log(2)); v.probabilities=array_alloc(double,0); v.booleanVars=array_alloc(DdNode *,0); for (i=0;i<nVal;i++) { if (create_dot) { strcpy(inames[b+i],"X"); sprintf(numberVar,"%d",varIndex); strcat(inames[b+i],numberVar); strcat(inames[b+i],"_"); sprintf(numberBit,"%d",i); strcat(inames[b+i],numberBit); } p=YAP_FloatOfTerm(YAP_HeadOfTerm(probTerm)); array_insert(double,v.probabilities,i,p); probTerm=YAP_TailOfTerm(probTerm); array_insert(DdNode *,v.booleanVars,i,Cudd_bddIthVar(mgr,b+i)); array_insert(int,bVar2mVar,b+i,varIndex); } Cudd_MakeTreeNode(mgr,b,nVal,MTR_FIXED); b=b+nVal; array_insert(variable,vars,varIndex,v); t=YAP_TailOfTerm(t); } }
/** * Groups some variables such that they "stick" together during the reordering process. * @param which The variables that should be grouped. They must have not been allocated a non-grouped variable in between the allocation of two grouped variables. */ void BFBddManager::groupVariables(const std::vector<BFBdd> &which) { // Only allow continuous variables to be grouped. std::set<DdHalfWord> indices; DdHalfWord min = std::numeric_limits<DdHalfWord>::max(); DdHalfWord max = std::numeric_limits<DdHalfWord>::min(); for (unsigned int i = 0; i < which.size(); i++) { DdNode *node = which[i].node; DdHalfWord index = ((Cudd_Regular(node))->index); if (index < min) min = index; if (index > max) max = index; indices.insert(index); } if ((unsigned int) (max - min + 1) != indices.size()) throw std::runtime_error("Error in BFBddManager::groupVariables(const std::vector<BFBdd> &which) - Can only group continuous variables!\n"); Cudd_MakeTreeNode(mgr, min, max - min + 1, MTR_DEFAULT); }
variables createVars(YAP_Term t,DdManager * mgr, int create_dot, char inames[1000][20]) /* adds the boolean variables to the BDD and returns the array vars containing them returns also the names of the variables to be used to save the ADD in dot format */ { YAP_Term varTerm,probTerm; int varIndex,nVal,i,b; variable v; char numberVar[10],numberBit[10]; double p; variables vars; vars.varar=NULL; vars.bVar2mVar=NULL; b=0; vars.nVar=0; varIndex=0; while(YAP_IsPairTerm(t)) { varTerm=YAP_HeadOfTerm(t); varIndex=YAP_IntOfTerm(YAP_HeadOfTerm(varTerm)); varTerm=YAP_TailOfTerm(varTerm); nVal=YAP_IntOfTerm(YAP_HeadOfTerm(varTerm)); varTerm=YAP_TailOfTerm(varTerm); probTerm=YAP_HeadOfTerm(varTerm); v.nVal=nVal; v.nBit=(int)ceil(log(nVal)/log(2)); v.probabilities=(double *) malloc(nVal* sizeof(double)); v.booleanVars=(DdNode * *) malloc(v.nBit* sizeof(DdNode *)); for (i=0; i<nVal; i++) { p=YAP_FloatOfTerm(YAP_HeadOfTerm(probTerm)); v.probabilities[i]=p; probTerm=YAP_TailOfTerm(probTerm); } for (i=0; i<v.nBit; i++) { if (create_dot) { strcpy(inames[b+i],"X"); sprintf(numberVar,"%d",varIndex); strcat(inames[b+i],numberVar); strcat(inames[b+i],"_"); sprintf(numberBit,"%d",i); strcat(inames[b+i],numberBit); } v.booleanVars[i]=Cudd_bddIthVar(mgr,b+i); vars.bVar2mVar=(int *)realloc(vars.bVar2mVar,(b+i+1)*sizeof(int)); vars.bVar2mVar[b+i]=varIndex; } Cudd_MakeTreeNode(mgr,b,v.nBit,MTR_FIXED); b=b+v.nBit; vars.varar=(variable *) realloc(vars.varar,(varIndex+1)* sizeof(variable)); vars.varar[varIndex]=v; t=YAP_TailOfTerm(t); } vars.nVar=varIndex+1; vars.nBVar=b; return vars; }