Predicate Class Reference

List of all members.

Public Member Functions

 Predicate (const PredicateTemplate *const &pt)
 Predicate (const PredicateTemplate *const &pt, Clause *const &parent)
 Predicate (const Predicate &p)
 Predicate (const Predicate &p, Clause *const &par)
 ~Predicate ()
double sizeMB () const
void compress ()
bool isEqualPred () const
bool isEqualPredWithType () const
bool isEmptyPred () const
bool isInternalPred () const
bool isInternalPredWithoutType () const
void canonicalize ()
void appendTerm (Term *const &term)
TermremoveLastTerm ()
 Removes the last term in the predicate.
bool getSense () const
void setSense (const bool &s)
void invertSense ()
TruthValue getTruthValue () const
void setTruthValue (const TruthValue &tv)
string getTruthValueAsStr () const
double getNumGroundingsIfAllVarDiff (const Domain *const &domain) const
void createAllGroundingsIfAllVarDiff (const Domain *const &domain, Array< Predicate * > &returnArray)
void createAllGroundings (const Domain *const &domain, Array< Predicate * > &returnArray)
void createAllGroundings (const Domain *const &domain, Array< int * > &returnArray)
void getGroundingNumber (const Domain *const &domain, Array< Predicate * > &returnArray, const int &grounding)
 Generates exactly one grounding of this predicate.
int getNumTerms () const
const TermgetTerm (const int &idx) const
void setTermToConstant (const int &termNum, const int &constId)
bool containsConstant (const int &constId) const
bool containsConstants () const
 Checks if this predicate contains at least one constant.
void setTemplate (PredicateTemplate *const &t)
const PredicateTemplategetTemplate () const
const char * getName () const
int getId () const
const char * getTermTypeAsStr (const int &idx) const
int getTermTypeAsInt (const int &idx) const
bool allTermsAreDiffVars ()
bool checkAllTermsAreDiffVars ()
bool isGrounded ()
bool canBeGroundedAs (Predicate *const &partGndPred)
 Checks if this predicate can be grounded as another (potentially) partially grounded predicate.
bool canBeGroundedAs (const GroundPredicate *const &gndPred)
Array< int > * getPredicateConstants (Array< int > *const &constants)
Array< int > * getPredicateConstants ()
void setDirty ()
bool isDirty () const
void setParent (Clause *const &parent)
ClausegetParent () const
bool isIndexable (bool posClause)
void createVarsTypeIdArr (Array< VarsTypeId * > *&varsTypeIdArr)
void deleteVarsTypeIdArr (Array< VarsTypeId * > *&varsTypeIdArr)
bool same (Predicate *const &p)
bool same (const GroundPredicate *const &gp)
void appendIntArrRep (Array< int > &rep)
size_t hashCode ()
ostream & printAsInt (ostream &out) const
ostream & printWithStrVar (ostream &out, const Domain *const &domain) const
ostream & print (ostream &out, const Domain *const &domain) const

Static Public Member Functions

static void computeFixedSizeB ()
static void createAllGroundings (const int &predId, const Domain *const &domain, Array< Predicate * > &returnArray)
static void createAllGroundingsUnifyingWithTerm (const int &predId, const Domain *const &domain, Array< Predicate * > &returnArray, int termTypeId, int termVal)

Detailed Description

Definition at line 88 of file predicate.h.


Member Function Documentation

Term* Predicate::removeLastTerm (  )  [inline]

Removes the last term in the predicate.

The template is not changed and terms_ is compressed. Returned Term* no longer belongs to the predicate and caller is responsible for deleting it.

Definition at line 186 of file predicate.h.

References Array< Type >::compress(), Array< Type >::removeLastItem(), and setDirty().

00187   {
00188     Term* term = terms_->removeLastItem();
00189     terms_->compress();
00190     setDirty();
00191     return term;
00192   }

void Predicate::getGroundingNumber ( const Domain *const &  domain,
Array< Predicate * > &  returnArray,
const int &  grounding 
) [inline]

Generates exactly one grounding of this predicate.

Parameters:
domain Domain in which this predicate exists.
returnArray The one grounding produced is placed as the only element in this Array.
grounding The index of the grounding to be produced. This is the grounding-th combination of constants.

Definition at line 252 of file predicate.h.

References createAllGroundings().

Referenced by Domain::getPredInBlock().

00254   { createAllGroundings(domain, &returnArray, NULL, grounding); }

bool Predicate::containsConstants (  )  const [inline]

Checks if this predicate contains at least one constant.

Returns:
True if and only if at least one term is a constant

Definition at line 288 of file predicate.h.

References Array< Type >::size().

Referenced by Database::getIndexedGndings().

00289   {
00290     for (int i = 0; i < terms_->size(); i++)
00291     {
00292       Term* t = (*terms_)[i];
00293       if (t->getType() == Term::CONSTANT) return true;
00294     }
00295     return false;    
00296   }

bool Predicate::canBeGroundedAs ( Predicate *const &  partGndPred  )  [inline]

Checks if this predicate can be grounded as another (potentially) partially grounded predicate.

Parameters:
partGndPred Partially grounded predicate to which this predicate is being compared.
Returns:
true, if this predicate can be grounded as partGndPred.

Definition at line 372 of file predicate.h.

References allTermsAreDiffVars(), getId(), PredicateTemplate::getId(), isGrounded(), same(), and Array< Type >::size().

00373   {
00374     //assert(partGndPred->isGrounded());
00375     if (template_->getId() != partGndPred->getId()) return false;
00376     if (allTermsAreDiffVars()) return true;
00377     if (isGrounded() && partGndPred->isGrounded()) return same(partGndPred);
00378     
00379     int varGndings[MAX_VAR];
00380     memset(varGndings, -1, MAX_VAR*sizeof(int));
00381     for (int i = 0; i < terms_->size(); i++) 
00382     {
00383       int termType = (*terms_)[i]->getType();
00384       
00385       if (termType == Term::CONSTANT) 
00386       {
00387         if ((*terms_)[i]->getId() != partGndPred->getTerm(i)->getId()) 
00388           return false;
00389       }
00390       else 
00391       if (termType == Term::VARIABLE) 
00392       {
00393         int varId = -(*terms_)[i]->getId();
00394         assert(varId > 0);
00395         assert(varId < MAX_VAR);
00396         if (varGndings[varId] < 0) // if variable has not been grounded
00397           varGndings[varId] = partGndPred->getTerm(i)->getId();
00398         else 
00399           if (varGndings[varId] != partGndPred->getTerm(i)->getId())
00400             return false;
00401       }
00402       else
00403       {
00404         assert(false);
00405       }
00406     }
00407     return true;
00408   }


The documentation for this class was generated from the following files:
Generated on Sun Jun 7 11:55:27 2009 for Alchemy by  doxygen 1.5.1