ProbLog - simplecudd Distribution Fixed warnings
This commit is contained in:
parent
258d8cf997
commit
835b099d98
@ -260,9 +260,12 @@ char * extractpattern(char *thestr);
|
|||||||
|
|
||||||
// added by GUY
|
// added by GUY
|
||||||
double* read_util_file(char * filename);
|
double* read_util_file(char * filename);
|
||||||
|
int forestSize(DdNode **forest);
|
||||||
|
int compare_util_adds(const void* A, const void* B);
|
||||||
void exact_strategy_search(extmanager* MyManager, DdNode **forest, double* utilities);
|
void exact_strategy_search(extmanager* MyManager, DdNode **forest, double* utilities);
|
||||||
DdNode* buildADDfromBDD(extmanager* MyManager, DdNode *Current, DdManager* addmgr);
|
DdNode* buildADDfromBDD(extmanager* MyManager, DdNode *Current, DdManager* addmgr);
|
||||||
void ReInitAndUnrefHistory(hisqueue *HisQueue, int varcnt, DdManager* mgr);
|
void ReInitAndUnrefHistory(hisqueue *HisQueue, int varcnt, DdManager* mgr);
|
||||||
|
char* GetAddNodeVarNameDisp(namedvars varmap, DdNode *node);
|
||||||
int extractstrategy(extmanager* MyManager, DdManager * add_mgr, DdNode *Current, DdNode *max_node);
|
int extractstrategy(extmanager* MyManager, DdManager * add_mgr, DdNode *Current, DdNode *max_node);
|
||||||
DdNode * setLowerBound(DdManager * dd, DdNode * f, double lowerBound);
|
DdNode * setLowerBound(DdManager * dd, DdNode * f, double lowerBound);
|
||||||
DdNode * setLowerBoundRecur(DdManager * dd, DdNode * f, double lowerBound);
|
DdNode * setLowerBoundRecur(DdManager * dd, DdNode * f, double lowerBound);
|
||||||
@ -273,6 +276,7 @@ void print_strategy(namedvars varmap);
|
|||||||
void newManager(extmanager* MyManager,bddfileheader fileheader, int nbManagers);
|
void newManager(extmanager* MyManager,bddfileheader fileheader, int nbManagers);
|
||||||
bdd_mgr* generateIndependentBDDForest(bddfileheader fileheader);
|
bdd_mgr* generateIndependentBDDForest(bddfileheader fileheader);
|
||||||
int LoadVariableDataForForest(namedvars varmap, char *filename);
|
int LoadVariableDataForForest(namedvars varmap, char *filename);
|
||||||
|
int printTime(void);
|
||||||
|
|
||||||
int main(int argc, char **arg) {
|
int main(int argc, char **arg) {
|
||||||
extmanager MyManager;
|
extmanager MyManager;
|
||||||
@ -289,6 +293,7 @@ int main(int argc, char **arg) {
|
|||||||
|
|
||||||
//Initializin to NULL to be safe?
|
//Initializin to NULL to be safe?
|
||||||
bdd = NULL;
|
bdd = NULL;
|
||||||
|
bakbdd = NULL;
|
||||||
forest = NULL;
|
forest = NULL;
|
||||||
bdd_mgrs = NULL;
|
bdd_mgrs = NULL;
|
||||||
|
|
||||||
@ -619,7 +624,7 @@ double* read_util_file(char *filename){
|
|||||||
return utils;
|
return utils;
|
||||||
}
|
}
|
||||||
|
|
||||||
int forestSize(DdNode **forest){
|
int forestSize(DdNode **forest) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
do{
|
do{
|
||||||
i++;
|
i++;
|
||||||
@ -651,6 +656,7 @@ void exact_strategy_search(extmanager* MyManager, DdNode **forest, double* utili
|
|||||||
double utility_to_go = 0.000001;
|
double utility_to_go = 0.000001;
|
||||||
util_add * util_adds = (util_add *) malloc(sizeof(util_add)*n);
|
util_add * util_adds = (util_add *) malloc(sizeof(util_add)*n);
|
||||||
|
|
||||||
|
names = NULL;
|
||||||
if (params.debug) {
|
if (params.debug) {
|
||||||
fprintf(stderr, "init add\n");
|
fprintf(stderr, "init add\n");
|
||||||
}
|
}
|
||||||
@ -808,6 +814,8 @@ DdNode* buildADDfromBDD(extmanager* MyManager, DdNode *Current, DdManager* addmg
|
|||||||
DdNode* var;
|
DdNode* var;
|
||||||
DdNode *posprob, *negprob;
|
DdNode *posprob, *negprob;
|
||||||
|
|
||||||
|
curnode = NULL;
|
||||||
|
|
||||||
//if (_debug && Cudd_DebugCheck(addmgr)!=0) exit(-1);
|
//if (_debug && Cudd_DebugCheck(addmgr)!=0) exit(-1);
|
||||||
|
|
||||||
if (_debug) {
|
if (_debug) {
|
||||||
@ -1181,7 +1189,7 @@ void print_strategy(namedvars varmap){
|
|||||||
|
|
||||||
// new manager for bdd forest needs very low memory requirements! -l
|
// new manager for bdd forest needs very low memory requirements! -l
|
||||||
void newManager(extmanager* MyManager, bddfileheader fileheader, int nbManagers){
|
void newManager(extmanager* MyManager, bddfileheader fileheader, int nbManagers){
|
||||||
MyManager->manager;
|
// MyManager->manager;
|
||||||
if (_debug) fprintf(stderr,"Creating new BDD manager.\n\n");
|
if (_debug) fprintf(stderr,"Creating new BDD manager.\n\n");
|
||||||
if (_debug) fprintf(stderr,"Setting BDD manager memory consumption to %i.\n", max(1024,(512*1024*1024)/nbManagers));
|
if (_debug) fprintf(stderr,"Setting BDD manager memory consumption to %i.\n", max(1024,(512*1024*1024)/nbManagers));
|
||||||
MyManager->manager = Cudd_Init((unsigned int)fileheader.varcnt, 0,
|
MyManager->manager = Cudd_Init((unsigned int)fileheader.varcnt, 0,
|
||||||
@ -1206,15 +1214,16 @@ int printTime(void){
|
|||||||
time(&now);
|
time(&now);
|
||||||
current = localtime(&now);
|
current = localtime(&now);
|
||||||
fprintf(stderr, "%i:%i:%i: ", current->tm_hour, current->tm_min, current->tm_sec);
|
fprintf(stderr, "%i:%i:%i: ", current->tm_hour, current->tm_min, current->tm_sec);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bdd_mgr* generateIndependentBDDForest(bddfileheader fileheader) {
|
bdd_mgr* generateIndependentBDDForest(bddfileheader fileheader) {
|
||||||
int i;
|
|
||||||
int icomment, maxlinesize, icur, iline, curinter, iequal;
|
int icomment, maxlinesize, icur, iline, curinter, iequal;
|
||||||
DdNode *Line;
|
DdNode *Line;
|
||||||
bdd_mgr * bdd_mgrs;
|
bdd_mgr * bdd_mgrs;
|
||||||
char buf, *inputline, *filename, *subl;
|
char buf, *inputline, *filename, *subl;
|
||||||
bddfileheader interfileheader;
|
bddfileheader interfileheader;
|
||||||
|
subl = NULL; // This addition might hide a real bug GUY you need to check your free(subl) instructions
|
||||||
// Initialization of intermediate steps
|
// Initialization of intermediate steps
|
||||||
//Guy: +1 to delimit array????
|
//Guy: +1 to delimit array????
|
||||||
bdd_mgrs = (bdd_mgr *) malloc(sizeof(bdd_mgr) * (fileheader.intercnt+1));
|
bdd_mgrs = (bdd_mgr *) malloc(sizeof(bdd_mgr) * (fileheader.intercnt+1));
|
||||||
@ -1399,6 +1408,7 @@ int LoadVariableDataForForest(namedvars varmap, char *filename) {
|
|||||||
double dvalue = 0.0;
|
double dvalue = 0.0;
|
||||||
int icur = 0, maxbufsize = 10, hasvar = 0, index = 0, idat = 0, ivalue = 0;
|
int icur = 0, maxbufsize = 10, hasvar = 0, index = 0, idat = 0, ivalue = 0;
|
||||||
dynvalue = NULL;
|
dynvalue = NULL;
|
||||||
|
varname = NULL;
|
||||||
if ((data = fopen(filename, "r")) == NULL) {
|
if ((data = fopen(filename, "r")) == NULL) {
|
||||||
perror(filename);
|
perror(filename);
|
||||||
return -1;
|
return -1;
|
||||||
@ -1797,6 +1807,13 @@ double CalcProbability(extmanager MyManager, DdNode *Current) {
|
|||||||
double lvalue, hvalue, tvalue;
|
double lvalue, hvalue, tvalue;
|
||||||
density_integral dynvalue_parsed;
|
density_integral dynvalue_parsed;
|
||||||
|
|
||||||
|
dynvalue_parsed.low = 0.0;
|
||||||
|
dynvalue_parsed.high = 0.0;
|
||||||
|
dynvalue_parsed.mu = 0.0;
|
||||||
|
dynvalue_parsed.log_sigma = 0.0;
|
||||||
|
|
||||||
|
curnode = NULL;
|
||||||
|
|
||||||
if (params.debug) {
|
if (params.debug) {
|
||||||
curnode = GetNodeVarNameDisp(MyManager.manager, MyManager.varmap, Current);
|
curnode = GetNodeVarNameDisp(MyManager.manager, MyManager.varmap, Current);
|
||||||
fprintf(stderr, "%s\n", curnode);
|
fprintf(stderr, "%s\n", curnode);
|
||||||
@ -1847,12 +1864,18 @@ gradientpair CalcGradient(extmanager MyManager, DdNode *Current, int TargetVar,
|
|||||||
hisnode *Found;
|
hisnode *Found;
|
||||||
char *curnode, *dynvalue;
|
char *curnode, *dynvalue;
|
||||||
gradientpair lowvalue, highvalue, tvalue;
|
gradientpair lowvalue, highvalue, tvalue;
|
||||||
double this_probability;
|
double this_probability = 0.0;
|
||||||
double this_gradient;
|
double this_gradient = 0.0;
|
||||||
double continuous_denominator,continuous_numerator;
|
double continuous_denominator = 0.0, continuous_numerator = 0.0;
|
||||||
double *gradient;
|
double *gradient;
|
||||||
density_integral dynvalue_parsed;
|
density_integral dynvalue_parsed;
|
||||||
|
|
||||||
|
dynvalue_parsed.low = 0.0;
|
||||||
|
dynvalue_parsed.high = 0.0;
|
||||||
|
dynvalue_parsed.mu = 0.0;
|
||||||
|
dynvalue_parsed.log_sigma = 0.0;
|
||||||
|
|
||||||
|
curnode = NULL;
|
||||||
if (params.debug) {
|
if (params.debug) {
|
||||||
curnode = GetNodeVarNameDisp(MyManager.manager, MyManager.varmap, Current);
|
curnode = GetNodeVarNameDisp(MyManager.manager, MyManager.varmap, Current);
|
||||||
fprintf(stderr, "%s\n", curnode);
|
fprintf(stderr, "%s\n", curnode);
|
||||||
|
@ -643,7 +643,7 @@ int LoadVariableData(namedvars varmap, char *filename) {
|
|||||||
char *dataread, buf, *varname, *dynvalue;
|
char *dataread, buf, *varname, *dynvalue;
|
||||||
double dvalue = 0.0;
|
double dvalue = 0.0;
|
||||||
int icur = 0, maxbufsize = 10, hasvar = 0, index = -1, idat = 0, ivalue = 0;
|
int icur = 0, maxbufsize = 10, hasvar = 0, index = -1, idat = 0, ivalue = 0;
|
||||||
dynvalue = NULL;
|
dynvalue = NULL; varname = NULL;
|
||||||
if ((data = fopen(filename, "r")) == NULL) {
|
if ((data = fopen(filename, "r")) == NULL) {
|
||||||
perror(filename);
|
perror(filename);
|
||||||
return -1;
|
return -1;
|
||||||
@ -975,12 +975,12 @@ DdNode* FileGenerateBDD(DdManager *manager, namedvars varmap, bddfileheader file
|
|||||||
return (FileGenerateBDDForest(manager, varmap, fileheader))[0];
|
return (FileGenerateBDDForest(manager, varmap, fileheader))[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void unreference(DdManager *manager, DdNode ** intermediates, int count){
|
// void unreference(DdManager *manager, DdNode ** intermediates, int count){
|
||||||
// int i;
|
// // int i;
|
||||||
// for(i = 0;i<count;i++){
|
// // for(i = 0;i<count;i++){
|
||||||
// if(intermediates[i] != NULL) Cudd_RecursiveDeref(manager,intermediates[i]);
|
// // if(intermediates[i] != NULL) Cudd_RecursiveDeref(manager,intermediates[i]);
|
||||||
// }
|
// // }
|
||||||
}
|
// }
|
||||||
|
|
||||||
DdNode** FileGenerateBDDForest(DdManager *manager, namedvars varmap, bddfileheader fileheader) {
|
DdNode** FileGenerateBDDForest(DdManager *manager, namedvars varmap, bddfileheader fileheader) {
|
||||||
int icomment, maxlinesize, icur, iline, curinter, iequal;
|
int icomment, maxlinesize, icur, iline, curinter, iequal;
|
||||||
@ -1031,7 +1031,7 @@ DdNode** FileGenerateBDDForest(DdManager *manager, namedvars varmap, bddfilehead
|
|||||||
result = (DdNode **) malloc(sizeof(DdNode *) * 1);
|
result = (DdNode **) malloc(sizeof(DdNode *) * 1);
|
||||||
result[0] = inter[curinter];
|
result[0] = inter[curinter];
|
||||||
Cudd_Ref(result[0]);
|
Cudd_Ref(result[0]);
|
||||||
unreference(manager, inter, fileheader.intercnt);
|
//unreference(manager, inter, fileheader.intercnt);
|
||||||
free(inter);
|
free(inter);
|
||||||
free(inputline);
|
free(inputline);
|
||||||
return result;
|
return result;
|
||||||
@ -1084,7 +1084,7 @@ DdNode** FileGenerateBDDForest(DdManager *manager, namedvars varmap, bddfilehead
|
|||||||
}
|
}
|
||||||
if (_debug) fprintf(stderr, "Returned: %s\n", inputline);
|
if (_debug) fprintf(stderr, "Returned: %s\n", inputline);
|
||||||
fclose(fileheader.inputfile);
|
fclose(fileheader.inputfile);
|
||||||
unreference(manager, inter, fileheader.intercnt);
|
//unreference(manager, inter, fileheader.intercnt);
|
||||||
free(inter);
|
free(inter);
|
||||||
free(inputline);
|
free(inputline);
|
||||||
free(subl);
|
free(subl);
|
||||||
@ -1198,7 +1198,7 @@ DdNode* LineParser(DdManager *manager, namedvars varmap, DdNode **inter, int max
|
|||||||
int istart, iend, ilength, i, symbol, ivar, inegvar, inegoper, iconst;
|
int istart, iend, ilength, i, symbol, ivar, inegvar, inegoper, iconst;
|
||||||
long startAt, endAt;
|
long startAt, endAt;
|
||||||
double secs;
|
double secs;
|
||||||
DdNode *bdd, *temp;
|
DdNode *bdd;//, *temp;
|
||||||
char *term, curoper;
|
char *term, curoper;
|
||||||
bdd = HIGH(manager);
|
bdd = HIGH(manager);
|
||||||
Cudd_Ref(bdd);
|
Cudd_Ref(bdd);
|
||||||
@ -1684,8 +1684,8 @@ int GetParam(char *inputline, int iParam) {
|
|||||||
|
|
||||||
void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, DdNode *bdd) {
|
void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, DdNode *bdd) {
|
||||||
char buf, *inputline;
|
char buf, *inputline;
|
||||||
int icur, maxlinesize, iline, index, iloop, ivalue, iQsize, i, inQ, iRoot;
|
int icur, maxlinesize, iline, index, iloop, iQsize, i, inQ, iRoot; //ivalue,
|
||||||
double dvalue;
|
// double dvalue;
|
||||||
DdNode **Q, **Q2, *h_node, *l_node, *curnode;
|
DdNode **Q, **Q2, *h_node, *l_node, *curnode;
|
||||||
hisqueue *his;
|
hisqueue *his;
|
||||||
hisnode *hnode;
|
hisnode *hnode;
|
||||||
@ -1723,10 +1723,10 @@ void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, Dd
|
|||||||
inQ = 0;
|
inQ = 0;
|
||||||
for(i = 0; (i < iQsize / 2) && (inQ < 3); i++)
|
for(i = 0; (i < iQsize / 2) && (inQ < 3); i++)
|
||||||
inQ = (Q[i] == l_node) || (Q[iQsize - i] == l_node) + 2 * (Q[i] == h_node) || (Q[iQsize - i] == h_node);
|
inQ = (Q[i] == l_node) || (Q[iQsize - i] == l_node) + 2 * (Q[i] == h_node) || (Q[iQsize - i] == h_node);
|
||||||
if (inQ & 1 == 0) inQ = inQ + (GetNode(his, varmap.varstart, l_node) != NULL);
|
if ((inQ & 1) == 0) inQ = inQ + (GetNode(his, varmap.varstart, l_node) != NULL);
|
||||||
if (inQ & 2 == 0) inQ = inQ + 2 * (GetNode(his, varmap.varstart, h_node) != NULL);
|
if ((inQ & 2) == 0) inQ = inQ + 2 * (GetNode(his, varmap.varstart, h_node) != NULL);
|
||||||
if (inQ & 1 == 1) inQ = inQ - (l_node == HIGH(manager) || l_node == LOW(manager));
|
if ((inQ & 1) == 1) inQ = inQ - (l_node == HIGH(manager) || l_node == LOW(manager));
|
||||||
if (inQ & 2 == 2) inQ = inQ - 2 * (h_node == HIGH(manager) || h_node == LOW(manager));
|
if ((inQ & 2) == 2) inQ = inQ - 2 * (h_node == HIGH(manager) || h_node == LOW(manager));
|
||||||
inQ = 0;
|
inQ = 0;
|
||||||
switch(inQ) {
|
switch(inQ) {
|
||||||
case 0:
|
case 0:
|
||||||
|
Reference in New Issue
Block a user