Database Class Reference

List of all members.

Public Member Functions

 Database (Domain *const &d, const Array< bool > &closedWorld, const bool &storeGndPreds)
 Database (const Database &db)
 ~Database ()
void compress ()
void printInfo ()
void setLazyFlag ()
void setLazyFlag (const bool &lf)
bool setPerformingInference (bool pi)
const DomaingetDomain () const
TruthValue getValue (const Predicate *const &pred) const
 Get the truth value of a predicate in this database.
TruthValue getValue (const GroundPredicate *const &pred) const
 Get the truth value of a predicate (in GroundPredicate representation) in this database.
bool getActiveStatus (const Predicate *const &pred) const
 Get the active status of a predicate in this database.
bool getActiveStatus (const GroundPredicate *const &pred) const
 Get the active status of a predicate (in GroundPredicate representation) in this database.
bool getDeactivatedStatus (const Predicate *const &pred) const
 Get the deactivated status of a predicate in this database.
bool getDeactivatedStatus (const GroundPredicate *const &pred) const
 Get the deactivated status of a predicate (in GroundPredicate representation) in this database.
bool getEvidenceStatus (const Predicate *const &pred) const
 Get the evidence status of a predicate in this database.
bool getEvidenceStatus (const GroundPredicate *const &pred) const
 Get the evidence status of a predicate (in GroundPredicate representation) in this database.
string getValueAsString (const Predicate *const &pred) const
TruthValue setValue (const Predicate *const &pred, const TruthValue &tv)
 Sets the value of a predicate in this database.
TruthValue setValue (const GroundPredicate *const &pred, const TruthValue &tv)
 Sets the value of a predicate (in GroundPredicate representation) in this database.
TruthValue flipValue (const Predicate *const &pred)
 Flips the value of a predicate in this database.
TruthValue flipValue (const GroundPredicate *const &pred)
 Flips the value of a predicate (in GroundPredicate representation) in this database.
bool setActiveStatus (const Predicate *const &pred, const bool &as)
 Sets the active status of a predicate in this database.
bool setActiveStatus (const GroundPredicate *const &pred, const bool &as)
 Sets the active status of a predicate (in GroundPredicate representation) in this database.
void resetActiveStatus ()
bool setDeactivatedStatus (const Predicate *const &pred, const bool &das)
 Sets the deactivated status of a predicate in this database.
bool setDeactivatedStatus (const GroundPredicate *const &pred, const bool &das)
 Sets the deactivated status of a predicate (in GroundPredicate representation) in this database.
void resetDeactivatedStatus ()
bool setEvidenceStatus (const Predicate *const &pred, const bool &es)
 Sets the evidence status of a predicate in this database.
bool setEvidenceStatus (const GroundPredicate *const &pred, const bool &es)
 Sets the evidence status of a predicate (in GroundPredicate representation) in this database.
void setValuesToUnknown (const Array< Predicate * > *const &gndPreds, Array< TruthValue > *const &prevValues)
void setValuesToUnknown (const GroundPredicateHashArray *const &gndPreds, Array< TruthValue > *const &prevValues)
void setValuesToGivenValues (const Array< Predicate * > *const &gndPreds, const Array< TruthValue > *const &values)
void setValuesToGivenValues (const GroundPredicateHashArray *const &gndPreds, const Array< TruthValue > *const &values)
void alterTruthValue (const Array< Predicate * > *const &gndPreds, const TruthValue &tobeAlteredVal, const TruthValue &newVal, Array< TruthValue > *const &gndPredValues)
void addEvidenceGroundPredicate (Predicate *const &pred)
int getNumGroundings (const int &predId) const
int getNumEvidenceGndPreds (const int &predId) const
int getNumTrueGndPreds (const int &predId) const
int getNumFalseGndPreds (const int &predId) const
int getNumUnknownGndPreds (const int &predId) const
int getNumPredIds () const
bool isClosedWorld (const int &predId) const
void setClosedWorld (const int &predId, const bool &b)
const Array< bool > & getClosedWorld () const
const PredicateHashArraygetTrueNonEvidenceGndPreds (const int &predId) const
void getIndexedGndings (Array< Predicate * > *const &indexedGndings, Predicate *const &pred, bool const &ignoreActivePreds)
 Retrieves indexed groundings of a predicate.

Static Public Member Functions

static bool sameTruthValueAndSense (const TruthValue &tv, const bool &sense)

Detailed Description

Definition at line 92 of file database.h.


Member Function Documentation

