diff --git a/packages/cplint/approx/bestfirst.pl b/packages/cplint/approx/bestfirst.pl index 8f5cf20ee..f7c162f83 100644 --- a/packages/cplint/approx/bestfirst.pl +++ b/packages/cplint/approx/bestfirst.pl @@ -15,7 +15,7 @@ :- use_module(library(system)). :- use_module(library(ugraphs)). :- use_module(params). -:- use_module(tptreefile). +:- use_module(tptree_lpad). :- use_module(utility). % :- source. diff --git a/packages/cplint/approx/bestk.pl b/packages/cplint/approx/bestk.pl index 7a47c8fd5..c71f8321f 100644 --- a/packages/cplint/approx/bestk.pl +++ b/packages/cplint/approx/bestk.pl @@ -15,7 +15,7 @@ :- use_module(library(system)). :- use_module(library(ugraphs)). :- use_module(params). -:- use_module(tptreefile). +:- use_module(tptree_lpad). :- use_module(utility). % :- source. diff --git a/packages/cplint/approx/deepdyn.pl b/packages/cplint/approx/deepdyn.pl index 8bdb8b981..ced734864 100644 --- a/packages/cplint/approx/deepdyn.pl +++ b/packages/cplint/approx/deepdyn.pl @@ -15,7 +15,7 @@ :- use_module(library(system)). :- use_module(library(ugraphs)). :- use_module(params). -:- use_module(tptreefile). +:- use_module(tptree_lpad). :- use_module(utility). % :- source. diff --git a/packages/cplint/approx/deepit.pl b/packages/cplint/approx/deepit.pl index 52c71047c..585351aba 100644 --- a/packages/cplint/approx/deepit.pl +++ b/packages/cplint/approx/deepit.pl @@ -15,7 +15,7 @@ :- use_module(library(system)). :- use_module(library(ugraphs)). :- use_module(params). -:- use_module(tptreefile). +:- use_module(tptree_lpad). :- use_module(utility). % :- source. diff --git a/packages/cplint/approx/exact.pl b/packages/cplint/approx/exact.pl index ead21b34c..c7decaa11 100644 --- a/packages/cplint/approx/exact.pl +++ b/packages/cplint/approx/exact.pl @@ -15,7 +15,7 @@ :- use_module(library(system)). :- use_module(library(ugraphs)). :- use_module(params). -:- use_module(tptreefile). +:- use_module(tptree_lpad). :- use_module(utility). % :- source. diff --git a/packages/cplint/approx/simplecuddLPADs/ProblogBDD.c b/packages/cplint/approx/simplecuddLPADs/ProblogBDD.c index 269ae533d..a472d5c8d 100644 --- a/packages/cplint/approx/simplecuddLPADs/ProblogBDD.c +++ b/packages/cplint/approx/simplecuddLPADs/ProblogBDD.c @@ -141,6 +141,13 @@ * The End * * * \******************************************************************************/ +/* modified by Fabrizio Riguzzi in 2009 for dealing with multivalued variables: +instead of variables or their negation, the script can contain equations of the +form +variable=value +Multivalued variables are translated to binary variables by means of a log +encodimg +*/ #include "simplecudd.h" @@ -717,31 +724,17 @@ so that it is not recomputed double value; - //printf("Prob node %d\n",node); - //index=Cudd_NodeReadIndex(node); - //printf("Prob INdex %d\n",index); if (Cudd_IsConstant(node)) { - value=Cudd_V(node);//node->type.value; - //printf("Value %e comp %d\n",value,comp); - if (comp)//Cudd_IsComplement(node)) - //return (1.0-value); - //if (value>0) + value=Cudd_V(node); + if (comp) { -// printf("return 0"); return 0.0; } else { -// printf("return 1"); return 1.0; } -/*else - if (value>0) - return 1.0; - else - return 0.0; -*/ //return value; } else { @@ -749,22 +742,15 @@ so that it is not recomputed if (Found!=NULL) { - //printf("value found %e\n",Found->dvalue); return Found->dvalue; } else { index=Cudd_NodeReadIndex(node); - //printf("node absent %d comp %d\n",node,comp); - //mVarIndex=array_fetch(int,bVar2mVar,index); mVarIndex=MyManager.varmap.bVar2mVar[index]; - //v=array_fetch(variable,vars,mVarIndex); v=MyManager.varmap.mvars[mVarIndex]; nBit=v.nBit; -// printf("calling prob bool mvar %d nbit %d\n",mVarIndex,nBit); - //scanf("%d",&r); res=ProbBool(MyManager,node,0,nBit,0,v,comp); - //printf("New val %e\n",res); AddNode1(MyManager.varmap.bVar2mVar,MyManager.his, MyManager.varmap.varstart, node, res, 0, NULL); return res; } @@ -778,68 +764,40 @@ double ProbBool(extmanager MyManager, DdNode *node, int bits, int nBit,int posBV double p,res; double * probs; int index; -// printf("ProbBool nBit %d\n",nBit); - //scanf("%d",&r); probs=v.probabilities; if (nBit==0) { - //printf("last var bits %d larray %d comp %d\n",bits,array_n(probs),comp); -// printf("bits %d v.nbit %d\n",bits,v.nBit); if (bits>=v.nVal) - //if (comp) { - //printf("bits>=v.nbit return 0\n"); return 0.0; } - //else - //{printf("return 0\n"); - //return 1.0;}} else { - // printf("Val %d\n",bits); - - //p=array_fetch(double,probs,bits); p=probs[bits]; - //printf("prob %e\n",p); res=p*Prob(MyManager,node,comp); - //printf("prob %e\n",p); - //printf("bottom %e\n",res); return res; } } else { - //if (correctPosition(node->index,v,node,posBVar)) index=Cudd_NodeReadIndex(node); - //printf("index %d\n",Cudd_NodeReadIndex(node)); if (correctPosition(index,v,posBVar)) { - //printf("node %d\n",node); - T = Cudd_T(node);//node->type.kids.T; - F = Cudd_E(node);//node->type.kids.E; + T = Cudd_T(node); + F = Cudd_E(node); bits=bits<<1; - //printf("calling on the true child %di complement %d\n",T,Cudd_IsComplement(T)); res=ProbBool(MyManager,T,bits+1,nBit-1,posBVar+1,v,comp); - //printf("res %e\ncalling on the else child %d c %d\n",res,F,Cudd_IsComplement(F)); - //printf("comp %d ",comp); comp=(!comp && Cudd_IsComplement(F)) || (comp && !Cudd_IsComplement(F)); - //printf("comp %d \n",comp); res=res+ ProbBool(MyManager,F,bits,nBit-1,posBVar+1,v,comp); - //printf("res 2 %e\n",res); return res; } else { - //printf("absent var\n"); bits=bits<<1; - // printf("Var =1\n"); res=ProbBool(MyManager,node,bits+1,nBit-1,posBVar+1,v,comp); - //printf("res 1 %e\n",res); -//printf("var =0\n"); res=res+ ProbBool(MyManager,node,bits,nBit-1,posBVar+1,v,comp); - // printf("res 2 %e\n",res); return res; } } @@ -850,12 +808,8 @@ int correctPosition(int index,variable v,int posBVar) currently explored by ProbBool */ { int bvar; -//printf("posbvar %d\n",posBVar); -//printf("length %d\n",array_n(v.booleanVars)); - //bvar=array_fetch(DdNode *,v.booleanVars,posBVar); bvar=v.booleanVars[posBVar]; - // return var->index==index; return(bvar==index); } diff --git a/packages/cplint/approx/simplecuddLPADs/general.c b/packages/cplint/approx/simplecuddLPADs/general.c index 64a7f88e1..fd1d01fb4 100644 --- a/packages/cplint/approx/simplecuddLPADs/general.c +++ b/packages/cplint/approx/simplecuddLPADs/general.c @@ -140,6 +140,11 @@ * The End * * * \******************************************************************************/ +/* modified by Fabrizio Riguzzi in 2009 for dealing with multivalued variables +instead of variables or their negation, the script can contain equations of the +form +variable=value +*/ #include "general.h" diff --git a/packages/cplint/approx/simplecuddLPADs/general.h b/packages/cplint/approx/simplecuddLPADs/general.h index 4441ed623..4411092e4 100644 --- a/packages/cplint/approx/simplecuddLPADs/general.h +++ b/packages/cplint/approx/simplecuddLPADs/general.h @@ -140,6 +140,11 @@ * The End * * * \******************************************************************************/ +/* modified by Fabrizio Riguzzi in 2009 for dealing with multivalued variables +instead of variables or their negation, the script can contain equations of the +form +variable=value +*/ #include diff --git a/packages/cplint/approx/simplecuddLPADs/simplecudd.c b/packages/cplint/approx/simplecuddLPADs/simplecudd.c index e361aeb91..52667ff3c 100644 --- a/packages/cplint/approx/simplecuddLPADs/simplecudd.c +++ b/packages/cplint/approx/simplecuddLPADs/simplecudd.c @@ -140,8 +140,11 @@ * The End * * * \******************************************************************************/ - - +/* modified by Fabrizio Riguzzi in 2009 for dealing with multivalued variables +instead of variables or their negation, the script can contain equations of the +form +variable=value +*/ #include "simplecudd.h" /* BDD manager initialization */ @@ -587,7 +590,6 @@ int LoadMultiVariableData(DdManager * mgr,namedvars varmap, char *filename) { varname = (char *) malloc(sizeof(char) * strlen(dataread)); strcpy(varname, dataread); varmap.vars[index]=varname; - //printf("vname %d %s\n",index, varmap.vars[index]); fscanf(data, "%d\n", &values); varmap.loaded[index] = 1; @@ -767,7 +769,6 @@ int AddNamedMultiVar(DdManager *mgr,namedvars varmap, const char *varname, int * int *booleanVars; char * vname; l=strlen(varname); - //printf("addnamed %s\n",varname); i=0; while (varname[i]!='-') { @@ -776,11 +777,8 @@ int AddNamedMultiVar(DdManager *mgr,namedvars varmap, const char *varname, int * vname=(char *)malloc(sizeof(char)*(l+1)); strncpy(vname,varname,i); vname[i]='\0'; - //printf("addnamed vname %s\n",vname); sscanf(varname+i+1,"%d",value); index= GetNamedVarIndex(varmap, vname); - //printf("index %d\n",index); - //printf("init %d\n",varmap.mvars[index].init); if (index == -1 * varmap.varcnt) { return -1; } else if ((index < 0) || (index == 0 && varmap.vars[0] == NULL)) { @@ -790,16 +788,14 @@ int AddNamedMultiVar(DdManager *mgr,namedvars varmap, const char *varname, int * if (varmap.mvars[index].init==0){ nBit=varmap.mvars[index].nBit; booleanVars= varmap.mvars[index].booleanVars; - //Cudd_MakeTreeNode(mgr,boolVars,nBit,MTR_FIXED); for (i=0;i diff --git a/packages/cplint/approx/tptree_lpad.pl b/packages/cplint/approx/tptree_lpad.pl index d0e724167..d3db013b9 100644 --- a/packages/cplint/approx/tptree_lpad.pl +++ b/packages/cplint/approx/tptree_lpad.pl @@ -6,8 +6,14 @@ % remembers shortest prefix of a conjunction only (i.e. a*b+a*b*c results in a*b only, but b*a+a*b*c is not reduced) % children are sorted, but branches aren't (to speed up search while keeping structure sharing from proof procedure) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +/* derived from tptree.yap from ProbLog by Fabrizio Riguzzi in 2009 +for dealing with multivalued variables +instead of variables or their negation, the script can contain equations of the +form +variable=value +*/ -:- module(ptree,[init_ptree/1, +:- module(ptree_lpad,[init_ptree/1, delete_ptree/1, rename_ptree/2, member_ptree/2,