本文整理汇总了C++中Predicate类的典型用法代码示例。如果您正苦于以下问题:C++ Predicate类的具体用法?C++ Predicate怎么用?C++ Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Predicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nodesInAxis
void Step::evaluate(Node* context, NodeSet& nodes) const
{
nodesInAxis(context, nodes);
EvaluationContext& evaluationContext = Expression::evaluationContext();
for (unsigned i = 0; i < m_predicates.size(); i++) {
Predicate* predicate = m_predicates[i];
NodeSet newNodes;
if (!nodes.isSorted())
newNodes.markSorted(false);
evaluationContext.size = nodes.size();
evaluationContext.position = 1;
for (unsigned j = 0; j < nodes.size(); j++) {
Node* node = nodes[j];
Expression::evaluationContext().node = node;
EvaluationContext backupCtx = evaluationContext;
if (predicate->evaluate())
newNodes.append(node);
evaluationContext = backupCtx;
++evaluationContext.position;
}
nodes.swap(newNodes);
}
}
示例2: GetLog
shared_ptr<ActionObject> HingeEffector::GetActionObject(const Predicate& predicate)
{
for(;;)
{
if (mJoint.get() == 0)
{
break;
}
if (predicate.name != GetPredicate())
{
GetLog()->Error()
<< "ERROR: (HingeEffector) invalid predicate"
<< predicate.name << "\n";
break;
}
Predicate::Iterator iter = predicate.begin();
float velocity;
if (! predicate.AdvanceValue(iter, velocity))
{
GetLog()->Error()
<< "ERROR: (HingeEffector) motor velocity expected\n";
break;
}
return shared_ptr<HingeAction>(new HingeAction(GetPredicate(),velocity));
}
return shared_ptr<ActionObject>();
}
示例3: 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("");
}
}
示例4: parseParamList
void Parser::parseParamList(vector<Token>& toParse, Predicate& p)
{
fillmyToken(toParse);
if(myToken.myType == STRING)
{
match(STRING);
Parameter param(myToken.data, myToken.myType);
p.addParameter(param);
domain.insert(myToken.data);
}
else
{
match(ID);
Parameter param(myToken.data, myToken.myType);
p.addParameter(param);
}
fillmyToken(toParse);
if(myToken.myType == COMMA) //more parameters to read
{
advanceIndex();
parseParamList(toParse, p);
}
else
{
//do nothing; no more parameters
}
}
示例5: ParseError
/*
* Fa il parsing della RHS della regola
*/
list<PredicateCall>
Parser::parse_rule_rhs(list<Token> token_list) {
list<Token>::iterator token_iterator = token_list.begin();
list<Token> predicate_tokens;
list<PredicateCall> rhs;
uint32_t read_tokens = 0;
if (token_iterator == token_list.end())
throw ParseError("empty right hand side");
while (token_iterator != token_list.end()) {
predicate_tokens = BUILD_TOKEN_BLOCK(token_iterator, string(1, LNG_STMT_END).c_str(), TKN_OPERATOR, token_list.end());
Predicate pred = this->parse_predicate(predicate_tokens, predicate_tokens.begin(), &read_tokens);
token_iterator = this->advance_iterator(token_iterator, read_tokens);
++token_iterator;
read_tokens = 0;
if ((token_iterator->get_type() == TKN_OPERATOR) &&
(!token_iterator->get_value().compare(string(1, LNG_STMT_END)))) {
++token_iterator;
} else if (token_iterator == token_list.end()) {
throw ParseError("expected ; as predicate separator", (*(--token_iterator)).get_line_no());
}
PredicateCall call;
call.set_name(pred.get_name());
call.set_parameters(pred.get_parameters());
rhs.push_back(call);
}
return rhs;
};
示例6: nodesInAxis
void Step::evaluate(EvaluationContext& evaluationContext, Node* context, NodeSet& nodes) const
{
evaluationContext.position = 0;
nodesInAxis(evaluationContext, context, nodes);
// Check predicates that couldn't be merged into node test.
for (unsigned i = 0; i < m_predicates.size(); i++) {
Predicate* predicate = m_predicates[i].get();
OwnPtrWillBeRawPtr<NodeSet> newNodes(NodeSet::create());
if (!nodes.isSorted())
newNodes->markSorted(false);
for (unsigned j = 0; j < nodes.size(); j++) {
Node* node = nodes[j];
evaluationContext.node = node;
evaluationContext.size = nodes.size();
evaluationContext.position = j + 1;
if (predicate->evaluate(evaluationContext))
newNodes->append(node);
}
nodes.swap(*newNodes);
}
}
示例7: if
ProteinList_Filter::Impl::Impl(ProteinListPtr _original, const Predicate& predicate)
: original(_original), getSequence(false)
{
if (!original.get()) throw runtime_error("[ProteinList_Filter] Null pointer");
// iterate through the proteins, using predicate to build the sub-list
for (size_t i=1, end=original->size(); i<=end; ++i)
{
if (predicate.done()) break;
ProteinPtr protein = original->protein(i-1, getSequence);
tribool accepted = predicate.accept(*protein);
if (accepted || getSequence) // if still indeterminate with getSequence = true, it passes the filter by default
{
pushProtein(*protein);
}
else if (!accepted)
{
// do nothing
}
else // indeterminate and !getSequence
{
// try again with getSequence = true
getSequence = true;
--i;
}
}
}
示例8: nodesInAxis
void Step::evaluate(Node* context, NodeSet& nodes) const
{
EvaluationContext& evaluationContext = Expression::evaluationContext();
evaluationContext.position = 0;
nodesInAxis(context, nodes);
// Check predicates that couldn't be merged into node test.
for (unsigned i = 0; i < m_predicates.size(); i++) {
Predicate* predicate = m_predicates[i].get();
NodeSet newNodes;
if (!nodes.isSorted())
newNodes.markSorted(false);
for (unsigned j = 0; j < nodes.size(); j++) {
Node* node = nodes[j];
evaluationContext.node = node;
evaluationContext.size = nodes.size();
evaluationContext.position = j + 1;
if (predicate->evaluate())
newNodes.append(node);
}
nodes.swap(newNodes);
}
}
示例9: assert
/*
* Caller is responsible for deleting returned Predicate* if necessary
*/
Predicate* Domain::getNonEvidenceAtom(const int& index) const
{
int predId = -1;
int numAtomsPerPred;
int numAtoms = 0;
for (int i = 0; i < getNumPredicates(); i++)
{
numAtomsPerPred = (*numNonEvidAtomsPerPred_)[i];
if (numAtoms + numAtomsPerPred >= index + 1)
{
predId = i;
break;
}
numAtoms += numAtomsPerPred;
}
assert(predId >= 0);
// Get the newIndex-th grounding of f.o. pred with id predId
Predicate* pred = createPredicate(predId, false);
// Not all groundings of pred are non-evidence, so we need the while loop
bool foundNE = false;
while(!foundNE)
{
for (int i = 0; i < pred->getNumTerms(); i++)
{
int termType = pred->getTermTypeAsInt(i);
const Array<int>* constantsByType = getConstantsByType(termType);
int constIdx = random() % constantsByType->size();
pred->setTermToConstant(i, (*constantsByType)[constIdx]);
}
assert(pred->isGrounded());
if (!db_->getEvidenceStatus(pred)) foundNE = true;
}
return pred;
}
示例10: GetLog
shared_ptr<ActionObject>
PanTiltEffector::GetActionObject(const Predicate& predicate)
{
if (predicate.name != GetPredicate())
{
GetLog()->Error() << "ERROR: (PanTiltEffector) invalid predicate"
<< predicate.name << "\n";
return shared_ptr<ActionObject>();
}
Predicate::Iterator iter = predicate.begin();
float pan;
if (! predicate.AdvanceValue(iter, pan))
{
GetLog()->Error() << "ERROR: (PanTiltEffector) 2 float parameters expected\n";
return shared_ptr<ActionObject>(new ActionObject(GetPredicate()));
}
float tilt;
if (! predicate.AdvanceValue(iter, tilt))
{
GetLog()->Error() << "ERROR: (PanTiltEffector) float parameter expected\n";
return shared_ptr<ActionObject>(new ActionObject(GetPredicate()));
}
return shared_ptr<ActionObject>(new PanTiltAction(GetPredicate(),pan,tilt));
}
示例11: 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;
}
}
}
示例12: GetLog
boost::shared_ptr<ActionObject>
SceneEffector::GetActionObject(const Predicate& predicate)
{
if (predicate.name != GetPredicate())
{
GetLog()->Error() << "(SceneEffector) ERROR: invalid predicate"
<< predicate.name << "\n";
return boost::shared_ptr<ActionObject>();
}
string scene;
if (! predicate.GetValue(predicate.begin(), scene))
{
GetLog()->Error()
<< "ERROR: (SceneEffector) scene filename expected\n";
return boost::shared_ptr<ActionObject>();
};
boost::shared_ptr<ParameterList> parameters(
new ParameterList(predicate.parameter));
parameters->Pop_Front();
return boost::shared_ptr<ActionObject>(
new SceneAction(GetPredicate(), scene, parameters));
}
示例13:
double Matcher::predicateMatchScore
( const Predicate& sp,
const Predicate& tp ) const
{
map<Predicate, Predicate>::const_iterator sp_pos = matchedPreds.find(sp);
map<Predicate, Predicate>::const_iterator tp_pos = matchedPreds.find(tp);
if (sp_pos != matchedPreds.end() and sp_pos->second != tp) {
return 0;
}
if (tp_pos != matchedPreds.end() and tp_pos->second != sp) {
return 0;
}
if (sp.get_arity() == 0 and tp.get_arity() == 0) {
return 1;
}
set<PlaceType> spTypes = sourcePreds.find(sp)->second;
set<PlaceType> tpTypes = targetPreds.find(tp)->second;
vector<PlaceType> intersection;
set_intersection(spTypes.begin(), spTypes.end(),
tpTypes.begin(), tpTypes.end(),
back_inserter(intersection));
double score = intersection.size() / (spTypes.size() + tpTypes.size());
return score;
}
示例14: GetLog
boost::shared_ptr<ActionObject>
SayEffector::GetActionObject(const Predicate& predicate)
{
if (predicate.name != GetPredicate())
{
GetLog()->Error() << "ERROR: (SayEffector) invalid predicate"
<< predicate.name << "\n";
// some error happened
return boost::shared_ptr<ActionObject>();
}
Predicate::Iterator iter = predicate.begin();
std::string message;
if (! predicate.AdvanceValue(iter, message))
{
GetLog()->Error()
<< "ERROR: (SayEffector) said message expected\n";
// some error happened
return boost::shared_ptr<ActionObject>();
}
// construct the SayAction object
return boost::shared_ptr<SayAction>(new SayAction(GetPredicate(), message));
}
示例15: getPredicate
Predicate* PredicateTable::getPredicate(index_object id) {
Predicate p;
p.setIndex(id);
Predicate *p_finded = *hash.find(&p);
return p_finded;
}