TruthValue Database::setValue ( const Predicate *const &  pred,
const TruthValue &  tv 
) [inline]

Sets the value of a predicate in this database.

Caller is responsible for deleting pred.

Parameters:
flip If true, value of predicate is flipped.
ttv TruthValue to which the predicate is set (This is ignored if flip is true)
Returns:
Previous value of the predicate in this database.

Definition at line 646 of file database.h.

Referenced by addEvidenceGroundPredicate(), alterTruthValue(), LWInfo::chooseOtherToFlip(), LazyInfo::chooseOtherToFlip(), Clause::countDiffNumTrueGroundings(), LWInfo::flipVar(), LazyInfo::flipVar(), LWInfo::getUnSatCostWhenFlipped(), LazyInfo::getUnSatCostWhenFlipped(), LWInfo::getWalksatClausesWhenFlipped(), LazyInfo::getWalksatClausesWhenFlipped(), LWInfo::initBlocks(), LazyInfo::initBlocks(), VariableState::saveLowStateToDB(), LWInfo::setAllFalse(), LazyInfo::setAllFalse(), LWInfo::setOthersInBlockToFalse(), LazyInfo::setOthersInBlockToFalse(), VariableState::setValueOfAtom(), setValuesToGivenValues(), setValuesToUnknown(), LWInfo::setVarVal(), LazyInfo::setVarVal(), LWInfo::setVarVals(), and LazyInfo::setVarVals().

00647   { return setValueHelper(pred, false, tv); }

TruthValue Database::setValue ( const GroundPredicate *const &  pred,
const TruthValue &  tv 
) [inline]

Sets the value of a predicate (in GroundPredicate representation) in this database.

Caller is responsible for deleting pred.

Parameters:
flip If true, value of predicate is flipped.
ttv TruthValue to which the predicate is set (This is ignored if flip is true)
Returns:
Previous value of the predicate in this database.

Definition at line 659 of file database.h.

00660   { 
00661     return setValueHelper(pred, false, tv);
00662   }

TruthValue Database::flipValue ( const Predicate *const &  pred  )  [inline]

Flips the value of a predicate in this database.

Caller is responsible for deleting pred.

Returns:
Previous value of the predicate in this database.

Definition at line 670 of file database.h.

00671   { return setValueHelper(pred, true, UNKNOWN); }

TruthValue Database::flipValue ( const GroundPredicate *const &  pred  )  [inline]

Flips the value of a predicate (in GroundPredicate representation) in this database.

Caller is responsible for deleting pred.

Returns:
Previous value of the predicate in this database.

Definition at line 679 of file database.h.

00680   { return setValueHelper(pred, true, UNKNOWN); }

bool Database::setActiveStatus ( const Predicate *const &  pred,
const bool &  as 
) [inline]

Sets the active status of a predicate in this database.

Caller is responsible for deleting pred.

Returns:
Previous active status of predicate.

Definition at line 688 of file database.h.

References getEvidenceStatus(), Predicate::getId(), and Predicate::isEqualPredWithType().

Referenced by VariableState::activateAtom(), LWInfo::activateRandomAtom(), LazyInfo::activateRandomAtom(), LWInfo::removeVars(), LazyInfo::removeVars(), LWInfo::setActive(), LazyInfo::setActive(), setActiveStatus(), LWUtil::setAllActive(), LazyUtil::setAllActive(), LWInfo::setAllInactive(), LazyInfo::setAllInactive(), LWInfo::setInactive(), LazyInfo::setInactive(), and VariableState::VariableState().

00689   { 
00690         if (dbdebug >= 1) cout << "Calling database::setActiveStatus" << endl;
00691         if (pred->isEqualPredWithType())
00692         {
00693           if (dbdebug >= 1) cout << "Returning false" << endl;
00694           return false;
00695         }
00696           // Active preds can not be evidence
00697         if (as) assert(!getEvidenceStatus(pred));
00698         
00699         assert(lazyFlag_);
00700     assert(((Predicate*)pred)->isGrounded());
00701         
00702     int predId = pred->getId();
00703     int idx = getIdxOfGndPredValues(pred);
00704     return setActiveStatus(idx, predId, as, pred, NULL);
00705   }

bool Database::setActiveStatus ( const GroundPredicate *const &  pred,
const bool &  as 
) [inline]

Sets the active status of a predicate (in GroundPredicate representation) in this database.

Caller is responsible for deleting pred.

Returns:
Previous active status of predicate.

Definition at line 713 of file database.h.

