DdNode * Dddmp_cuddBddLoad ( DdManager *ddMgr /* IN: DD Manager */, Dddmp_VarMatchType varMatchMode /* IN: storing mode selector */, char **varmatchnames /* IN: array of variable names - by IDs */, int *varmatchauxids /* IN: array of variable auxids - by IDs */, int *varcomposeids /* IN: array of new ids accessed - by IDs */, int mode /* IN: requested input file format */, char *file /* IN: file name */, FILE *fp /* IN: file pointer */ ) { DdNode *f , **tmpArray; int i, nRoots; nRoots = Dddmp_cuddBddArrayLoad(ddMgr,DDDMP_ROOT_MATCHLIST,NULL, varMatchMode,varmatchnames,varmatchauxids,varcomposeids, mode,file,fp,&tmpArray); if (nRoots == 0) { return (NULL); } else { f = tmpArray[0]; if (nRoots > 1) { fprintf (stderr, "Warning: %d BDD roots found in file. Only first retrieved.\n", nRoots); for (i=1; i<nRoots; i++) { Cudd_RecursiveDeref (ddMgr, tmpArray[i]); } } DDDMP_FREE (tmpArray); return (f); } }
bool qbf_skizzo_coret::get_certificate(void) { std::string result_tmp_file="ozziKs.out"; std::string options="-dump qbm=bdd"; std::string log_file = qbf_tmp_file + ".sKizzo.log"; system(("ozziKs " + options + " " + log_file + " > "+result_tmp_file).c_str()); // read result bool result=false; { std::ifstream in(result_tmp_file.c_str()); std::string key=" [OK, VALID,"; while(in) { std::string line; std::getline(in, line); if(line!="" && line[line.size()-1]=='\r') line.resize(line.size()-1); if(line.compare(0, key.size(), key)==0) { result=true; break; } } } if(!result) { messaget::error("Skizzo failed: unknown result"); return true; } remove(result_tmp_file.c_str()); remove(log_file.c_str()); // certificate reconstruction done, now let's load it from the .qbm file int n_e; std::vector<int> e_list; int e_max=0; // check header result=false; { std::ifstream in((qbf_tmp_file+".qbm").c_str()); std::string key="# existentials["; std::string line; std::getline(in, line); assert(line=="# QBM file, 1.3"); while(in) { std::getline(in, line); if(line!="" && line[line.size()-1]=='\r') line.resize(line.size()-1); if(line.compare(0, key.size(), key)==0) { result=true; break; } } size_t ob=line.find('['); std::string n_es=line.substr(ob+1, line.find(']')-ob-1); n_e=atoi(n_es.c_str()); assert(n_e!=0); e_list.resize(n_e); std::string e_lists=line.substr(line.find(':')+2); for(int i=0; i<n_e; i++) { size_t space=e_lists.find(' '); int cur=atoi(e_lists.substr(0, space).c_str()); assert(cur!=0); e_list[i]=cur; if(cur>e_max) e_max=cur; e_lists = e_lists.substr(space+1); } if(!result) throw ("Existential mapping from sKizzo missing"); in.close(); // workaround for long comments system(("sed -e \"s/^#.*$/# no comment/\" -i "+qbf_tmp_file+".qbm").c_str()); } { DdNode **bdds; std::string bdd_file=qbf_tmp_file+".qbm"; // dddmp insists on a non-const string here... char filename[bdd_file.size()+1]; strcpy(filename, bdd_file.c_str()); bdd_manager->AutodynEnable(CUDD_REORDER_SIFT); int nroots = Dddmp_cuddBddArrayLoad(bdd_manager->getManager(), DDDMP_ROOT_MATCHLIST, NULL, DDDMP_VAR_MATCHIDS, NULL, NULL, NULL, DDDMP_MODE_DEFAULT, filename, NULL, &bdds); assert(nroots=2*n_e); // ozziKs documentation guarantees that. model_bdds.resize(e_max+1, NULL); for(unsigned i=0; i<e_list.size(); i++) { int cur=e_list[i]; DdNode *posNode = bdds[2*i]; DdNode *negNode = bdds[2*i+1]; if(Cudd_DagSize(posNode) <= Cudd_DagSize(negNode)) model_bdds[cur]=new BDD(bdd_manager, posNode); else model_bdds[cur]=new BDD(bdd_manager, Cudd_Not(negNode)); } // tell CUDD that we don't need those BDDs anymore. for(int i=0; i<nroots; i++) Cudd_Deref(bdds[i]); free(bdds); bdds=NULL; remove(bdd_file.c_str()); remove((qbf_tmp_file+".qbm").c_str()); } return false; }