本文整理汇总了C++中Formula类的典型用法代码示例。如果您正苦于以下问题:C++ Formula类的具体用法?C++ Formula怎么用?C++ Formula使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Formula类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readFromFile
/**************************************************************************************************
* IO
* ***********************************************************************************************/
Formula IO::readFromFile(const std::string fileName){
Formula result;
uint numberVars;
std::fstream data;
data.open(fileName, std::ios::in);
if(!data.is_open()){
std::cout << "Could not open: " << fileName;
exit(1);
}
while(!data.eof()){
std::string line;
getline(data, line);
if(line.empty()) continue;
if(line[0] == 'c' || line[0] == 'C') continue;
// Header line
if(line[0] == 'p'){
line = line.substr(line.find(" ")+1);
line = line.substr(line.find(" ")+1);
numberVars = std::stoi(line.substr(0, line.find(" ")));
result.setNumberOfVariables(numberVars);
continue;
}
result.addClauses(Clauses(line));
}
return result;
}
示例2: impIClicked
void MainWindow::impIClicked()
{
QList<QGraphicsItem *> selected_list = scene->selectedItems();
Node* selected = (Node*)(selected_list.at(0));
selected->setRule("impI");
selected->update();
Formula f = selected->getFormula();
Formula op1 = ((Imp*)f.get())->getOperand1();
Formula op2 = ((Imp*)f.get())->getOperand2();
std::ostringstream stream;
op2->printFormula(stream);
qreal rect_width = stream.str().length()*PARAMETER;
qreal rect_height = 20;
int rect_x = selected->getx() ;
int rect_y = selected->gety() - 20 - depth/2;
QVector<Formula> assumptions = selected->getAssumptions();
assumptions.push_back(op1);
Node* item = new Node( op2, rect_width, rect_height, rect_x, rect_y, selected_list.at(0), assumptions);
scene->addNode(item);
}
示例3: equalTo
bool equalTo( const Formula & f) const
{
return f->getType() == this->getType() &&
_op1->equalTo(((BinaryConjective *)f.get())->getOperand1())
&&
_op2->equalTo(((BinaryConjective *)f.get())->getOperand2());
}
示例4: Formula
/**
* ((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;
}
示例5: FormulaException
Formula Formula::differentiateWithRespectTo(std::string varName) {
using AST::Expression::Expression;
using AST::Expression::Text;
using AST::Visitor::GetDerivativeVisitor;
using AST::Visitor::StringifyVisitor;
using AST::Visitor::SimplifyVisitor;
if (formulaExpr == NULL) {
throw FormulaException("invalid formula");
}
std::unique_ptr<GetDerivativeVisitor> getDerivativeVisitorPtr(new GetDerivativeVisitor());
std::unique_ptr<SimplifyVisitor> simplifyVisitorPtr(new SimplifyVisitor());
std::unique_ptr<StringifyVisitor> stringifyVisitorPtr(new StringifyVisitor());
getDerivativeVisitorPtr.get()->setDerivativeVariableName(varName);
std::unique_ptr<Expression> derivativeExprPtr((Expression *)formulaExpr->accept(getDerivativeVisitorPtr.get()));
std::unique_ptr<Expression> simplifiedDerivativeExprPtr((Expression *)derivativeExprPtr.get()->accept(simplifyVisitorPtr.get()));
std::unique_ptr<Text> stringifiedDerivativeExprPtr((Text *)simplifiedDerivativeExprPtr.get()->accept(stringifyVisitorPtr.get()));
Formula derivative;
derivative.setFormulaString(stringifiedDerivativeExprPtr.get()->getContent());
derivative.setFormulaExpr(simplifiedDerivativeExprPtr.release());
return derivative;
}
示例6: copyConsTest
void copyConsTest()
{
char str[100];
while (gets(str)) {
Parser p(str);
Formula *f = p.parse();
f->print();
puts("");
Predicate *pred = f->getPredicate();
Term *t = pred->getTermList()->getList()->at(0);
puts("here");
Term w = *t;
w.print();
puts("here");
w.setName("chan");
w.print();
puts("");
f->print();
puts("");
}
}
示例7: formulaTest
void formulaTest()
{
TermList *list = new TermList();
list->addTerm(new Term(Term::VAR, "x"));
list->addTerm(new Term(Term::VAR, NULL));
list->addTerm(new Term(Term::CONS, "A"));
Formula *f = new Formula(new Predicate("P", list));
Formula *g = new Formula(f);
Formula *q = new Formula(f, g, '&');
Formula *r = new Formula(new Term(Term::VAR, NULL), q, Formula::UNIV);
r->print();
Term *x = new Term(Term::VAR, "xy");
Term *y = new Term(Term::VAR, "x");
TermList *list2 = new TermList();
list2->addTerm(x);
list2->addTerm(y);
Term *f2 = new Term("f10", list2);
Term *g2 = new Term("f10", list2);
f2->print();
puts("");
g2->print();
puts("");
if (!(*f2 != *g2)) {
printf("yes! equal!");
}
}
示例8: if
bool Prover::isClosed(queue<Formula*> &q, int tabCount)
{
vector<Formula*> aList;
vector<Formula*> ntAList;
int sz = q.size();
for (int i = 0; i < sz; ++i) {
Formula *f = q.front();
q.pop();
q.push(f);
if (f->isAtomic()) {
aList.push_back(f);
}
else if (f->isNegated() && f->nextFormula->isAtomic()) {
ntAList.push_back(f->nextFormula);
}
}
for (int i = 0; i < aList.size(); i++) {
Formula *f1 = aList.at(i);
for (int j = 0; j < ntAList.size(); j++) {
Formula *f2 = ntAList.at(j);
if (!strcmp(f1->getPredicate()->getName(), f2->getPredicate()->getName())) {
//if (isUnifiable(f1->getPredicate()->getTermList(), f2->getPredicate()->getTermList())) {
if (isUnifiable(f1->getPredicate(), f2->getPredicate(), tabCount)) {
return true;
}
}
}
}
return false;
}
示例9: func_multiple_operations
//
// Function: MULTIPLE.OPERATIONS
//
Value func_multiple_operations(valVector args, ValueCalc *, FuncExtra *e)
{
if (args.count() != 3 && args.count() != 5)
return Value::errorVALUE(); // invalid number of parameters
for (int i = 0; i < args.count(); i++) {
if (e->ranges[i].col1 == -1 || e->ranges[i].row1 == -1)
return Value::errorVALUE();
}
CellStorage *s = e->sheet->cellStorage();
// get formula to evaluate
int formulaCol = e->ranges[0].col1;
int formulaRow = e->ranges[0].row1;
Formula formula = s->formula(formulaCol, formulaRow);
if (!formula.isValid())
return Value::errorVALUE();
CellIndirection cellIndirections;
cellIndirections.insert(Cell(e->sheet, e->ranges[1].col1, e->ranges[1].row1), Cell(e->sheet, e->ranges[2].col1, e->ranges[2].row1));
if (args.count() > 3) {
cellIndirections.insert(Cell(e->sheet, e->ranges[3].col1, e->ranges[3].row1), Cell(e->sheet, e->ranges[4].col1, e->ranges[4].row1));
}
return formula.eval(cellIndirections);
}
示例10: Formula
Formula* Formula::getDelta(Term *newFunc)
{
Formula *f;
Term *v;
if (this->type == EXIST) {
f = this->nextFormula;
v = this->qVar;
}
else {
f = new Formula(this->nextFormula->getNext());
v = this->nextFormula->getQVar();
}
if (newFunc == NULL) {
TermList *list = new TermList();
f->getFreeVarList(list);
newFunc = new Term(NULL, list);
}
f->replace(v, newFunc);
return f;
}
示例11: Formula
void EspressoData::add(EspressoCover &f, Formula::State state)
{
if (origFormula) {
Formula *formula = new Formula(*origFormula, f.cover);
formula->setState(state);
steps.push_back(formula);
}
}
示例12: func_isformula
// Function: ISFORMULA
Value func_isformula(valVector /*args*/, ValueCalc */*calc*/, FuncExtra *e)
{
const Calligra::Sheets::Region ®ion = e->regions[0];
QPoint p = region.firstRange().topLeft();
CellStorage *s = region.firstSheet()->cellStorage();
Formula formula = s->formula(p.x(), p.y());
return Value(formula.isValid());
}
示例13: SetUseValuesFromTriggerTime
bool AntimonyEvent::SetUseValuesFromTriggerTime(const Formula& form)
{
if (!form.IsBoolean()) {
g_registry.SetError("Unable to use '" + form.ToDelimitedStringWithEllipses(".") + "': only 'true' or 'false' may be used to set the value of 'fromTrigger' on an event.");
return true;
}
m_useValuesFromTriggerTime = form.GetBoolean();
return false;
}
示例14: SetInitialValue
bool AntimonyEvent::SetInitialValue(const Formula& form)
{
if (!form.IsBoolean()) {
g_registry.SetError("Unable to use '" + form.ToDelimitedStringWithEllipses(".") + "': only 'true' or 'false' may be used to set the value of 't0' (the initial value) of an event.");
return true;
}
m_initialValue = form.GetBoolean();
return false;
}
示例15: SetPersistent
bool AntimonyEvent::SetPersistent(const Formula& form)
{
if (!form.IsBoolean()) {
g_registry.SetError("Unable to use '" + form.ToDelimitedStringWithEllipses(".") + "': only 'true' or 'false' may be used to set the value of 'persistent' on an event.");
return true;
}
m_persistent = form.GetBoolean();
return false;
}