References getEvidenceStatus(), GroundPredicate::getId(), and setActiveStatus().

00714   { 
00715     if (dbdebug >= 1) cout << "Calling database::setActiveStatus" << endl;
00716       // Active preds can not be evidence
00717     if (as) assert(!getEvidenceStatus(pred));
00718     assert(lazyFlag_);
00719     
00720     int predId = pred->getId();
00721     int idx = getIdxOfGndPredValues(pred);
00722     return setActiveStatus(idx, predId, as, NULL, pred);
00723   }

bool Database::setDeactivatedStatus ( const Predicate *const &  pred,
const bool &  das 
) [inline]

Sets the deactivated status of a predicate in this database.

Caller is responsible for deleting pred.

Returns:
Previous deactivated status of predicate.

Definition at line 738 of file database.h.

References getEvidenceStatus(), Predicate::getId(), and Predicate::isEqualPredWithType().

Referenced by LWInfo::removeVars(), LazyInfo::removeVars(), and setDeactivatedStatus().

00739   { 
00740         if (dbdebug >= 1) cout << "Calling database::setDeactivatedStatus" << endl;
00741         if (pred->isEqualPredWithType())
00742         {
00743           if (dbdebug >= 1) cout << "Returning false" << endl;
00744           return false;
00745         }
00746         //deactivated preds can not be evidence
00747         if (das) assert(!getEvidenceStatus(pred));
00748         
00749         assert(lazyFlag_);
00750     assert(((Predicate*)pred)->isGrounded());
00751         
00752     int predId = pred->getId();
00753     int idx = getIdxOfGndPredValues(pred);
00754     return setDeactivatedStatus(idx, predId, das);
00755   }

bool Database::setDeactivatedStatus ( const GroundPredicate *const &  pred,
const bool &  das 
) [inline]

Sets the deactivated status of a predicate (in GroundPredicate representation) in this database.

Caller is responsible for deleting pred.

Returns:
Previous deactivated status of predicate.

Definition at line 763 of file database.h.

References getEvidenceStatus(), GroundPredicate::getId(), and setDeactivatedStatus().

00765   { 
00766     if (dbdebug >= 1) cout << "Calling database::setDeactivatedStatus" << endl;
00767       // Deactivated preds can not be evidence
00768     if (das) assert(!getEvidenceStatus(pred));
00769     assert(lazyFlag_);
00770     
00771     int predId = pred->getId();
00772     int idx = getIdxOfGndPredValues(pred);
00773     return setDeactivatedStatus(idx, predId, das);
00774   }

bool Database::setEvidenceStatus ( const Predicate *const &  pred,
const bool &  es 
) [inline]

Sets the evidence status of a predicate in this database.

Caller is responsible for deleting pred.

Returns:
Previous evidence status of predicate.

Definition at line 789 of file database.h.

References getActiveStatus(), Predicate::getId(), and Predicate::isEqualPredWithType().

Referenced by addEvidenceGroundPredicate(), LWInfo::setEvidence(), LazyInfo::setEvidence(), and setEvidenceStatus().

00790   {
00791         if (dbdebug >= 1) cout << "Calling database::setEvidenceStatus" << endl;
00792         if (pred->isEqualPredWithType())
00793         {
00794           if (dbdebug >= 1) cout << "Returning true" << endl;
00795           return true;
00796         }
00797         //active preds can not be evidence
00798         if (es) assert(!getActiveStatus(pred));
00799                                   
00800         assert(lazyFlag_);
00801     assert(((Predicate*)pred)->isGrounded());
00802 
00803     int predId = pred->getId();
00804     int idx = getIdxOfGndPredValues(pred);
00805     return setEvidenceStatus(idx, predId, es);
00806   }

bool Database::setEvidenceStatus ( const GroundPredicate *const &  pred,
const bool &  es 
) [inline]

Sets the evidence status of a predicate (in GroundPredicate representation) in this database.

Caller is responsible for deleting pred.

Returns:
Previous evidence status of predicate.

Definition at line 814 of file database.h.

References getActiveStatus(), GroundPredicate::getId(), and setEvidenceStatus().

00815   {
00816     if (dbdebug >= 1) cout << "Calling database::setEvidenceStatus" << endl;
00817       // Active preds can not be evidence
00818     if (es) assert(!getActiveStatus(pred));
00819     assert(lazyFlag_);
00820 
00821     int predId = pred->getId();
00822     int idx = getIdxOfGndPredValues(pred);
00823     return setEvidenceStatus(idx, predId, es);
00824   }

