void CNFMgr::convertFormulaToCNFPosAND(const ASTNode& varphi, ClauseList* defs) { //**************************************** // (pos) AND ~> UNION //**************************************** ASTVec::const_iterator it = varphi.GetChildren().begin(); convertFormulaToCNF(*it, defs); ClauseList* psi = ClauseList::COPY(*(info[*it]->clausespos)); for (it++; it != varphi.GetChildren().end(); it++) { convertFormulaToCNF(*it, defs); CNFInfo* x = info[*it]; if (sharesPos(*x) == 1) { psi->insert(x->clausespos); delete (x->clausespos); x->clausespos = NULL; if (x->clausesneg == NULL) { delete x; info.erase(*it); } } else { ClauseList::INPLACE_UNION(psi, *(x->clausespos)); reduceMemoryFootprintPos(*it); } } if (renameAllSiblings) { assert(((unsigned)psi->size()) == varphi.GetChildren().size()); } info[varphi]->clausespos = psi; } //End of convertFormulaToCNFPosAND()
void CNFMgr::doRenamingNeg(const ASTNode& varphi, ClauseList* defs) { CNFInfo* x = info[varphi]; //######################################## // step 2, calc new variable //######################################## ostringstream oss; oss << "cnf" << "{" << varphi.GetNodeNum() << "}"; ASTNode psi = bm->CreateSymbol(oss.str().c_str(),0,0); //######################################## // step 3, add defs //######################################## ASTNode* copy = ASTNodeToASTNodePtr(psi); ClauseList* cl = info[varphi]->clausesneg; cl->appendToAllClauses(copy); defs->insert(cl); delete cl; //######################################## // step 4, update info[varphi] //######################################## x->clausesneg = SINGLETON(bm->CreateNode(NOT, psi)); setWasRenamedNeg(*x); } //End of doRenamingNeg()
void CNFMgr::convertFormulaToCNFNegOR(const ASTNode& varphi, ClauseList* defs) { //**************************************** // (neg) OR ~> UNION NOT //**************************************** ASTVec::const_iterator it = varphi.GetChildren().begin(); convertFormulaToCNF(*it, defs); ClauseList* psi = ClauseList::COPY(*(info[*it]->clausesneg)); reduceMemoryFootprintNeg(*it); for (it++; it != varphi.GetChildren().end(); it++) { convertFormulaToCNF(*it, defs); CNFInfo* x = info[*it]; if (sharesNeg(*x) != 1) { ClauseList::INPLACE_UNION(psi, *(x->clausesneg)); reduceMemoryFootprintNeg(*it); } else { // If this is the only use of "clausesneg", no reason to make a copy. psi->insert(x->clausesneg); // Copied from reduceMemoryFootprintNeg delete x->clausesneg; x->clausesneg = NULL; if (x->clausespos == NULL) { delete x; info.erase(*it); } } } info[varphi]->clausesneg = psi; } //End of convertFormulaToCNFNegOR()
ClauseList* CNFMgr::SINGLETON(const ASTNode& varphi) { ASTNode* copy = ASTNodeToASTNodePtr(varphi); ClausePtr clause = new vector<const ASTNode*> (); clause->push_back(copy); ClauseList* psi = new ClauseList(); psi->push_back(clause); return psi; } //End of SINGLETON()
void CNFMgr::convertFormulaToCNFPosNAND(const ASTNode& varphi, ClauseList* defs) { bool renamesibs = false; ClauseList* clauses; ClauseList* psi; ClauseList* oldpsi; //**************************************** // (pos) NAND ~> PRODUCT NOT //**************************************** ASTVec::const_iterator it = varphi.GetChildren().begin(); convertFormulaToCNF(*it, defs); clauses = info[*it]->clausesneg; if (clauses->size() > 1) { renamesibs = true; } psi = ClauseList::COPY(*clauses); reduceMemoryFootprintNeg(*it); for (it++; it != varphi.GetChildren().end(); it++) { if (renamesibs) { setDoSibRenamingNeg(*(info[*it])); } convertFormulaToCNF(*it, defs); clauses = info[*it]->clausesneg; if (clauses->size() > 1) { renamesibs = true; } oldpsi = psi; psi = ClauseList::PRODUCT(*psi, *clauses); reduceMemoryFootprintNeg(*it); DELETE(oldpsi); } info[varphi]->clausespos = psi; } //End of convertFormulaToCNFPosNAND()
ClauseList* CNFMgr::convertToCNF(const ASTNode& varphi) { bm->GetRunTimes()->start(RunTimes::CNFConversion); scanFormula(varphi, true, false); ClauseList* defs = SINGLETON(dummy_true_var); convertFormulaToCNF(varphi, defs); ClauseList* top = info[varphi]->clausespos; defs->insertAtFront(top); cleanup(varphi); bm->GetRunTimes()->stop(RunTimes::CNFConversion); if (bm->UserFlags.stats_flag) { cerr << "\nPrinting: After CNF conversion: " << endl; cerr << "Number of clauses:" << defs->size() << endl; // PrintClauseList(cout, *defs); cerr << "Number of xor-clauses:" << clausesxor->size() << endl; // PrintClauseList(cout, *clausesxor); } return defs; }//End of convertToCNF()
// expects varphi2 to be just a single clause. void ClauseList::INPLACE_PRODUCT(const ClauseList& varphi2) { assert(1 == varphi2.size()); ClauseList& varphi1 = *this; ClauseContainer::iterator it1 = varphi1.cont.begin(); ClauseContainer::iterator this_end = varphi1.cont.end(); const ClauseNoPtr::const_iterator& insert_end = varphi2.cont.front()->end(); const ClauseNoPtr::const_iterator& insert_begin = varphi2.cont.front()->begin(); for (; it1 != this_end; it1++) { ClausePtr p = *it1; p->insert(p->end(), insert_begin, insert_end); } }