本文整理汇总了C++中Predicate::printWithStrVar方法的典型用法代码示例。如果您正苦于以下问题:C++ Predicate::printWithStrVar方法的具体用法?C++ Predicate::printWithStrVar怎么用?C++ Predicate::printWithStrVar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predicate
的用法示例。
在下文中一共展示了Predicate::printWithStrVar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getConstantTuples
//.........这里部分代码省略.........
// Put the indexable literals first and ground them
sortLiteralsByNegationAndArity(*origClauseLits, ignoreActivePreds, db);
groundIndexableLiterals(domain, db, *origClauseLits, partGroundedClauses,
ignoreActivePreds);
}
else
{
//Sort preds in decreasing order of #TrueGndOfLiteral/#numOfGroundings.
//The larger the number of true groundings of a literal, the more likely
//it is to be true, so put it in front so that we can decide whether the
//clause is true early.The larger the number of groundings of the
//literal, the larger the savings when we decide that preceding literals
//are true.
sortLiteralsByTrueDivTotalGroundings(*origClauseLits, domain, db);
// Put the original clause as the only clause into partGroundedClauses
Array<Predicate*>* clauseLitsCopy = new Array<Predicate*>;
clauseLitsCopy->growToSize(origClauseLits->size());
for (int i = 0; i < origClauseLits->size(); i++)
(*clauseLitsCopy)[i] = new Predicate(*(*origClauseLits)[i]);
partGroundedClauses.append(clauseLitsCopy);
}
// At this point partGroundedClauses holds the nodes of the branch and
// bound algorithm. This means nothing more is indexed and we must ground
// out the rest of the predicates
if (clausedebug)
{
cout << "Partially grounded clauses to be completed: " << endl;
for (int pgcIdx = 0; pgcIdx < partGroundedClauses.size(); pgcIdx++)
{
cout << "\t";
for (int i = 0; i < partGroundedClauses[pgcIdx]->size(); i++)
{
(*partGroundedClauses[pgcIdx])[i]->printWithStrVar(cout, domain);
cout << " ";
}
cout << endl;
}
}
bool skip;
// Go through each clause in partGroundedClauses (nodes of the branch and
// bound algorithm if using inverted index; otherwise, the original
// clause), ground them out and check truth values
for (int pgcIdx = 0; pgcIdx < partGroundedClauses.size(); pgcIdx++)
{
//intially, the list of constants is simply the mln term ids
constants->copyFrom(*mlnClauseTermIds);
skip = false;
// clauseLits is a sorted copy of predicates_
Array<Predicate*> clauseLits = *(partGroundedClauses[pgcIdx]);
assert(clauseLits.size() == origClauseLits->size());
// Set the var to groundings in this clause to be those in clauseLits
Array<int>* origVarIds = new Array<int>;
for (int i = 0; i < clauseLits.size(); i++)
{
assert(clauseLits[i]->getNumTerms() ==
(*origClauseLits)[i]->getNumTerms());
// Ground variables throughout clause
for (int j = 0; j < (*origClauseLits)[i]->getNumTerms(); j++)
{
const Term* oldTerm = (*origClauseLits)[i]->getTerm(j);
const Term* newTerm = clauseLits[i]->getTerm(j);
示例2: createAndAddActiveClause
/**
* Creates and adds a ground active clause.
*
* @param activeGroundClauses If not NULL, then active GroundClauses are
* accumulated here.
* @param seenGndPreds GroundPredicates which have been seen before. Used when
* accumulating GroundClauses.
* @param db Database used to check truth values and evidence status of
* predicates.
* @param getSatisfied If true, satisfied clauses are also retrieved.
*/
bool Clause::createAndAddActiveClause(
Array<GroundClause *> * const & activeGroundClauses,
GroundPredicateHashArray* const& seenGndPreds,
const Database* const & db,
bool const & getSatisfied)
{
bool accumulateClauses = activeGroundClauses;
Predicate *cpred;
PredicateSet predSet; // used to detect duplicates
PredicateSet::iterator iter;
GroundClause *groundClause;
Clause* clause = NULL;
bool isEmpty = true;
for (int i = 0; i < predicates_->size(); i++)
{
Predicate* predicate = (*predicates_)[i];
assert(predicate);
assert(predicate->isGrounded());
if ( (iter = predSet.find(predicate)) != predSet.end() )
{
// The two gnd preds are of opp sense, so clause must be satisfied
// and no point in adding it
if (wt_ >= 0 && !getSatisfied &&
(*iter)->getSense() != predicate->getSense())
{
if (clause) delete clause;
return false;
}
// Since the two gnd preds are identical, no point adding a dup
continue;
}
else
predSet.insert(predicate);
bool isEvidence = db->getEvidenceStatus(predicate);
if (clausedebug >= 2)
{
cout << "isEvidence " << isEvidence << endl;
predicate->printWithStrVar(cout, db->getDomain());
cout << endl;
}
if (!isEvidence)
isEmpty = false;
// True evidence in a neg. clause: Discard clause
if (wt_ < 0 && isEvidence && !getSatisfied &&
db->sameTruthValueAndSense(db->getValue(predicate),
predicate->getSense()))
{
if (clause) delete clause;
return false;
}
// Add only non-evidence prdicates
if (accumulateClauses && !isEvidence)
{
if (!clause) clause = new Clause();
cpred = new Predicate(*predicate, clause);
assert(cpred);
if (clausedebug >= 2)
{
cout << "Appending pred ";
predicate->printWithStrVar(cout, db->getDomain());
cout << " to clause ";
clause->print(cout, db->getDomain());
cout << endl;
}
clause->appendPredicate(cpred);
if (clausedebug >= 2) cout << "Appended pred to clause" << endl;
}
}
// If the clause is empty after taking evidence into account, it should
// be discarded
if (isEmpty)
{
if (clausedebug >= 2) cout << "Clause is empty" << endl;
assert(!clause);
return false;
}
// Came to this point means that the clause is active (and hence nonEmpty)
else
{
// Add the corresponding ground clause if accumulateClauses is true
//.........这里部分代码省略.........