Domain Class Reference

List of all members.

Public Member Functions

 Domain ()
 ~Domain ()
void replaceTypeDualMap (DualMap *const &map)
void setTypeDualMap (DualMap *const &map)
const DualMapgetTypeDualMap () const
void replaceStrToPredTemplateMapAndPredDualMap (StrToPredTemplateMap *const &m, DualMap *const &predDualMap)
void setStrToPredTemplateMapAndPredDualMap (StrToPredTemplateMap *const &map, DualMap *const &predDualMap)
const StrToPredTemplateMap * getStrToPredTemplateMap () const
const DualMapgetPredDualMap () const
void replaceStrToFuncTemplateMapAndFuncDualMap (StrToFuncTemplateMap *const &m, DualMap *const &funcDualMap)
void setStrToFuncTemplateMapAndFuncDualMap (StrToFuncTemplateMap *const &m, DualMap *const &funcDualMap)
const StrToFuncTemplateMap * getStrToFuncTemplateMap () const
const DualMapgetFuncDualMap () const
void replaceEqualPredTemplate (PredicateTemplate *const &t)
void setEqualPredTemplate (PredicateTemplate *const &t)
const PredicateTemplategetEqualPredTemplate () const
void replaceEmptyPredTemplate (PredicateTemplate *const &t)
void setEmptyPredTemplate (PredicateTemplate *const &t)
const PredicateTemplategetEmptyPredTemplate () const
void replaceEmptyFuncUnaryTemplate (FunctionTemplate *const &t)
void replaceEmptyFuncBinaryTemplate (FunctionTemplate *const &t)
void setEmptyFuncUnaryTemplate (FunctionTemplate *const &t)
void setEmptyFuncBinaryTemplate (FunctionTemplate *const &t)
const FunctionTemplategetEmptyFuncUnaryTemplate () const
const FunctionTemplategetEmptyFuncBinaryTemplate () const
void setConstDualMap (ConstDualMap *const &map)
const ConstDualMapgetConstDualMap () const
void setConstantsByType (Array< Array< int > * > *const &cbt)
const Array< Array< int > * > * getConstantsByType () const
const Array< Array< int > * > * getExternalConstantsByType () const
void replaceFuncSet (FunctionSet *const &funcSet)
void setFuncSet (FunctionSet *const &funcSet)
const FunctionSet * getFuncSet () const
void deleteDB ()
DatabasegetDB () const
void setDB (Database *const &db)
void newTrueFalseGroundingsStore ()
TrueFalseGroundingsStoregetTrueFalseGroundingsStore () const
void setTrueFalseGroundingsStore (TrueFalseGroundingsStore *const &tfgs)
void compress ()
void updatePerOldToNewIds (MLN *const &mln, hash_map< int, int > &oldToNewConstIds)
 The constants of this domain are replaced by new constants.
void reorderConstants (MLN *const &mln, hash_map< int, PredicateHashArray * > &predIdToPredsMap)
void reorderConstants (MLN *const &mln)
void reorderConstants (ConstDualMap *const &map, Array< Array< int > * > *const &cbt, Array< Array< int > * > *const &ecbt, MLN *const &mln)
PredicatecreatePredicate (const int &predId, const bool &includeEqualPreds) const
void createPredicates (Array< Predicate * > *const &preds, const bool &includeEqualPreds) const
void createPredicates (Array< Predicate * > *const &preds, const Array< string > *const &predNames)
int addType (const char *const &name)
int getNumTypes () const
const Array< const char * > * getTypeNames () const
int getTypeId (const char *const &name) const
const char * getTypeName (const int typeId) const
bool isType (const char *const &name) const
bool isType (const int &id) const
const Array< int > * getConstantsByType (const int &typeId) const
const Array< int > * getConstantsByType (const char *const &typeName) const
const Array< int > * getConstantsByTypeWithExt (const int &typeId) const
const Array< int > * getConstantsByTypeWithExt (const char *const &typeName) const
int getNumConstantsByType (const int &typeId) const
 Returns the number of constants of a certain type in this domain.
int getNumConstantsByType (const char *const &typeName) const
 Returns the number of constants of a certain type in this domain.
int getNumConstantsByTypeWithExt (const int &typeId) const
 Returns the number of constants of a certain type in this domain.
