本文整理汇总了C++中Predicate::getSense方法的典型用法代码示例。如果您正苦于以下问题:C++ Predicate::getSense方法的具体用法?C++ Predicate::getSense怎么用?C++ Predicate::getSense使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predicate
的用法示例。
在下文中一共展示了Predicate::getSense方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initFactorMesssages
//the contribution of the factor itself
void Factor::initFactorMesssages()
{
Predicate *pred;
int numPreds = clause_->getNumPredicates();
int stateCnt = (int)pow(2.0, numPreds);
factorMsgs_ = new double[stateCnt];
bool isSatisfied;
for (int state = 0; state < stateCnt; state++)
{
isSatisfied = false;
for (int predno = 0; predno < numPreds; predno++)
{
pred = clause_->getPredicate(predno);
bool predBit = state & (1<<predno);
if (pred->getSense() == predBit)
{
isSatisfied = true;
break;
}
}
if (isSatisfied)
{
// Always 1
// MS: should be weight of clause in ground network (super or ground)
factorMsgs_[state] = clause_->getWt();
}
else
{
factorMsgs_[state] = 0;
}
}
}
示例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
//.........这里部分代码省略.........
示例3: createAndAddUnknownClause
//returns true if the (ground) clause has two literals with opposite sense
//i.e. the clause is satisfied; otherwise returns false
bool Clause::createAndAddUnknownClause(
Array<GroundClause*>* const& unknownGndClauses,
Array<Clause*>* const& unknownClauses,
double* const & numUnknownClauses,
const AddGroundClauseStruct* const & agcs,
const Database* const & db)
{
PredicateSet predSet; // used to detect duplicates
PredicateSet::iterator iter;
Clause* clause = NULL;
for (int i = 0; i < predicates_->size(); i++)
{
Predicate* predicate = (*predicates_)[i];
assert(predicate->isGrounded());
if (db->getValue(predicate) == UNKNOWN)
{
if ( (iter=predSet.find(predicate)) != predSet.end() )
{
// the two gnd preds are of opp sense, so clause must be satisfied
if ((*iter)->getSense() != predicate->getSense())
{
if (clause) delete clause;
return true;
}
// since the two gnd preds are identical, no point adding a dup
continue;
}
else
predSet.insert(predicate);
if (clause == NULL) clause = new Clause();
Predicate* pred = new Predicate(*predicate, clause);
clause->appendPredicate(pred);
}
}
if (clause)
{
if (numUnknownClauses) (*numUnknownClauses)++;
clause->setWt(wt_);
clause->canonicalizeWithoutVariables();
if (agcs)
{
if (clausedebug >= 2)
{
cout << "Appending unknown clause to MRF ";
clause->print(cout, db->getDomain());
cout << endl;
}
MRF::addUnknownGndClause(agcs, this, clause, isHardClause_);
}
// MARC: The case with unknownGndClauses appears to be obsolete!
if (unknownGndClauses)
{
if (clausedebug >= 2)
{
cout << "Appending unknown ground clause ";
clause->print(cout, db->getDomain());
cout << endl;
}
unknownGndClauses->append(new GroundClause(clause, agcs->gndPreds));
if (isHardClause_) unknownGndClauses->lastItem()->setWtToHardWt();
}
else if (unknownClauses)
{
if (clausedebug >= 2)
{
cout << "Appending unknown clause ";
clause->print(cout, db->getDomain());
cout << endl;
}
unknownClauses->append(clause);
if (isHardClause_) clause->setIsHardClause(true);
}
if (unknownClauses == NULL) delete clause;
}
return false;
}