void Database::getIndexedGndings ( Array< Predicate * > *const &  indexedGndings,
Predicate *const &  pred,
bool const &  ignoreActivePreds 
) [inline]

Retrieves indexed groundings of a predicate.

The predicate must have exactly 2 terms. The indexed groundings are the true (and false and active) groundings of the (possibly partially grounded) predicate. Caller should delete indexedGndings and elements of indexedGndings, if necessary.

Parameters:
indexedGndings Groundings found are appended here.
pred Predicate whose groundings are found.
ignoreActivePreds If true, only true groundings are retrieved; otherwise, groundings which are false and active are retrieved as well.

Definition at line 1037 of file database.h.

References Array< Type >::append(), Domain::getConstantIndexInType(), Domain::getConstantsByType(), Term::getId(), Predicate::getId(), Predicate::getNumTerms(), Predicate::getTemplate(), Predicate::getTerm(), Predicate::getTermTypeAsInt(), Term::getType(), getValue(), and Array< Type >::size().

01040   {
01041     assert(pred->getNumTerms() == 2);
01042     int predId = pred->getId();
01043 
01044     const Term* term0 = pred->getTerm(0);
01045     const Term* term1 = pred->getTerm(1);
01046           
01047           // Both terms are grounded
01048     if (term0->getType() == Term::CONSTANT &&
01049         term1->getType() == Term::CONSTANT)
01050     {
01051         // Check if pred is true or, if getting active preds, active
01052       TruthValue tv = getValue(pred);
01053       if (tv == TRUE || (!ignoreActivePreds && tv == FALSE))
01054       {
01055         Predicate* p = new Predicate(*pred);
01056         indexedGndings->append(p);
01057       }
01058       return;
01059     }
01060 
01061           // Neither term is grounded
01062         if (term0->getType() != Term::CONSTANT && 
01063         term1->getType() != Term::CONSTANT)
01064         {
01065           const Array<int>* constArray =
01066             domain_->getConstantsByType(pred->getTermTypeAsInt(0));
01067         
01068                 //
01069           for (int j = 0; j < constArray->size(); j++)
01070           {
01071                 int constIdx = domain_->getConstantIndexInType((*constArray)[j]);
01072         Array<int>* preds =
01073           (*(*(*(*paramPredsArray_)[T_INDEX])[predId])[0])[constIdx];
01074         for (int i = 0; i < preds->size(); i++)
01075                 {
01076           Predicate* p = getPredFromIdx((*preds)[i], pred->getTemplate());
01077                   indexedGndings->append(p);
01078                 }
01079           }
01080         
01081           if (!ignoreActivePreds)
01082           {
01083                 for (int j = 0; j < constArray->size(); j++)
01084                 {
01085                   int constIdx = domain_->getConstantIndexInType((*constArray)[j]);
01086           Array<int>* preds =
01087             (*(*(*(*paramPredsArray_)[FA_INDEX])[predId])[0])[constIdx];
01088           for (int i = 0; i < preds->size(); i++)
01089               {
01090             Predicate* p = getPredFromIdx((*preds)[i], pred->getTemplate());
01091                         indexedGndings->append(p);
01092               }
01093                 }
01094           }     
01095           return;       
01096         }
01097           // If we've reached here, then one term is grounded, the other isn't
01098         int gndTerm = (term0->getType() == Term::CONSTANT) ? 0 : 1;
01099         int constIdx =
01100       domain_->getConstantIndexInType(pred->getTerm(gndTerm)->getId());
01101     Array<int>* preds =
01102       (*(*(*(*paramPredsArray_)[T_INDEX])[predId])[gndTerm])[constIdx];
01103     for (int i = 0; i < preds->size(); i++)
01104         {
01105       Predicate* p = getPredFromIdx((*preds)[i], pred->getTemplate());
01106           indexedGndings->append(p);
01107          }
01108           
01109         if (!ignoreActivePreds)
01110         {
01111       Array<int>* preds =
01112         (*(*(*(*paramPredsArray_)[FA_INDEX])[predId])[gndTerm])[constIdx];
01113       for (int i = 0; i < preds->size(); i++)
01114           {
01115         Predicate* p = getPredFromIdx((*preds)[i], pred->getTemplate());
01116                 indexedGndings->append(p);
01117           }
01118         }       
01119   }


The documentation for this class was generated from the following file:
Generated on Tue Jan 16 05:30:05 2007 for Alchemy by  doxygen 1.5.1