int getNumConstantsByTypeWithExt (const char *const &typeName) const
 Returns the number of constants of a certain type in this domain.
int addConstant (const char *const &constName, const char *const &typeName)
 Adds a constant to the domain.
int addExternalConstant (const char *const &constName, const char *const &typeName)
 Adds an external constant to the domain.
int addConstant (const char *const &constName, const char *const &typeName, const bool &external)
const char * getConstantName (const int &id) const
 Returns the name of a constant in this domain associated with a given id.
int getConstantId (const char *const &name) const
bool isConstant (const char *const &name) const
bool isConstant (const int &id) const
Array< int > * getConstantTypeIds (const char *const &constName) const
Array< int > * getConstantTypeIds (const int &constId) const
Array< const char * > * getConstantTypeNames (const int &constId) const
int addPredicateTemplate (const PredicateTemplate *const &predTemplate)
int getNumPredicates () const
const Array< const char * > * getPredicateNames () const
void getNonEqualPredicateNames (Array< string > &predNames) const
int getPredicateId (const char *const &name) const
const char * getPredicateName (const int &id) const
const Array< int > * getPredicateTermTypesAsInt (const char *const &name) const
const Array< int > * getPredicateTermTypesAsInt (const int &id) const
const Array< const char * > * getPredicateTermTypesAsStr (const char *const &name) const
const Array< const char * > * getPredicateTermTypesAsStr (const int &id)
const PredicateTemplategetPredicateTemplate (const char *const &name) const
const PredicateTemplategetPredicateTemplate (const int &id) const
const int getHighestPredicateArity () const
 Finds the maximum arity of all predicates present in the domain.
const PredicateTemplategetEqualPredicateTemplate () const
const PredicateTemplategetEmptyPredicateTemplate () const
const FunctionTemplategetEmptyFunctionUnaryTemplate () const
const FunctionTemplategetEmptyFunctionBinaryTemplate () const
bool isPredicate (const char *const &name) const
bool isPredicate (const int &id) const
int addFunctionTemplate (const FunctionTemplate *const &funcTemplate)
int getNumFunctions () const
const Array< const char * > * getFunctionNames () const
int getFunctionId (const char *const &name) const
const char * getFunctionName (const int &id) const
const Array< int > * getFunctionTermTypesAsInt (const char *const &name) const
const Array< const char * > * getFunctionTermTypesAsStr (const char *const &name) const
const FunctionTemplategetFunctionTemplate (const char *const &name) const
const FunctionTemplategetFunctionTemplate (const int &id) const
bool isFunction (const char *const &name) const
bool isFunction (const int &id) const
const FunctionSet * getFunctionMappings () const
bool addFunctionMapping (Function *f)
int getFunctionRetConstId (Function *const &f) const
void printPredicateTemplates (ostream &out) const
void printFunctionTemplates (ostream &out) const
 print out the function declarations.
int getNumNonEvidenceAtoms () const
PredicategetNonEvidenceAtom (const int &index) const
int addPredBlock (Predicate *const &predBlock) const
int getBlock (const Predicate *const &pred) const
 Returns the index of the block which a ground predicate is in.
int getBlock (const GroundPredicate *const &pred) const
 Returns the index of the block which a ground predicate is in.
int getNumPredBlocks () const
const Array< Predicate * > * getPredBlocks () const
const PredicategetPredBlock (const int &index) const
const PredicategetTruePredInBlock (const int &index) const
 Caller should not delete returned Predicate.
void setTruePredInBlock (const int &index, Predicate *const &pred) const
 Sets the true predicate in a block.
const int getBlockSize (const int &index) const
const Array< bool > * getBlockEvidenceArray () const
const bool getBlockEvidence (const int &index) const
void setBlockEvidence (const int &index, const bool &value) const
const PredicategetRandomPredInBlock (const int &index) const
 Picks a predicate at random from a block.
const PredicategetPredInBlock (const int &grounding, const int &index) const
 Gets one ground predicate from a block.
const int getIndexOfPredInBlock (const Predicate *const &pred, const int &blockIdx) const
 Gets the index in a block of a predicate.
void computeNumNonEvidAtoms ()
 Computes the number of non-evidence atoms for each first-order predicate.
