示例#1
0
void CNFMgr::convertFormulaToCNFNegAND(const ASTNode& varphi,
                                       ClauseList* defs)
{
    bool renamesibs = false;
    ClauseList* clauses;
    ClauseList* psi;
    ClauseList* oldpsi;

    //****************************************
    // (neg) AND ~> 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;
        }

        if (clauses->size() ==1)
            psi->INPLACE_PRODUCT(*clauses);
        else
        {
            oldpsi = psi;
            psi = ClauseList::PRODUCT(*psi, *clauses);
            DELETE(oldpsi);
        }
        reduceMemoryFootprintNeg(*it);
    }

    info[varphi]->clausesneg = psi;
} //End of convertFormulaToCNFNegAND()
示例#2
0
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()
示例#3
0
void CNFMgr::convertFormulaToCNFPosOR(const ASTNode& varphi,
                                      ClauseList* defs)
{
    bool renamesibs = false;
    ClauseList* clauses;
    ClauseList* psi;
    ClauseList* oldpsi;

    //****************************************
    // (pos) OR ~> PRODUCT
    //****************************************
    ASTVec::const_iterator it = varphi.GetChildren().begin();
    convertFormulaToCNF(*it, defs);
    clauses = info[*it]->clausespos;
    if (clauses->size() > 1)
    {
        renamesibs = true;
    }
    psi = ClauseList::COPY(*clauses);
    reduceMemoryFootprintPos(*it);

    for (it++; it != varphi.GetChildren().end(); it++)
    {
        if (renamesibs)
        {
            setDoSibRenamingPos(*(info[*it]));
        }
        convertFormulaToCNF(*it, defs);
        clauses = info[*it]->clausespos;
        if (clauses->size() > 1)
        {
            renamesibs = true;
        }
        oldpsi = psi;
        psi = ClauseList::PRODUCT(*psi, *clauses);
        reduceMemoryFootprintPos(*it);
        DELETE(oldpsi);
    }

    info[varphi]->clausespos = psi;
} //End of convertFormulaToCNFPosOR()
示例#4
0
// 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);
  }
}
示例#5
0
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()