/** * 把量词保存到对应的vector * @param originalFml 一阶语句 * @return */ Formula HengZhang::recordQuantifier(const Formula& _originalFml) { m_vTermsX.clear(); m_vTermsY.clear(); m_vTermsZ.clear(); m_vTermsMIN.clear(); m_vTermsMAX.clear(); _formula* fml = _originalFml.getFormula(); while(fml->formula_type == UNIV) { m_vTermsX.push_back(fml->variable_id); fml = fml->subformula_l; } while (fml->formula_type == EXIS) { m_vTermsY.push_back(fml->variable_id); const char* sDomainName = Vocabulary::instance().getVariableDomain(fml->variable_id); // MIN int id = Vocabulary::instance().generateDomainMIN(sDomainName); m_vTermsMIN.push_back(id); // MAX id = Vocabulary::instance().generateDomainMAX(sDomainName); m_vTermsMAX.push_back(id); // Z id = Vocabulary::instance().generateNewVariable(fml->variable_id); m_vTermsZ.push_back(id); fml = fml->subformula_l; } Formula ret = Formula(fml, true); return ret; }
/** * ((succ(_Y,_Z) & s(_X,_Z)) | theta__(_X,_Y)) -> s(_X,_Y) * @return */ Formula HengZhang::createSuccAndSOrTheta__ImplS(const Formula& _originalFml) { //1 (succ(_Y,_Z) _term* term_y_z = Utils::combineTerms(m_vTermsY, m_vTermsZ); _formula* succ_y_z = Utils::compositeToAtom(m_nSymbolSucc, term_y_z); //2 s(_X,_Z) _term* term_x_z = Utils::combineTerms(m_vTermsX, m_vTermsZ); _formula* s_x_z = Utils::compositeToAtom(m_nSymbolS, term_x_z); //3 theta__(_X,_Y) Formula copyOriginalFml = _originalFml; map<int, string> mapPredicates = Vocabulary::instance().getAllIntensionPredicates(); copyOriginalFml.doubleNegationPredicates(mapPredicates); _formula* theta__ = Utils::copyFormula(copyOriginalFml.getFormula()); //4 s(_X,_Y) _term* term_x_y = Utils::combineTerms(m_vTermsX, m_vTermsY); _formula* s_x_y = Utils::compositeToAtom(m_nSymbolS, term_x_y); //create structure _formula* ll = Utils::compositeByConnective(CONJ, succ_y_z, s_x_z); _formula* l = Utils::compositeByConnective(DISJ, ll, theta__); _formula* r = s_x_y; _formula* f = Utils::compositeByConnective(IMPL, l, r); Formula fml = Formula(f, false); return fml; }
/** * 章衡量词消去公式五 2 succ(_Y,_Z) -> ((theta(_X,_Z) | t(_X,_Z)) -> t(_X,_Y)) * @param originalFml 一阶语句 * @return */ Formula HengZhang::createFormula_5_2(const Formula& _originalFml) { //1 _succ(_Y,_Z) _term* term_y_z = Utils::combineTerms(m_vTermsY, m_vTermsZ); _formula* succ_y_z = Utils::compositeToAtom(m_nSymbolSucc, term_y_z); //2 T(_X,_Y) _term* term_x_y = Utils::combineTerms(m_vTermsX, m_vTermsY); _formula* t_x_y = Utils::compositeToAtom(m_nSymbolT, term_x_y); //3 theta(_X,_Z) Formula copyOriginalFml = _originalFml; copyOriginalFml.replaceTerms(m_vTermsY, m_vTermsZ); _formula* theta_x_z = Utils::copyFormula(copyOriginalFml.getFormula()); //4 T(_X,_Z) _term* term_x_z = Utils::combineTerms(m_vTermsX, m_vTermsZ); _formula* t_x_z = Utils::compositeToAtom(m_nSymbolT, term_x_z); //create structure _formula* left = succ_y_z; _formula* rl = Utils::compositeByConnective(DISJ, theta_x_z, t_x_z); _formula* right = Utils::compositeByConnective(IMPL, rl, t_x_y); _formula* F = Utils::compositeByConnective(IMPL, left, right); Formula fml = Formula(F, false); return fml; }
void Vocabulary::addAtom(const Formula& _newAtom) { for (FORMULAS_CONST_ITERATOR iter = m_fmlAtomList->begin(); iter != m_fmlAtomList->end(); ++ iter) { if (iter->getFormula()->predicate_id == _newAtom.getFormula()->predicate_id) { return; } } m_fmlAtomList->pushBack(_newAtom); }
/** * 章衡量词消去公式四_2 (s(_X,_Y) & ((~s(_X,_Z) & succ(_Y,_Z)) | _max(Y))) * -> (theta(_X,_Y) -> t(_X,_MAX)) * @param originalFml 一阶语句 * @return */ Formula HengZhang::createFormula_4_2(const Formula& _originalFml) { // 5 theta(_X,_Y) _formula* theta_x_y = Utils::copyFormula(_originalFml.getFormula()); // 6 T(_X,_MAX) _term* term_x_max = Utils::combineTerms(m_vTermsX, m_vTermsMAX); _formula* t_x_max = Utils::compositeToAtom(m_nSymbolT, term_x_max); _formula* left = generateFormulaLeft_4(); _formula* right = Utils::compositeByConnective(IMPL, theta_x_y, t_x_max); _formula* F = Utils::compositeByConnective(IMPL, left, right); Formula fml = Formula(F, false); return fml; }
/** * 章衡量词消去公式三 t(_X,_MIN) | theta(_X,_MIN) * @param originalFml 一阶语句 * @return */ Formula HengZhang::createFormula_3(const Formula& _originalFml) { //create left sub-formula t(_X,_MIN) _term* term_x_min = Utils::combineTerms(m_vTermsX, m_vTermsMIN); _formula* t_x_min = Utils::compositeToAtom(m_nSymbolT, term_x_min); //create right sub-formula theta(_X,_MIN) Formula copyOriginalFml = _originalFml; copyOriginalFml.replaceTerms(m_vTermsY, m_vTermsMIN); _formula* theta_x_min = Utils::copyFormula(copyOriginalFml.getFormula()); //create structure _formula* F = Utils::compositeByConnective(DISJ, t_x_min, theta_x_min); Formula fml = Formula(F, false); return fml; }
bool Formula::operator == (const Formula& _rhs) const { return Utils::compareFormula(m_pFormula, _rhs.getFormula()); }
Formula::Formula(const Formula& _rhs) { m_pFormula = Utils::copyFormula(_rhs.getFormula()); }