void setNumTrueNonEvidGndingsPerClause (Array< double > *numTrueNonEvidGndingsPerClause)
void setNumFalseNonEvidGndingsPerClause (Array< double > *numFalseNonEvidGndingsPerClause)
void setNumTrueNonEvidGndings (const int &clauseIdx, const double &count)
void setNumFalseNonEvidGndings (const int &clauseIdx, const double &count)
const double getNumTrueNonEvidGroundings (const int &clauseIdx) const
const double getNumFalseNonEvidGroundings (const int &clauseIdx) const
const double getNumNonEvidGroundings (const int &clauseIdx) const
PredicategetPredicate (Array< int > *const &constants, int predId)

Static Public Attributes

static const char * PROPOSITIONAL_TYPE
static const char * PROPOSITIONAL_CONSTANT

Detailed Description

Definition at line 92 of file domain.h.


Member Function Documentation

void Domain::updatePerOldToNewIds ( MLN *const &  mln,
hash_map< int, int > &  oldToNewConstIds 
)

The constants of this domain are replaced by new constants.

The new set of constants must be a superset of the original one. New constants are marked as external.

Definition at line 194 of file domain.cpp.

References Database::changeConstantsToNewIds(), MLN::getClauses(), Array< Type >::size(), and HashArray< Type, HashFn, EqualFn >::size().

Referenced by reorderConstants().

00196 {
00197     //ensure that the constants in MLN clauses have the new ids 
00198   const ClauseHashArray* clauses = mln->getClauses();
00199   for (int i = 0; i < clauses->size(); i++)
00200   {
00201     Clause* c = (*clauses)[i];
00202     for (int i = 0; i < c->getNumPredicates(); i++)
00203       changePredTermsToNewIds(c->getPredicate(i), oldToNewConstIds);
00204   }
00205 
00206     // Change the const ids in the pred blocks
00207   for (int i = 0; i < predBlocks_->size(); i++)
00208   {
00209     changePredTermsToNewIds((*predBlocks_)[i], oldToNewConstIds);
00210   }
00211   for (int i = 0; i < truePredsInBlock_->size(); i++)
00212   {
00213     changePredTermsToNewIds((*truePredsInBlock_)[i], oldToNewConstIds);
00214   }
00215 
00216     // Change the const ids in the database
00217   if (db_)
00218   {
00219     db_->changeConstantsToNewIds(oldToNewConstIds);
00220   }
00221 }

int Domain::getNumConstantsByType ( const int &  typeId  )  const [inline]

Returns the number of constants of a certain type in this domain.

External constants are not included.

Parameters:
typeId Id of type for which number of constants is retrieved.
Returns:
Number of constants with type typeId in this domain (not including external).

Definition at line 452 of file domain.h.

Referenced by RecursiveFeature::cacheNumGroundings(), Database::Database(), Feature::getGroundingIndex(), getNumConstantsByType(), Database::getNumEvidenceGndPreds(), Database::getNumFalseGndPreds(), Database::getNumGroundings(), Predicate::getNumGroundingsIfAllVarDiff(), and Database::getNumTrueGndPreds().

00453   { 
00454     if (!(*constantsByType_)[typeId]) return 0;
00455     return (*constantsByType_)[typeId]->size();
00456   }

int Domain::getNumConstantsByType ( const char *const &  typeName  )  const [inline]

Returns the number of constants of a certain type in this domain.

External constants are not included.

Parameters:
typeName Name of type for which number of constants is retrieved.
Returns:
Number of constants of type typeName in this domain (not including external).

Definition at line 467 of file domain.h.

References getNumConstantsByType(), and getTypeId().

00468   {
00469     int typeId = getTypeId(typeName);
00470     if (typeId < 0) return 0;
00471     return getNumConstantsByType(typeId);
00472   }

int Domain::getNumConstantsByTypeWithExt ( const int &  typeId  )  const [inline]

Returns the number of constants of a certain type in this domain.

External constants are included.

Parameters:
typeId Id of type for which number of constants is retrieved.
Returns:
Number of constants with type typeId in this domain (including external).

Definition at line 482 of file domain.h.

Referenced by Database::changeConstantsToNewIds(), Database::Database(), and getNumConstantsByTypeWithExt().

00483   {
00484     return ((*constantsByType_)[typeId])->size() +
00485            ((*externalConstantsByType_)[typeId])->size();
00486   }

int Domain::getNumConstantsByTypeWithExt ( const char *const &  typeName  )  const [inline]

Returns the number of constants of a certain type in this domain.

External constants are included.

Parameters:
typeName Name of type for which number of constants is retrieved.
Returns:
Number of constants of type typeName in this domain (including external).

Definition at line 497 of file domain.h.

References getNumConstantsByTypeWithExt(), and getTypeId().

00498   {
00499     int typeId = getTypeId(typeName);
00500     if (typeId < 0) return 0;
00501     return getNumConstantsByTypeWithExt(typeId); 
00502   }

int Domain::addConstant ( const char *const &  constName,
const char *const &  typeName 
) [inline]

Adds a constant to the domain.

Parameters:
constName Name of constant as a char*
typeName Type of constant as a char*

Definition at line 510 of file domain.h.

Referenced by addExternalConstant().

00511   {
00512     return addConstant(constName, typeName, false);
00513   }

int Domain::addExternalConstant ( const char *const &  constName,
const char *const &  typeName 
) [inline]

Adds an external constant to the domain.

External constants are not used when generating groundings of preds.

Parameters:
constName Name of constant as a char*
typeName Type of constant as a char*

Definition at line 522 of file domain.h.

References addConstant().

00524   {
00525     return addConstant(constName, typeName, true);
00526   }

const char* Domain::getConstantName ( const int &  id  )  const [inline]

Returns the name of a constant in this domain associated with a given id.

Caller should not delete returned const char*

Parameters:
id Id of constant whose name is to be retrieved.
Returns:
name of constant if id is found as constant or external constant, otherwise NULL.

Definition at line 663 of file domain.h.

References ConstDualMap::getStr().

Referenced by GroundPredicate::getPredicateStr(), GroundPredicate::getPredString(), isConstant(), Term::print(), GroundPredicate::print(), Function::printWithRetConstName(), Term::printWithStrVar(), reorderConstants(), ListObj::toCNF(), and Clause::translateConstants().

00664   {
00665     return constDualMap_->getStr(id);
00666   }

const int Domain::getHighestPredicateArity (  )  const [inline]

Finds the maximum arity of all predicates present in the domain.

Returns:
maximum arity of all predicates in the domain.

Definition at line 833 of file domain.h.

References getNumPredicates(), PredicateTemplate::getNumTerms(), and getPredicateTemplate().

00834   {
00835         int highestArity = 1;
00836         int arity;
00837         for (int i = 0; i < getNumPredicates(); i++)
00838     {
00839       arity = getPredicateTemplate(i)->getNumTerms();
00840       if (arity > highestArity) highestArity = arity;
00841     }
00842     
00843         return highestArity;
00844   }

void Domain::printFunctionTemplates ( ostream &  out  )  const [inline]

print out the function declarations.

output stream to which the declarations are written

Definition at line 1020 of file domain.h.

01021   {
01022     StrToFuncTemplateMap::iterator it = strToFuncTemplateMap_->begin();
01023     for (; it !=  strToFuncTemplateMap_->end(); it++)
01024     {
01025       if (!(*it).second->isInternalFunctionTemplate())
01026         out << *((*it).second) << endl;
01027     }
01028   }

int Domain::getBlock ( const Predicate *const &  pred  )  const

Returns the index of the block which a ground predicate is in.

If not in any, returns -1.

Parameters:
pred Predicate whose block is being searched for.
Returns:
Index of the block found, or -1 if none.

Definition at line 628 of file domain.cpp.

References Array< Type >::size().

Referenced by Clause::countDiffNumTrueGroundings(), and VariableState::getBlockIndex().

00629 {
00630   assert(((Predicate*)pred)->isGrounded());
00631   for (int i = 0; i < predBlocks_->size(); i++)
00632   {
00633     if ((*predBlocks_)[i]->canBeGroundedAs((Predicate*)pred))
00634       return i;
00635   }
00636   return -1;
00637 }

int Domain::getBlock ( const GroundPredicate *const &  pred  )  const

Returns the index of the block which a ground predicate is in.

If not in any, returns -1.

Parameters:
pred Predicate whose block is being searched for.
Returns:
Index of the block found, or -1 if none.

Definition at line 646 of file domain.cpp.

References Array< Type >::size().

00647 {
00648   for (int i = 0; i < predBlocks_->size(); i++)
00649   {
00650     if ((*predBlocks_)[i]->canBeGroundedAs(pred))
00651       return i;
00652   }
00653   return -1;
00654 }

const Predicate* Domain::getTruePredInBlock ( const int &  index  )  const [inline]

Caller should not delete returned Predicate.

Parameters:
index Index of the block.

Definition at line 1051 of file domain.h.

Referenced by Clause::countDiffNumTrueGroundings(), and VariableState::getTrueFixedAtomInBlock().

01052   {
01053     assert(index <= truePredsInBlock_->size());
01054     return (*truePredsInBlock_)[index];
01055   }

void Domain::setTruePredInBlock ( const int &  index,
Predicate *const &  pred 
) const [inline]

Sets the true predicate in a block.

The truth value must also be set in the database.

Parameters:
index Index of the block.
pred Predicate being set to the true one in the block.

Definition at line 1064 of file domain.h.

Referenced by VariableState::setValueOfAtom(), and HVariableState::setValueOfAtom().

01065   {
01066     assert(index <= truePredsInBlock_->size());
01067     if ((*truePredsInBlock_)[index]) delete (*truePredsInBlock_)[index];
01068     (*truePredsInBlock_)[index] = pred;
01069   }

const Predicate* Domain::getRandomPredInBlock ( const int &  index  )  const [inline]

Picks a predicate at random from a block.

Caller should delete the returned Predicate*.

Parameters:
index Index of block from which to generate the Predicate.

Definition at line 1088 of file domain.h.

References getBlockSize(), and getPredInBlock().

Referenced by MaxWalkSat::calculateImprovement(), VariableState::initBlocksRandom(), HVariableState::initBlocksRandom(), MaxWalkSat::pickRandom(), and MCMC::randomInitGndPredsTruthValues().

01089   {
01090     const int chosen = random() % getBlockSize(index);
01091     return getPredInBlock(chosen, index);
01092   }

const Predicate* Domain::getPredInBlock ( const int &  grounding,
const int &  index 
) const [inline]

Gets one ground predicate from a block.

Caller should delete the returned Predicate*.

Parameters:
grounding Index of grounding in block to generate.
index Index of block from which to generate the Predicate.

Definition at line 1101 of file domain.h.

References Array< Type >::deleteItemsAndClear(), getBlockSize(), Predicate::getGroundingNumber(), getPredBlock(), and Array< Type >::size().

Referenced by MaxWalkSat::calculateImprovement(), Clause::countDiffNumTrueGroundings(), VariableState::fixAtom(), HVariableState::fixAtom(), getIndexOfPredInBlock(), getRandomPredInBlock(), MCMC::gibbsSampleFromBlock(), SimulatedTempering::infer(), MCMC::performGibbsStep(), MaxWalkSat::pickRandom(), VariableState::setOthersInBlockToFalse(), HVariableState::setOthersInBlockToFalse(), and MCMC::setOthersInBlockToFalse().

01102   {
01103     Predicate* pred = (Predicate*)getPredBlock(index);
01104     assert(grounding <= getBlockSize(index));
01105     Array<Predicate*> predArr;
01106     pred->getGroundingNumber(this, predArr, grounding);
01107     assert(predArr.size() == 1);
01108     const Predicate* gndPred = new Predicate(*predArr[0]);
01109     predArr.deleteItemsAndClear();
01110     return gndPred;
01111   }

const int Domain::getIndexOfPredInBlock ( const Predicate *const &  pred,
const int &  blockIdx 
) const [inline]

Gets the index in a block of a predicate.

Parameters:
pred Predicate being searched for in the block.
blockIdx Index of block to search.
Returns:
Index in the block of the predicate, if present; otherwise, -1.

Definition at line 1121 of file domain.h.

References getBlockSize(), and getPredInBlock().

Referenced by Clause::countDiffNumTrueGroundings().

01123   {
01124     assert(((Predicate*)pred)->isGrounded());
01125 
01126     for (int i = 0; i < getBlockSize(blockIdx); i++)
01127     {
01128       const Predicate* predInBlock = getPredInBlock(i, blockIdx);
01129       if (((Predicate*)pred)->same((Predicate*)predInBlock))
01130       {
01131         delete predInBlock;
01132         return i;
01133       }
01134       delete predInBlock;
01135     }
01136     return -1;
01137   }


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