VariableState Class Reference

Represents the state of propositional variables and clauses. More...

#include <variablestate.h>

List of all members.

Public Member Functions

 VariableState (GroundPredicateHashArray *const &unknownQueries, GroundPredicateHashArray *const &knownQueries, Array< TruthValue > *const &knownQueryValues, const Array< int > *const &allPredGndingsAreQueries, const bool &markHardGndClauses, const bool &trackParentClauseWts, const MLN *const &mln, const Domain *const &domain, const bool &lazy)
 Constructor for a VariableState.
 ~VariableState ()
 Destructor.
void addNewClauses (bool initial)
 New clauses are added to the state.
void init ()
 Information about the state is reset and initialized.
void reinit ()
 State is re-initialized with all new clauses and atoms.
void initRandom ()
 Makes a random truth assigment to all (active) atoms.
void initBlocksRandom ()
 Sets one atom in each block to true and the rest to false.
void initMakeBreakCostWatch ()
 Re-initializes the makeCost, breakCost and watch arrays based on the current variable assignment.
void initMakeBreakCostWatch (const int &startClause)
 Initialize makeCost and breakCost and watch arrays based on the current variable assignment.
int getNumAtoms ()
int getNumClauses ()
int getNumDeadClauses ()
int getIndexOfRandomAtom ()
 Returns the absolute index of a random atom.
int getIndexOfAtomInRandomFalseClause ()
 Returns the absolute index of a random atom in a random unsatisfied pos.
int getRandomFalseClauseIndex ()
 Returns the index of a random unsatisfied pos.
long double getCostOfFalseClauses ()
 Returns the cost of the unsatisfied positive and satisfied negative clauses.
int getNumFalseClauses ()
 Returns the number of the unsatisfied positive and satisfied negative clauses.
bool getValueOfAtom (const int &atomIdx)
 Returns the truth value of an atom.
bool getValueOfLowAtom (const int &atomIdx)
 Returns the truth value of an atom in the best state.
void setValueOfAtom (const int &atomIdx, const bool &value)
 Sets the truth value of an atom.
Array< int > & getNegOccurenceArray (const int &atomIdx)
 Retrieves the negative occurence array of an atom.
Array< int > & getPosOccurenceArray (const int &atomIdx)
 Retrieves the positive occurence array of an atom.
void flipAtom (const int &toFlip)
 Flip the truth value of an atom and update info arrays.
void flipAtomValue (const int &atomIdx)
 Flips the truth value of an atom.
long double getImprovementByFlipping (const int &atomIdx)
 Calculates the improvement achieved by flipping an atom.
void activateAtom (const int &atomIdx, const bool &ignoreActivePreds)
 If in lazy mode, an atom is activated and all clauses activated by this atom are added to the state.
bool isActive (const int &atomIdx)
 Checks if an atom is active.
bool isActive (const Predicate *pred)
 Checks if an atom is active.
Array< int > & getOccurenceArray (const int &idx)
 Retrieves the occurence array of an atom.
int incrementNumTrueLits (const int &clauseIdx)
 Increments the number of true literals in a clause.
int decrementNumTrueLits (const int &clauseIdx)
 Decrements the number of true literals in a clause.
int getNumTrueLits (const int &clauseIdx)
 Retrieves the number of true literals in a clause.
long double getClauseCost (const int &clauseIdx)
 Retrieves the cost associated with a clause.
Array< int > & getAtomsInClause (const int &clauseIdx)
 Retrieves the atoms in a clauses as an Array of ints.
void addFalseClause (const int &clauseIdx)
 Marks a clause as false in the state.
void removeFalseClause (const int &clauseIdx)
 Unmarks a clause as false in the state.
void addBreakCost (const int &atomIdx, const long double &cost)
 Increases the breakcost of an atom.
void subtractBreakCost (const int &atomIdx, const long double &cost)
 Decreases the breakcost of an atom.
void addBreakCostToAtomsInClause (const int &clauseIdx, const long double &cost)
 Increases breakCost of all atoms in a given clause.
void subtractBreakCostFromAtomsInClause (const int &clauseIdx, const long double &cost)
 Decreases breakCost of all atoms in a given clause.
void addMakeCost (const int &atomIdx, const long double &cost)
 Increases makeCost of an atom.
void subtractMakeCost (const int &atomIdx, const long double &cost)
 Decreases makeCost of an atom.
void addMakeCostToAtomsInClause (const int &clauseIdx, const long double &cost)
 Increases makeCost of all atoms in a given clause.
void subtractMakeCostFromAtomsInClause (const int &clauseIdx, const long double &cost)
 Decreases makeCost of all atoms in a given clause.
const int getTrueLiteralOtherThan (const int &clauseIdx, const int &atomIdx1, const int &atomIdx2)
 Retrieves a true literal in a clause other than the two given.
const bool isTrueLiteral (const int &literal)
 Checks if a literal is true (Negated and false or non-negated an true).
const int getAtomInClause (const int &atomIdxInClause, const int &clauseIdx)
 Retrieves the absolute index of the nth atom in a clause.
const int getRandomAtomInClause (const int &clauseIdx)
 Retrieves the absolute index of a random atom in a clause.
const int getRandomTrueLitInClause (const int &clauseIdx)
 Retrieves the index of a random true literal in a clause.
const double getMaxClauseWeight ()
const long double getMakeCost (const int &atomIdx)
const long double getBreakCost (const int &atomIdx)
const int getClauseSize (const int &clauseIdx)
const int getWatch1 (const int &clauseIdx)
void setWatch1 (const int &clauseIdx, const int &atomIdx)
const int getWatch2 (const int &clauseIdx)
void setWatch2 (const int &clauseIdx, const int &atomIdx)
const bool isBlockEvidence (const int &blockIdx)
const int getBlockSize (const int &blockIdx)
const int getBlockIndex (const int &atomIdx)
 Returns the index of the block which the atom with index atomIdx is in.
Array< int > & getBlockArray (const int &blockIdx)
bool getBlockEvidence (const int &blockIdx)
int getNumBlocks ()
const long double getLowCost ()
 Returns the cost of bad clauses in the optimum state.
const int getLowBad ()
 Returns the number of bad clauses in the optimum state.
void makeUnitCosts ()
 Turns all costs into units.
void saveLowState ()
 Save current assignment as an optimum state.
int getTrueFixedAtomInBlock (const int blockIdx)
 Returns index in block if a true fixed atom is in block, otherwise -1.
const GroundPredicateHashArraygetGndPredHashArrayPtr () const
const GroundPredicateHashArraygetUnePreds () const
const GroundPredicateHashArraygetKnePreds () const
const Array< TruthValue > * getKnePredValues () const
void setGndClausesWtsToSumOfParentWts ()
 Sets the weight of a ground clause to the sum of its parents' weights.
void getNumClauseGndings (Array< double > *const &numGndings, bool tv)
 Gets the number of (true or false) clause groundings in this state.
void getNumClauseGndings (double numGndings[], int clauseCnt, bool tv)
 Gets the number of (true or false) clause groundings in this state.
void getNumClauseGndingsWithUnknown (double numGndings[], int clauseCnt, bool tv, const Array< bool > *const &unknownPred)
 Gets the number of (true or false) clause groundings in this state.
void setOthersInBlockToFalse (const int &atomIdx, const int &blockIdx)
 Sets the truth values of all atoms in a block except for the one given.
void fixAtom (const int &atomIdx, const bool &value)
 Fixes an atom to a truth value.
Array< int > * simplifyClauseFromFixedAtoms (const int &clauseIdx)
 Simplifies a clause using atoms which have been fixed.
const bool isDeadClause (const int &clauseIdx)
 Checks if a clause is dead.
void eliminateSoftClauses ()
 Marks soft clauses as dead.
void killClauses (const int &startClause)
 Marks clauses as dead which were not good in the previous iteration of inference or are not picked according to a weighted coin flip.
const bool clauseGoodInPrevious (const int &clauseIdx)
 Checks if a clause was good in the previous iteration of inference, i.e.
void resetDeadClauses ()
 Resets all dead clauses to be alive again.
void resetFixedAtoms ()
 Resets all fixed atoms to be not fixed again.
void setLazy (const bool &l)
const bool getLazy ()
void setUseThreshold (const bool &t)
const bool getUseThreshold ()
long double getHardWt ()
const DomaingetDomain ()
const MLNgetMLN ()
void printLowState (ostream &out)
 Prints the best state found to a stream.
void printGndPred (const int &predIndex, ostream &out)
 Prints a ground predicate to a stream.
void getTruePreds (vector< string > &truePreds)
 Puts the predicates set to true in the best state to a stream into a vector in string form.
void setAsEvidence (const GroundPredicate *const &predicate, const bool &trueEvidence)
 Sets a GroundPredicate to be evidence and sets its truth value.
void setAsQuery (const GroundPredicate *const &predicate)
 Sets a GroundPredicate to be query.
GroundPredicategetGndPred (const int &index)
 Gets a pointer to a GroundPredicate.
GroundClausegetGndClause (const int &index)
 Gets a pointer to a GroundClause.
void saveLowStateToGndPreds ()
 The atom assignment in the best state is saved to the ground predicates.
void saveLowStateToDB ()
 The atom assignment in the best state is saved to the database.
const int getGndPredIndex (GroundPredicate *const &gndPred)
 Gets the index of a GroundPredicate in this state.
void getActiveClauses (Predicate *inputPred, Array< GroundClause * > &activeClauses, bool const &active, bool const &ignoreActivePreds)
 Gets clauses and weights activated by the predicate inputPred, if active is true.
void getActiveClauses (Array< GroundClause * > &allClauses, bool const &ignoreActivePreds)
 Get all the active clauses in the database.
int getNumActiveAtoms ()
void addOneAtomToEachBlock ()
 Selects one atom in each block in the domain and adds it to the block here and sets it to true.
void initLazyBlocks ()
 Initializes the block structures for the lazy version.
void fillLazyBlocks ()
 Fills the blocks with the predicates in the domain blocks.


Detailed Description

Represents the state of propositional variables and clauses.

Some of this code is based on the MaxWalkSat package of Kautz et al.

All inference algorithms should have a VariableState to access the information needed in its predicates and clauses.

Each atom has its own index starting at 1. The negation of an atom with index a is represented by -a (this is why the indices do not start at 0). Each clause has its own index starting at 0.

A VariableState is either eager or lazy. Eager states build an MRF upfront based on an MLN and a domain. Thus, all ground clauses and predicates are in memory after building the MRF. Lazy states activate atoms and clauses as they are needed from the MLN and domain. An atom is activated if it is in an unsatisfied clause with the assumption of all atoms being false or if it is looked at during inference (it is flipped or the cost of flipping it is computed). Active clauses are those which contain active atoms.

Definition at line 93 of file variablestate.h.


Constructor & Destructor Documentation

VariableState::VariableState ( GroundPredicateHashArray *const &  unknownQueries,
GroundPredicateHashArray *const &  knownQueries,
Array< TruthValue > *const &  knownQueryValues,
const Array< int > *const &  allPredGndingsAreQueries,
const bool &  markHardGndClauses,
const bool &  trackParentClauseWts,
const MLN *const &  mln,
const Domain *const &  domain,
const bool &  lazy 
) [inline]

Constructor for a VariableState.

The hard clause weight is set. In lazy mode, the initial active atoms and clauses are retrieved and in eager mode, the MRF is built and the atoms and clauses are retrieved from it. In addition, all information arrays are filled with information.

Parameters:
unknownQueries Query predicates with unknown values used to build MRF in eager mode.
knownQueries Query predicates with known values used to build MRF in eager mode.
knownQueryValues Truth values of the known query predicates.
allPredGndingsAreQueries Array used to build MRF in eager mode.
mln mln and domain are used to build MRF in eager state and to retrieve active atoms in lazy state.
domain mln and domain are used to build MRF in eager state and to retrieve active atoms in lazy state.
lazy Flag stating whether lazy mode is used or not.

Definition at line 115 of file variablestate.h.

References addNewClauses(), addOneAtomToEachBlock(), HashArray< Type, HashFn, EqualFn >::append(), Array< Type >::clear(), MRF::deleteGndPredsGndClauseSets(), fillLazyBlocks(), getActiveClauses(), MRF::getBlockEvidence(), MRF::getBlocks(), Domain::getDB(), MRF::getGndClauses(), MRF::getGndPreds(), getNumClauses(), initLazyBlocks(), Database::setActiveStatus(), Database::setPerformingInference(), HashArray< Type, HashFn, EqualFn >::size(), and Array< Type >::size().

00123   {
00124     this->mln_ = (MLN*)mln;
00125     this->domain_ = (Domain*)domain;
00126     this->lazy_ = lazy;
00127 
00128       // Instantiate information
00129     baseNumAtoms_ = 0;
00130     activeAtoms_ = 0;
00131     numFalseClauses_ = 0;
00132     costOfFalseClauses_ = 0.0;
00133     lowCost_ = LDBL_MAX;
00134     lowBad_ = INT_MAX;
00135 
00136       // Clauses and preds are stored in gndClauses_ and gndPreds_
00137     gndClauses_ = new Array<GroundClause*>;
00138     gndPreds_ = new Array<GroundPredicate*>;
00139 
00140       // Set the hard clause weight
00141     setHardClauseWeight();
00142 
00143       // Lazy version: Produce state with initial active atoms and clauses
00144     if (lazy_)
00145     {
00146         // Unknown preds are treated as false
00147       domain_->getDB()->setPerformingInference(true);
00148 
00149         // Blocks are copied from the domain
00150       initLazyBlocks();
00151 
00152       clauseLimit_ = INT_MAX;
00153       noApprox_ = false;
00154       haveDeactivated_ = false;
00155 
00157         // Get initial set of active atoms (atoms in unsat. clauses)
00158         // Assumption is: all atoms are initially false except those in blocks
00159 
00160         // One atom in each block is set to true and activated
00161       addOneAtomToEachBlock();
00162 
00163 //cout << "After addOneAtomToEachBlock" << endl;
00164 //for (int i = 1; i < atom_.size(); i++)
00165 //  cout << atom_[i] << endl;
00166 
00167       bool ignoreActivePreds = false;
00168       getActiveClauses(newClauses_, ignoreActivePreds);
00169       int defaultCnt = newClauses_.size();
00170       long double defaultCost = 0;
00171 
00172       for (int i = 0; i < defaultCnt; i++)
00173       {
00174         if (newClauses_[i]->isHardClause())
00175           defaultCost += hardWt_;
00176         else
00177           defaultCost += abs(newClauses_[i]->getWt());
00178       }
00179 
00180         // Clear ground clauses in the ground preds
00181       for (int i = 0; i < gndPredHashArray_.size(); i++)
00182         gndPredHashArray_[i]->removeGndClauses();
00183 
00184         // Delete new clauses
00185       for (int i = 0; i < newClauses_.size(); i++)
00186         delete newClauses_[i];
00187       newClauses_.clear();
00188 
00189       baseNumAtoms_ = gndPredHashArray_.size();
00190       cout << "Number of Baseatoms = " << baseNumAtoms_ << endl;
00191       cout << "Default => Cost\t" << "******\t" << " Clause Cnt\t" << endl;
00192       cout << "           " << defaultCost << "\t" << "******\t" << defaultCnt
00193            << "\t" << endl << endl;
00194 
00195         // Set base atoms as active in DB
00196       for (int i = 0; i < baseNumAtoms_; i++)
00197       {
00198         domain_->getDB()->setActiveStatus(gndPredHashArray_[i], true);
00199         activeAtoms_++;        
00200       }
00201 
00202         // Add the rest of the atoms in the blocks, but don't activate
00203       fillLazyBlocks();
00204 
00205         // Get the initial set of active clauses
00206       ignoreActivePreds = false;
00207       getActiveClauses(newClauses_, ignoreActivePreds);      
00208     } // End lazy version
00209       // Eager version: Use KBMC to produce the state
00210     else
00211     {
00212       unePreds_ = unknownQueries;
00213       knePreds_ = knownQueries;
00214       knePredValues_ = knownQueryValues;
00215 
00216         // MRF is built on known and unknown queries
00217       int size = 0;
00218       if (unknownQueries) size += unknownQueries->size();
00219       if (knownQueries) size += knownQueries->size();
00220       GroundPredicateHashArray* queries = new GroundPredicateHashArray(size);
00221       if (unknownQueries) queries->append(unknownQueries);
00222       if (knownQueries) queries->append(knownQueries);
00223       mrf_ = new MRF(queries, allPredGndingsAreQueries, domain_,
00224                      domain_->getDB(), mln_, markHardGndClauses,
00225                      trackParentClauseWts, -1);
00226         //delete to save space. Can be deleted because no more gndClauses are
00227         //appended to gndPreds beyond this point
00228       mrf_->deleteGndPredsGndClauseSets();
00229         //do not delete the intArrRep in gndPreds_;
00230       delete queries;
00231 
00232         // Blocks built in MRF
00233       blocks_ = mrf_->getBlocks();
00234       blockEvidence_ = mrf_->getBlockEvidence();
00235         
00236         // Put ground clauses in newClauses_
00237       newClauses_ = *(Array<GroundClause*>*)mrf_->getGndClauses();
00238         // Put ground preds in the hash array
00239       //const Array<GroundPredicate*>* gndPreds = mrf_->getGndPreds();
00240       const GroundPredicateHashArray* gndPreds = mrf_->getGndPreds();
00241       for (int i = 0; i < gndPreds->size(); i++)
00242         gndPredHashArray_.append((*gndPreds)[i]);
00243     
00244         // baseNumAtoms_ are all atoms in eager version
00245       baseNumAtoms_ = gndPredHashArray_.size();        
00246     } // End eager version
00247     
00248       // At this point, ground clauses are held in newClauses_
00249       // and ground predicates are held in gndPredHashArray_
00250       // for both versions
00251     
00252       // Add the clauses and preds and fill info arrays
00253     bool initial = true;
00254     addNewClauses(initial);
00255     
00256     cout << "Initial num. of clauses: " << getNumClauses() << endl;
00257   }

VariableState::~VariableState (  )  [inline]

Destructor.

Blocks are deleted in lazy version; MRF is deleted in eager version.

Definition at line 263 of file variablestate.h.

References Array< Type >::size().

00264   {
00265     if (lazy_)
00266     {
00267         // Block information from lazy version is deleted
00268       for (int i = 0; i < blocks_->size(); i++)
00269         (*blocks_)[i].clearAndCompress();
00270       delete blocks_;
00271     
00272       delete blockEvidence_;  
00273     }
00274     else
00275     {
00276         // MRF from eager version is deleted
00277       if (mrf_) delete mrf_;
00278       //if (unePreds_) delete unePreds_;
00279       //if (knePreds_) delete knePreds_;
00280       //if (knePredValues_) delete knePredValues_;
00281     }    
00282   }


Member Function Documentation

void VariableState::addNewClauses ( bool  initial  )  [inline]

New clauses are added to the state.

If not the initialization, then makecost and breakcost are updated for the new atoms.

Parameters:
initial If true, this is the first time new clauses have been added.

Definition at line 292 of file variablestate.h.

References Array< Type >::append(), Array< Type >::clear(), Domain::getDB(), getNumAtoms(), getNumClauses(), Database::getValue(), Array< Type >::growToSize(), initMakeBreakCostWatch(), killClauses(), HashArray< Type, HashFn, EqualFn >::size(), and Array< Type >::size().

Referenced by activateAtom(), addOneAtomToEachBlock(), fillLazyBlocks(), reinit(), and VariableState().

00293   {
00294     if (vsdebug)
00295       cout << "Adding " << newClauses_.size() << " new clauses.." << endl;
00296 
00297       // Store the old number of clauses and atoms
00298     int oldNumClauses = getNumClauses();
00299     int oldNumAtoms = getNumAtoms();
00300 
00301     gndClauses_->append(newClauses_);
00302     gndPreds_->growToSize(gndPredHashArray_.size());
00303 
00304     int numAtoms = getNumAtoms();
00305     int numClauses = getNumClauses();
00306       // If no new atoms or clauses have been added, then do nothing
00307     if (numAtoms == oldNumAtoms && numClauses == oldNumClauses) return;
00308 
00309     if (vsdebug) cout << "Clauses: " << numClauses << endl;
00310       // atomIdx starts at 1
00311     atom_.growToSize(numAtoms + 1, false);
00312 
00313     makeCost_.growToSize(numAtoms + 1, 0.0);
00314     breakCost_.growToSize(numAtoms + 1, 0.0);
00315     lowAtom_.growToSize(numAtoms + 1, false);
00316     fixedAtom_.growToSize(numAtoms + 1, 0);
00317 
00318       // Copy ground preds to gndPreds_ and set values in atom and lowAtom
00319     for (int i = oldNumAtoms; i < gndPredHashArray_.size(); i++)
00320     {
00321       (*gndPreds_)[i] = gndPredHashArray_[i];
00322 
00323       if (vsdebug)
00324       {
00325         cout << "New pred: ";
00326         (*gndPreds_)[i]->print(cout, domain_);
00327         cout << endl;
00328       }
00329 
00330       lowAtom_[i + 1] = atom_[i + 1] = 
00331         (domain_->getDB()->getValue((*gndPreds_)[i]) == TRUE) ? true : false;
00332     }
00333     newClauses_.clear();
00334 
00335     clause_.growToSize(numClauses);
00336     clauseCost_.growToSize(numClauses);
00337     falseClause_.growToSize(numClauses);
00338     whereFalse_.growToSize(numClauses);
00339     numTrueLits_.growToSize(numClauses);
00340     watch1_.growToSize(numClauses);
00341     watch2_.growToSize(numClauses);
00342     isSatisfied_.growToSize(numClauses, false);
00343     deadClause_.growToSize(numClauses, false);
00344     threshold_.growToSize(numClauses, false);
00345 
00346     occurence_.growToSize(2*numAtoms + 1);
00347 
00348     for (int i = oldNumClauses; i < numClauses; i++)
00349     {
00350       GroundClause* gndClause = (*gndClauses_)[i];
00351 
00352       if (vsdebug)
00353       {
00354         cout << "New clause: ";
00355         gndClause->print(cout, domain_, &gndPredHashArray_);
00356         cout << endl;
00357       }
00358       
00359         // Set thresholds for clause selection
00360       if (gndClause->isHardClause()) threshold_[i] = RAND_MAX;
00361       else
00362       {
00363         double w = gndClause->getWt();
00364         threshold_[i] = RAND_MAX*(1 - exp(-abs(w)));
00365         if (vsdebug)
00366         {
00367           cout << "Weight: " << w << endl;            
00368         }
00369       }
00370       if (vsdebug)
00371         cout << "Threshold: " << threshold_[i] << endl;            
00372       
00373       int numGndPreds = gndClause->getNumGroundPredicates();
00374       clause_[i].growToSize(numGndPreds);
00375 
00376       for (int j = 0; j < numGndPreds; j++) 
00377       {
00378         int lit = gndClause->getGroundPredicateIndex(j);
00379         clause_[i][j] = lit;
00380         int litIdx = 2*abs(lit) - (lit > 0);
00381         occurence_[litIdx].append(i);
00382       }
00383 
00384         // Hard clause weight has been previously determined
00385       if (gndClause->isHardClause())
00386         clauseCost_[i] = hardWt_;
00387       else
00388         clauseCost_[i] = gndClause->getWt();
00389     }
00390 
00391     if (!initial)
00392     {
00393       //initNumSatLiterals(1, oldNumClauses);
00394       if (useThreshold_)
00395       {
00396         killClauses(oldNumClauses);
00397       }
00398       else
00399       {
00400         initMakeBreakCostWatch(oldNumClauses);
00401       }
00402     }
00403     if (vsdebug) cout << "Done adding new clauses.." << endl;
00404   }

void VariableState::initRandom (  )  [inline]

Makes a random truth assigment to all (active) atoms.

Blocks are taken into account: exactly one atom in the block is set to true and the others are set to false.

Definition at line 450 of file variablestate.h.

References getBlockIndex(), init(), initBlocksRandom(), and setValueOfAtom().

Referenced by MaxWalkSat::init().

00451   {
00452       // Set one in each block to true randomly
00453     initBlocksRandom();
00454 
00455       // Random truth value for all not in blocks
00456     for (int i = 1; i <= baseNumAtoms_; i++)
00457     {
00458         // fixedAtom_[i] = -1: false, fixedAtom_[i] = 1: true
00459       if (fixedAtom_[i] != 0) setValueOfAtom(i, (fixedAtom_[i] == 1));
00460         // Blocks are initialized above
00461       if (getBlockIndex(i - 1) >= 0)
00462       {
00463         if (vsdebug) cout << "Atom " << i << " in block" << endl;
00464         continue;
00465       }
00466         // Not fixed and not in block
00467       else
00468       {
00469         if (vsdebug) cout << "Atom " << i << " not in block" << endl;
00470         setValueOfAtom(i, random() % 2);
00471       }
00472     }
00473     init();
00474   }

void VariableState::initMakeBreakCostWatch ( const int &  startClause  )  [inline]

Initialize makeCost and breakCost and watch arrays based on the current variable assignment.

Parameters:
startClause All clauses with index of this or greater are initialized.

Definition at line 555 of file variablestate.h.

References getClauseSize(), getNumClauses(), and isTrueLiteral().

00556   {
00557     int theTrueLit = -1;
00558       // Initialize breakCost and makeCost in the following:
00559     for (int i = startClause; i < getNumClauses(); i++)
00560     {
00561         // Don't look at dead clauses
00562       if (deadClause_[i]) continue;
00563       int trueLit1 = 0;
00564       int trueLit2 = 0;
00565       long double cost = clauseCost_[i];
00566       numTrueLits_[i] = 0;
00567       for (int j = 0; j < getClauseSize(i); j++)
00568       {
00569         if (isTrueLiteral(clause_[i][j]))
00570         { // ij is true lit
00571           numTrueLits_[i]++;
00572           theTrueLit = abs(clause_[i][j]);
00573           if (!trueLit1) trueLit1 = theTrueLit;
00574           else if (trueLit1 && !trueLit2) trueLit2 = theTrueLit;
00575         }
00576       }
00577 
00578         // Unsatisfied positive-weighted clauses or
00579         // Satisfied negative-weighted clauses
00580       if ((numTrueLits_[i] == 0 && cost > 0) ||
00581           (numTrueLits_[i] > 0 && cost < 0))
00582       {
00583         whereFalse_[i] = numFalseClauses_;
00584         falseClause_[numFalseClauses_] = i;
00585         numFalseClauses_++;
00586         costOfFalseClauses_ += abs(cost);
00587         if (highestCost_ == abs(cost)) {eqHighest_ = true; numHighest_++;}
00588 
00589           // Unsat. pos. clause: increase makeCost_ of all atoms
00590         if (numTrueLits_[i] == 0)
00591           for (int j = 0; j < getClauseSize(i); j++)
00592           {
00593             makeCost_[abs(clause_[i][j])] += cost;
00594           }
00595 
00596           // Sat. neg. clause: increase makeCost_ if one true literal
00597         if (numTrueLits_[i] == 1)
00598         {
00599             // Subtract neg. cost
00600           makeCost_[theTrueLit] -= cost;
00601           watch1_[i] = theTrueLit;
00602         }
00603         else if (numTrueLits_[i] > 1)
00604         {
00605           watch1_[i] = trueLit1;
00606           watch2_[i] = trueLit2;
00607         }
00608       }
00609         // Pos. clauses satisfied by one true literal
00610       else if (numTrueLits_[i] == 1 && cost > 0)
00611       {
00612         breakCost_[theTrueLit] += cost;
00613         watch1_[i] = theTrueLit;
00614       }
00615         // Pos. clauses satisfied by 2 or more true literals
00616       else if (cost > 0)
00617       { /*if (numtruelit[i] == 2)*/
00618         watch1_[i] = trueLit1;
00619         watch2_[i] = trueLit2;
00620       }
00621         // Unsat. neg. clauses: increase breakCost of all atoms
00622       else if (numTrueLits_[i] == 0 && cost < 0)
00623       {
00624         for (int j = 0; j < getClauseSize(i); j++)
00625           breakCost_[abs(clause_[i][j])] -= cost;
00626       }
00627     } // for all clauses
00628   }

int VariableState::getIndexOfAtomInRandomFalseClause (  )  [inline]

Returns the absolute index of a random atom in a random unsatisfied pos.

clause or the absolute index of a random true literal in a random satisfied clause.

Definition at line 657 of file variablestate.h.

References getClauseSize(), and getRandomTrueLitInClause().

Referenced by MaxWalkSat::pickRandom().

00658   {
00659     if (numFalseClauses_ == 0) return NOVALUE;
00660     int clauseIdx = falseClause_[random()%numFalseClauses_];
00661       // Pos. clause: return index of random atom
00662     if (clauseCost_[clauseIdx] > 0)
00663       return abs(clause_[clauseIdx][random()%getClauseSize(clauseIdx)]);
00664       // Neg. clause: find random true lit
00665     else
00666       return getRandomTrueLitInClause(clauseIdx);
00667   }

int VariableState::getRandomFalseClauseIndex (  )  [inline]

Returns the index of a random unsatisfied pos.

clause or a random satisfied neg. clause.

Definition at line 673 of file variablestate.h.

Referenced by MaxWalkSat::pickBest(), and MaxWalkSat::pickTabu().

00674   {
00675     if (numFalseClauses_ == 0) return NOVALUE;
00676     return falseClause_[random()%numFalseClauses_];
00677   }

bool VariableState::getValueOfAtom ( const int &  atomIdx  )  [inline]

Returns the truth value of an atom.

Index of atom whose truth value is returned.

Returns:
Truth value of atom.

Definition at line 703 of file variablestate.h.

Referenced by MaxWalkSat::calculateImprovement(), flipAtom(), and MaxWalkSat::pickRandom().

00704   {
00705     return atom_[atomIdx];
00706   }

bool VariableState::getValueOfLowAtom ( const int &  atomIdx  )  [inline]

Returns the truth value of an atom in the best state.

Index of atom whose truth value is returned.

Returns:
Truth value of atom.

Definition at line 714 of file variablestate.h.

Referenced by UnitPropagation::getPredsWithNonZeroProb(), SAT::getPredsWithNonZeroProb(), UnitPropagation::getProbability(), SAT::getProbability(), getTruePreds(), UnitPropagation::printProbabilities(), SAT::printProbabilities(), UnitPropagation::printTruePreds(), SAT::printTruePreds(), and MCMC::saveLowStateToChain().

00715   {
00716     return lowAtom_[atomIdx];
00717   }

void VariableState::setValueOfAtom ( const int &  atomIdx,
const bool &  value 
) [inline]

Sets the truth value of an atom.

The truth value is propagated to the database.

Parameters:
atomIdx Index of atom whose value is to be set.
value Truth value being set.

Definition at line 726 of file variablestate.h.

References activateAtom(), Domain::getDB(), isActive(), and Database::setValue().

Referenced by addOneAtomToEachBlock(), fixAtom(), flipAtomValue(), initBlocksRandom(), initRandom(), and setOthersInBlockToFalse().

00727   {
00728     if (vsdebug) cout << "Setting value of atom " << atomIdx 
00729                       << " to " << value << endl;
00730       // If atom already has this value, then do nothing
00731     if (atom_[atomIdx] == value) return;
00732       // Propagate assigment to DB
00733     GroundPredicate* p = gndPredHashArray_[atomIdx - 1];
00734     if (value)
00735     {
00736       domain_->getDB()->setValue(p, TRUE);
00737     }
00738     else
00739     {
00740       domain_->getDB()->setValue(p, FALSE);
00741     }
00742       // If not active, then activate it
00743     if (lazy_ && !isActive(atomIdx))
00744     {
00745       bool ignoreActivePreds = false;
00746       activateAtom(atomIdx, ignoreActivePreds);
00747     }
00748     atom_[atomIdx] = value;
00749   }

void VariableState::flipAtom ( const int &  toFlip  )  [inline]

Flip the truth value of an atom and update info arrays.

Parameters:
toFlip Index of atom to be flipped.

Definition at line 774 of file variablestate.h.

References addBreakCost(), addBreakCostToAtomsInClause(), addFalseClause(), addMakeCost(), addMakeCostToAtomsInClause(), decrementNumTrueLits(), flipAtomValue(), getClauseCost(), getOccurenceArray(), getTrueLiteralOtherThan(), getValueOfAtom(), getWatch1(), getWatch2(), incrementNumTrueLits(), removeFalseClause(), setWatch1(), setWatch2(), and Array< Type >::size().

Referenced by MaxWalkSat::flipAtom(), and getImprovementByFlipping().

00775   {
00776     bool toFlipValue = getValueOfAtom(toFlip);
00777     register int clauseIdx;
00778     int sign;
00779     int oppSign;
00780     int litIdx;
00781     if (toFlipValue)
00782       sign = 1;
00783     else
00784       sign = 0;
00785     oppSign = sign ^ 1;
00786 
00787     flipAtomValue(toFlip);
00788     
00789       // Update all clauses in which the atom occurs as a true literal
00790     litIdx = 2*toFlip - sign;
00791     Array<int>& posOccArray = getOccurenceArray(litIdx);
00792     for (int i = 0; i < posOccArray.size(); i++)
00793     {
00794       clauseIdx = posOccArray[i];
00795         // Don't look at dead clauses
00796       if (deadClause_[clauseIdx]) continue;
00797         // The true lit became a false lit
00798       int numTrueLits = decrementNumTrueLits(clauseIdx);
00799       long double cost = getClauseCost(clauseIdx);
00800       int watch1 = getWatch1(clauseIdx);
00801       int watch2 = getWatch2(clauseIdx);
00802 
00803         // 1. If last true lit was flipped, then we have to update
00804         // the makecost / breakcost info accordingly        
00805       if (numTrueLits == 0)
00806       {
00807           // Pos. clause
00808         if (cost > 0)
00809         {
00810             // Add this clause as false in the state
00811           addFalseClause(clauseIdx);
00812             // Decrease toFlip's breakcost (add neg. cost)
00813           addBreakCost(toFlip, -cost);
00814             // Increase makecost of all vars in clause (add pos. cost)
00815           addMakeCostToAtomsInClause(clauseIdx, cost);
00816         }
00817           // Neg. clause
00818         else
00819         {
00820           assert(cost < 0);
00821             // Remove this clause as false in the state
00822           removeFalseClause(clauseIdx);
00823             // Increase breakcost of all vars in clause (add pos. cost)
00824           addBreakCostToAtomsInClause(clauseIdx, -cost);        
00825             // Decrease toFlip's makecost (add neg. cost)
00826           addMakeCost(toFlip, cost);
00827         }
00828       }
00829         // 2. If there is now one true lit left, then move watch2
00830         // up to watch1 and increase the breakcost / makecost of watch1
00831       else if (numTrueLits == 1)
00832       {
00833         if (watch1 == toFlip)
00834         {
00835           assert(watch1 != watch2);
00836           setWatch1(clauseIdx, watch2);
00837           watch1 = getWatch1(clauseIdx);
00838         }
00839 
00840           // Pos. clause: Increase toFlip's breakcost (add pos. cost)
00841         if (cost > 0)
00842         {
00843           addBreakCost(watch1, cost);
00844         }
00845           // Neg. clause: Increase toFlip's makecost (add pos. cost)
00846         else
00847         {
00848           assert(cost < 0);
00849           addMakeCost(watch1, -cost);
00850         }
00851       }
00852         // 3. If there are 2 or more true lits left, then we have to
00853         // find a new true lit to watch if one was flipped
00854       else
00855       { /* numtruelit[clauseIdx] >= 2 */
00856           // If watch1[clauseIdx] has been flipped
00857         if (watch1 == toFlip)
00858         {
00859             // find a different true literal to watch
00860           int diffTrueLit = getTrueLiteralOtherThan(clauseIdx, watch1, watch2);
00861           setWatch1(clauseIdx, diffTrueLit);
00862         }
00863           // If watch2[clauseIdx] has been flipped
00864         else if (watch2 == toFlip)
00865         {
00866             // find a different true literal to watch
00867           int diffTrueLit = getTrueLiteralOtherThan(clauseIdx, watch1, watch2);
00868           setWatch2(clauseIdx, diffTrueLit);
00869         }
00870       }
00871     }
00872         
00873       // Update all clauses in which the atom occurs as a false literal
00874     litIdx = 2*toFlip - oppSign;
00875     Array<int>& negOccArray = getOccurenceArray(litIdx);
00876     for (int i = 0; i < negOccArray.size(); i++)
00877     {
00878       clauseIdx = negOccArray[i];
00879         // Don't look at dead clauses
00880       if (deadClause_[clauseIdx]) continue;
00881         // The false lit became a true lit
00882       int numTrueLits = incrementNumTrueLits(clauseIdx);
00883       long double cost = getClauseCost(clauseIdx);
00884       int watch1 = getWatch1(clauseIdx);
00885 
00886         // 1. If this is the only true lit, then we have to update
00887         // the makecost / breakcost info accordingly        
00888       if (numTrueLits == 1)
00889       {
00890           // Pos. clause
00891         if (cost > 0)
00892         {
00893             // Remove this clause as false in the state
00894           removeFalseClause(clauseIdx);
00895             // Increase toFlip's breakcost (add pos. cost)
00896           addBreakCost(toFlip, cost);        
00897             // Decrease makecost of all vars in clause (add neg. cost)
00898           addMakeCostToAtomsInClause(clauseIdx, -cost);
00899         }
00900           // Neg. clause
00901         else
00902         {
00903           assert(cost < 0);
00904             // Add this clause as false in the state
00905           addFalseClause(clauseIdx);
00906             // Decrease breakcost of all vars in clause (add neg. cost)
00907           addBreakCostToAtomsInClause(clauseIdx, cost);
00908             // Increase toFlip's makecost (add pos. cost)
00909           addMakeCost(toFlip, -cost);
00910         }
00911           // Watch this atom
00912         setWatch1(clauseIdx, toFlip);
00913       }
00914         // 2. If there are now exactly 2 true lits, then watch second atom
00915         // and update breakcost
00916       else
00917       if (numTrueLits == 2)
00918       {
00919         if (cost > 0)
00920         {
00921             // Pos. clause
00922             // Decrease breakcost of first atom being watched (add neg. cost)
00923           addBreakCost(watch1, -cost);
00924         }
00925         else
00926         {
00927             // Neg. clause
00928           assert(cost < 0);
00929             // Decrease makecost of first atom being watched (add neg. cost)
00930           addMakeCost(watch1, cost);
00931         }
00932         
00933           // Watch second atom
00934         setWatch2(clauseIdx, toFlip);
00935       }
00936     }
00937   }

void VariableState::flipAtomValue ( const int &  atomIdx  )  [inline]

Flips the truth value of an atom.

If in lazy mode, the truth value is propagated to the database.

Definition at line 943 of file variablestate.h.

References setValueOfAtom().

Referenced by flipAtom(), and MaxWalkSat::reconstructLowState().

00944   {
00945     bool opposite = !atom_[atomIdx];
00946     setValueOfAtom(atomIdx, opposite);
00947   }

long double VariableState::getImprovementByFlipping ( const int &  atomIdx  )  [inline]

Calculates the improvement achieved by flipping an atom.

This is the cost of clauses which flipping the atom makes good minus the cost of clauses which flipping the atom makes bad. In lazy mode, if the atom is not active, then the atom is activated and the makecost and breakcost are updated.

Parameters:
atomIdx Index of atom to flip.
Returns:
Improvement achieved by flipping the atom.

Definition at line 960 of file variablestate.h.

References flipAtom(), and isActive().

Referenced by MaxWalkSat::calculateImprovement().

00961   {
00962     if (lazy_ && !isActive(atomIdx))
00963     {
00964         // First flip the atom to activate it, then flip it back
00965       flipAtom(atomIdx);
00966       flipAtom(atomIdx);
00967     }
00968     long double improvement = makeCost_[atomIdx] - breakCost_[atomIdx];
00969     return improvement;
00970   }

void VariableState::activateAtom ( const int &  atomIdx,
const bool &  ignoreActivePreds 
) [inline]

If in lazy mode, an atom is activated and all clauses activated by this atom are added to the state.

If in eager mode, nothing happens.

Parameters:
atomIdx Index of atom to be activated.

Definition at line 978 of file variablestate.h.

References addNewClauses(), getActiveClauses(), Domain::getDB(), isActive(), and Database::setActiveStatus().

Referenced by setValueOfAtom().

00979   {
00980       // Lazy version: if atom is not active, we need to activate clauses
00981       // and take their cost into account
00982     if (lazy_ && !isActive(atomIdx))
00983     {
00984       Predicate* p =
00985         gndPredHashArray_[atomIdx - 1]->createEquivalentPredicate(domain_);
00986       getActiveClauses(p, newClauses_, true, ignoreActivePreds);
00987         // Add the clauses and preds and fill info arrays
00988       bool initial = false;
00989       addNewClauses(initial);
00990         // Set active status in db
00991       domain_->getDB()->setActiveStatus(p, true);
00992       activeAtoms_++;
00993       delete p;
00994     }        
00995   }

bool VariableState::isActive ( const int &  atomIdx  )  [inline]

Checks if an atom is active.

Parameters:
atomIdx Index of atom to be checked.
Returns:
true, if atom is active, otherwise false.

Definition at line 1003 of file variablestate.h.

References Database::getActiveStatus(), and Domain::getDB().

Referenced by activateAtom(), getImprovementByFlipping(), and setValueOfAtom().

01004   {
01005     return domain_->getDB()->getActiveStatus(gndPredHashArray_[atomIdx-1]);
01006   }

bool VariableState::isActive ( const Predicate pred  )  [inline]

Checks if an atom is active.

Parameters:
pred Predicate to be checked.
Returns:
true, if atom is active, otherwise false.

Definition at line 1014 of file variablestate.h.

References Database::getActiveStatus(), and Domain::getDB().

01015   {
01016     return domain_->getDB()->getActiveStatus(pred);
01017   }

void VariableState::addBreakCostToAtomsInClause ( const int &  clauseIdx,
const long double &  cost 
) [inline]

Increases breakCost of all atoms in a given clause.

Parameters:
clauseIdx Index of clause whose atoms' breakCost is altered.
cost Cost to be added to atoms' breakCost.

Definition at line 1111 of file variablestate.h.

References getClauseSize().

Referenced by flipAtom().

01113   {
01114     register int size = getClauseSize(clauseIdx);
01115     for (int i = 0; i < size; i++)
01116     {
01117       register int lit = clause_[clauseIdx][i];
01118       breakCost_[abs(lit)] += cost;
01119     }
01120   }

void VariableState::subtractBreakCostFromAtomsInClause ( const int &  clauseIdx,
const long double &  cost 
) [inline]

Decreases breakCost of all atoms in a given clause.

Parameters:
clauseIdx Index of clause whose atoms' breakCost is altered.
cost Cost to be subtracted from atoms' breakCost.

Definition at line 1128 of file variablestate.h.

References getClauseSize().

01130   {
01131     register int size = getClauseSize(clauseIdx);
01132     for (int i = 0; i < size; i++)
01133     {
01134       register int lit = clause_[clauseIdx][i];
01135       breakCost_[abs(lit)] -= cost;
01136     }
01137   }

void VariableState::addMakeCost ( const int &  atomIdx,
const long double &  cost 
) [inline]

Increases makeCost of an atom.

Parameters:
atomIdx Index of atom whose makeCost is altered.
cost Cost to be added to atom's makeCost.

Definition at line 1145 of file variablestate.h.

Referenced by flipAtom().

01146   {
01147     makeCost_[atomIdx] += cost;
01148   }

void VariableState::subtractMakeCost ( const int &  atomIdx,
const long double &  cost 
) [inline]

Decreases makeCost of an atom.

Parameters:
atomIdx Index of atom whose makeCost is altered.
cost Cost to be subtracted from atom's makeCost.

Definition at line 1156 of file variablestate.h.

01157   {
01158     makeCost_[atomIdx] -= cost;
01159   }

void VariableState::addMakeCostToAtomsInClause ( const int &  clauseIdx,
const long double &  cost 
) [inline]

Increases makeCost of all atoms in a given clause.

Parameters:
clauseIdx Index of clause whose atoms' makeCost is altered.
cost Cost to be added to atoms' makeCost.

Definition at line 1167 of file variablestate.h.

References getClauseSize().

Referenced by flipAtom().

01169   {
01170     register int size = getClauseSize(clauseIdx);
01171     for (int i = 0; i < size; i++)
01172     {
01173       register int lit = clause_[clauseIdx][i];
01174       makeCost_[abs(lit)] += cost;
01175     }
01176   }

void VariableState::subtractMakeCostFromAtomsInClause ( const int &  clauseIdx,
const long double &  cost 
) [inline]

Decreases makeCost of all atoms in a given clause.

Parameters:
clauseIdx Index of clause whose atoms' makeCost is altered.
cost Cost to be subtracted from atoms' makeCost.

Definition at line 1184 of file variablestate.h.

References getClauseSize().

01186   {
01187     register int size = getClauseSize(clauseIdx);
01188     for (int i = 0; i < size; i++)
01189     {
01190       register int lit = clause_[clauseIdx][i];
01191       makeCost_[abs(lit)] -= cost;
01192     }
01193   }

const int VariableState::getTrueLiteralOtherThan ( const int &  clauseIdx,
const int &  atomIdx1,
const int &  atomIdx2 
) [inline]

Retrieves a true literal in a clause other than the two given.

Parameters:
clauseIdx Index of clause from which literal is retrieved.
atomIdx1 Index of first atom excluded from search.
atomIdx2 Index of second atom excluded from search.
Returns:
Index of atom found.

Definition at line 1204 of file variablestate.h.

References getClauseSize(), and isTrueLiteral().

Referenced by flipAtom().

01207   {
01208     register int size = getClauseSize(clauseIdx);
01209     for (int i = 0; i < size; i++)
01210     {
01211       register int lit = clause_[clauseIdx][i];
01212       register int v = abs(lit);
01213       if (isTrueLiteral(lit) && v != atomIdx1 && v != atomIdx2)
01214         return v;
01215     }
01216       // If we're here, then no other true lit exists
01217     assert(false);
01218     return -1;
01219   }

const int VariableState::getRandomTrueLitInClause ( const int &  clauseIdx  )  [inline]

Retrieves the index of a random true literal in a clause.

Parameters:
clauseIdx Index of clause from which the literal is retrieved.
Returns:
Index of the atom retrieved.

Definition at line 1251 of file variablestate.h.

References getClauseSize(), and isTrueLiteral().

Referenced by getIndexOfAtomInRandomFalseClause(), and MaxWalkSat::pickBest().

01252   {
01253     assert(numTrueLits_[clauseIdx] > 0);
01254     int trueLit = random()%numTrueLits_[clauseIdx];
01255     int whichTrueLit = 0;
01256     for (int i = 0; i < getClauseSize(clauseIdx); i++)
01257     {
01258       int lit = clause_[clauseIdx][i];
01259       int atm = abs(lit);
01260         // True literal
01261       if (isTrueLiteral(lit))
01262         if (trueLit == whichTrueLit++)
01263           return atm;
01264     }
01265       // If we're here, then no other true lit exists
01266     assert(false);
01267     return -1;
01268   }

const int VariableState::getBlockIndex ( const int &  atomIdx  )  [inline]

Returns the index of the block which the atom with index atomIdx is in.

If not in any, returns -1.

Definition at line 1334 of file variablestate.h.

References Array< Type >::size().

Referenced by MaxWalkSat::calculateImprovement(), SimulatedTempering::infer(), initRandom(), MCMC::performGibbsStep(), MaxWalkSat::pickRandom(), and MCMC::randomInitGndPredsTruthValues().

01335   {
01336     for (int i = 0; i < blocks_->size(); i++)
01337     {
01338       int blockIdx = (*blocks_)[i].find(atomIdx);
01339       if (blockIdx >= 0)
01340         return i;
01341     }
01342     return -1;
01343   }

void VariableState::makeUnitCosts (  )  [inline]

Turns all costs into units.

Positive costs are converted to 1, negative costs are converted to -1

Definition at line 1380 of file variablestate.h.

References initMakeBreakCostWatch(), and Array< Type >::size().

Referenced by MCSAT::init().

01381   {
01382     for (int i = 0; i < clauseCost_.size(); i++)
01383     {
01384       if (clauseCost_[i] > 0) clauseCost_[i] = 1.0;
01385       else
01386       {
01387         assert(clauseCost_[i] < 0);
01388         clauseCost_[i] = -1.0;
01389       }
01390     }
01391     if (vsdebug) cout << "Made unit costs" << endl;
01392     initMakeBreakCostWatch();
01393   }

void VariableState::getNumClauseGndings ( Array< double > *const &  numGndings,
bool  tv 
) [inline]

Gets the number of (true or false) clause groundings in this state.

If eager, the first order clause frequencies in the mrf are used.

Parameters:
numGndings Array being filled with values
clauseCnt 
tv 

Definition at line 1478 of file variablestate.h.

References MLN::getNumClauses(), isTrueLiteral(), and Array< Type >::size().

Referenced by SimulatedTempering::infer(), MaxWalkSat::infer(), and MCMC::performGibbsStep().

01479   {
01480     // TODO: lazy version
01481     IntPairItr itr;
01482     IntPair *clauseFrequencies;
01483     
01484       // numGndings should have been initialized with non-negative values
01485     int clauseCnt = numGndings->size();
01486     assert(clauseCnt == mln_->getNumClauses());
01487     for (int clauseno = 0; clauseno < clauseCnt; clauseno++)
01488       assert ((*numGndings)[clauseno] >= 0);
01489     
01490     for (int i = 0; i < gndClauses_->size(); i++)
01491     {
01492       GroundClause *gndClause = (*gndClauses_)[i];
01493       int satLitcnt = 0;
01494       for (int j = 0; j < gndClause->getNumGroundPredicates(); j++)
01495       {
01496         int lit = gndClause->getGroundPredicateIndex(j);
01497         if (isTrueLiteral(lit)) satLitcnt++;
01498       }
01499       //int satLitcnt = getNumTrueLits(i);
01500       if (tv && satLitcnt == 0)
01501         continue;
01502       if (!tv && satLitcnt > 0)
01503         continue;
01504 
01505       clauseFrequencies = gndClause->getClauseFrequencies();
01506       for (itr = clauseFrequencies->begin();
01507            itr != clauseFrequencies->end(); itr++)
01508       {
01509         int clauseno = itr->first;
01510         int frequency = itr->second;
01511         (*numGndings)[clauseno] += frequency;
01512       }
01513     }
01514   }

void VariableState::getNumClauseGndings ( double  numGndings[],
int  clauseCnt,
bool  tv 
) [inline]

Gets the number of (true or false) clause groundings in this state.

If eager, the first order clause frequencies in the mrf are used.

Parameters:
numGndings 
clauseCnt 
tv 

Definition at line 1524 of file variablestate.h.

References getNumTrueLits(), and Array< Type >::size().

01525   {
01526     // TODO: lazy version
01527     IntPairItr itr;
01528     IntPair *clauseFrequencies;
01529     
01530     for (int clauseno = 0; clauseno < clauseCnt; clauseno++)
01531       numGndings[clauseno] = 0;
01532     
01533     for (int i = 0; i < gndClauses_->size(); i++)
01534     {
01535       GroundClause *gndClause = (*gndClauses_)[i];
01536       int satLitcnt = getNumTrueLits(i);
01537       if (tv && satLitcnt == 0)
01538         continue;
01539       if (!tv && satLitcnt > 0)
01540         continue;
01541 
01542       clauseFrequencies = gndClause->getClauseFrequencies();
01543       for (itr = clauseFrequencies->begin();
01544            itr != clauseFrequencies->end(); itr++)
01545       {
01546         int clauseno = itr->first;
01547         int frequency = itr->second;
01548         numGndings[clauseno] += frequency;
01549       }
01550     }
01551   }

void VariableState::getNumClauseGndingsWithUnknown ( double  numGndings[],
int  clauseCnt,
bool  tv,
const Array< bool > *const &  unknownPred 
) [inline]

Gets the number of (true or false) clause groundings in this state.

If eager, the first order clause frequencies in the mrf are used.

Parameters:
numGndings Will hold the number of groundings for each first-order clause.
clauseCnt Number of first-order clauses whose groundings are being counted.
tv If true, true groundings are counted, otherwise false groundings.
unknownPred If pred is marked as unknown, it is ignored in the count

Definition at line 1564 of file variablestate.h.

References getNumAtoms(), isTrueLiteral(), and Array< Type >::size().

01567   {
01568     assert(unknownPred->size() == getNumAtoms());
01569     IntPairItr itr;
01570     IntPair *clauseFrequencies;
01571     
01572     for (int clauseno = 0; clauseno < clauseCnt; clauseno++)
01573       numGndings[clauseno] = 0;
01574     
01575     for (int i = 0; i < gndClauses_->size(); i++)
01576     {
01577       GroundClause *gndClause = (*gndClauses_)[i];
01578       int satLitcnt = 0;
01579       bool unknown = false;
01580       for (int j = 0; j < gndClause->getNumGroundPredicates(); j++)
01581       {
01582         int lit = gndClause->getGroundPredicateIndex(j);
01583         if ((*unknownPred)[abs(lit) - 1])
01584         {
01585           unknown = true;
01586           continue;
01587         }
01588         if (isTrueLiteral(lit)) satLitcnt++;
01589       }
01590       
01591       if (tv && satLitcnt == 0)
01592         continue;
01593       if (!tv && (satLitcnt > 0 || unknown))
01594         continue;
01595 
01596       clauseFrequencies = gndClause->getClauseFrequencies();
01597       for (itr = clauseFrequencies->begin();
01598            itr != clauseFrequencies->end(); itr++)
01599       {
01600         int clauseno = itr->first;
01601         int frequency = itr->second;
01602         numGndings[clauseno] += frequency;
01603       }
01604     }
01605   }

void VariableState::setOthersInBlockToFalse ( const int &  atomIdx,
const int &  blockIdx 
) [inline]

Sets the truth values of all atoms in a block except for the one given.

Parameters:
atomIdx Index of atom in block exempt from being set to false.
blockIdx Index of block whose atoms are set to false.

Definition at line 1613 of file variablestate.h.

References setValueOfAtom(), and Array< Type >::size().

Referenced by addOneAtomToEachBlock(), and initBlocksRandom().

01615   {
01616     Array<int>& block = (*blocks_)[blockIdx];
01617     for (int i = 0; i < block.size(); i++)
01618     {
01619         // Atom not the one specified and not fixed
01620       if (i != atomIdx && fixedAtom_[block[i] + 1] == 0)
01621         setValueOfAtom(block[i] + 1, false);
01622     }
01623   }

void VariableState::fixAtom ( const int &  atomIdx,
const bool &  value 
) [inline]

Fixes an atom to a truth value.

This means the atom can not change its truth values again. If the atom has already been fixed to the opposite value, then we have a contradiction and the program terminates.

Parameters:
atomIdx Index of atom to be fixed.
value Truth value to which the atom is fixed.

Definition at line 1634 of file variablestate.h.

References setValueOfAtom().

Referenced by UnitPropagation::infer().

01635   {
01636     assert(atomIdx > 0);
01637       // If already fixed to opp. sense, then contradiction
01638     if ((fixedAtom_[atomIdx] == 1 && value == false) ||
01639         (fixedAtom_[atomIdx] == -1 && value == true))
01640     {
01641       cout << "Contradiction: Tried to fix atom " << atomIdx <<
01642       " to true and false ... exiting." << endl;
01643       exit(0);
01644     }
01645 
01646     if (vsdebug)
01647     {
01648       cout << "Fixing ";
01649       (*gndPreds_)[atomIdx - 1]->print(cout, domain_);
01650       cout << " to " << value << endl;
01651     }
01652     
01653     setValueOfAtom(atomIdx, value);
01654     fixedAtom_[atomIdx] = (value) ? 1 : -1;
01655   }

Array<int>* VariableState::simplifyClauseFromFixedAtoms ( const int &  clauseIdx  )  [inline]

Simplifies a clause using atoms which have been fixed.

If clause is satisfied from the fixed atoms, this is marked in isSatisfied_ and an empty array is returned. If clause is empty and not satisfied, then a contradiction has occured. Otherwise, the simplified clause is returned.

Returned array should be deleted.

Parameters:
clauseIdx Index of the clause to be simplified
Returns:
Simplified clause

Definition at line 1668 of file variablestate.h.

References Array< Type >::append(), Array< Type >::clear(), and getClauseSize().

Referenced by UnitPropagation::infer().

01669   {
01670     Array<int>* returnArray = new Array<int>;
01671       // If already satisfied from fixed atoms, then return empty array
01672     if (isSatisfied_[clauseIdx]) return returnArray;
01673 
01674       // Keeps track of pos. clause being satisfied or 
01675       // neg. clause being unsatisfied due to fixed atoms
01676     bool isGood = (clauseCost_[clauseIdx] > 0) ? false : true;
01677       // Keeps track of all atoms being fixed to false in a pos. clause
01678     bool allFalseAtoms = (clauseCost_[clauseIdx] > 0) ? true : false;
01679       // Check each literal in clause
01680     for (int i = 0; i < getClauseSize(clauseIdx); i++)
01681     {
01682       int lit = clause_[clauseIdx][i];
01683       int fixedValue = fixedAtom_[abs(lit)];
01684 
01685       if (clauseCost_[clauseIdx] > 0)
01686       { // Pos. clause: check if clause is satisfied
01687         if ((fixedValue == 1 && lit > 0) ||
01688             (fixedValue == -1 && lit < 0))
01689         { // True fixed lit
01690           isGood = true;
01691           allFalseAtoms = false;
01692           returnArray->clear();
01693           break;
01694         }
01695         else if (fixedValue == 0)
01696         { // Lit not fixed
01697           allFalseAtoms = false;
01698           returnArray->append(lit);
01699         }
01700       }
01701       else
01702       { // Neg. clause:
01703         assert(clauseCost_[clauseIdx] < 0);
01704         if ((fixedValue == 1 && lit > 0) ||
01705             (fixedValue == -1 && lit < 0))
01706         { // True fixed lit
01707           cout << "Contradiction: Tried to fix atom " << abs(lit) <<
01708           " to true in a negative clause ... exiting." << endl;
01709           exit(0);
01710         }
01711         else
01712         { // False fixed lit or non-fixed lit
01713           returnArray->append(lit);
01714             // Non-fixed lit
01715           if (fixedValue == 0) isGood = false;          
01716         }
01717       }
01718     }
01719     if (allFalseAtoms)
01720     {
01721       cout << "Contradiction: All atoms in clause " << clauseIdx <<
01722       " fixed to false ... exiting." << endl;
01723       exit(0);
01724     }
01725     if (isGood) isSatisfied_[clauseIdx] = true;
01726     return returnArray;
01727   }

const bool VariableState::isDeadClause ( const int &  clauseIdx  )  [inline]

Checks if a clause is dead.

Parameters:
clauseIdx Index of clause being checked.
Returns:
True, if clause is dead, otherwise false.

Definition at line 1735 of file variablestate.h.

Referenced by UnitPropagation::infer().

01736   {
01737     return deadClause_[clauseIdx];
01738   }

void VariableState::killClauses ( const int &  startClause  )  [inline]

Marks clauses as dead which were not good in the previous iteration of inference or are not picked according to a weighted coin flip.

Parameters:
startClause All clauses with index of this or greater are looked at to be killed.

Definition at line 1764 of file variablestate.h.

References clauseGoodInPrevious(), getNumClauses(), and initMakeBreakCostWatch().

Referenced by addNewClauses().

01765   {
01766     for (int i = startClause; i < getNumClauses(); i++)
01767     {
01768       GroundClause* clause = (*gndClauses_)[i];
01769       if ((clauseGoodInPrevious(i)) &&
01770           (clause->isHardClause() || random() <= threshold_[i]))
01771       {
01772         if (vsdebug)
01773         {
01774           cout << "Keeping clause "<< i << " ";
01775           clause->print(cout, domain_, &gndPredHashArray_);
01776           cout << endl;
01777         }
01778         deadClause_[i] = false;
01779       }
01780       else
01781       {
01782         deadClause_[i] = true;
01783       }
01784     }
01785     initMakeBreakCostWatch();
01786   }

const bool VariableState::clauseGoodInPrevious ( const int &  clauseIdx  )  [inline]

Checks if a clause was good in the previous iteration of inference, i.e.

if it is positive and satisfied or negative and unsatisfied.

Parameters:
clauseIdx Index of clause being checked.
Returns:
true, if clause was good, otherwise false.

Definition at line 1796 of file variablestate.h.

Referenced by killClauses().

01797   {
01798     //GroundClause* clause = (*gndClauses_)[clauseIdx];
01799     int numSatLits = numTrueLits_[clauseIdx];
01800       // Num. of satisfied lits in previous iteration is stored in clause
01801     if ((numSatLits > 0 && clauseCost_[clauseIdx] > 0.0) ||
01802         (numSatLits == 0 && clauseCost_[clauseIdx] < 0.0))
01803       return true;
01804     else
01805       return false;
01806   }

void VariableState::printLowState ( ostream &  out  )  [inline]

Prints the best state found to a stream.

Parameters:
out Stream to which the state is printed.

Definition at line 1846 of file variablestate.h.

References getNumAtoms().

Referenced by MCSAT::init().

01847   {
01848     for (int i = 0; i < getNumAtoms(); i++)
01849     {
01850       (*gndPreds_)[i]->print(out, domain_);
01851       out << " " << lowAtom_[i + 1] << endl;
01852     }
01853   }

void VariableState::printGndPred ( const int &  predIndex,
ostream &  out 
) [inline]

Prints a ground predicate to a stream.

Parameters:
predIndex Index of predicate to be printed.
out Stream to which predicate is printed.

Definition at line 1861 of file variablestate.h.

Referenced by UnitPropagation::getPredsWithNonZeroProb(), SAT::getPredsWithNonZeroProb(), MCMC::getPredsWithNonZeroProb(), getTruePreds(), UnitPropagation::printProbabilities(), SAT::printProbabilities(), MCMC::printProbabilities(), UnitPropagation::printTruePreds(), SAT::printTruePreds(), and MCMC::printTruePreds().

01862   {
01863     (*gndPreds_)[predIndex]->print(out, domain_);
01864   }

void VariableState::getTruePreds ( vector< string > &  truePreds  )  [inline]

Puts the predicates set to true in the best state to a stream into a vector in string form.

Parameters:
truePreds vector being filled with true predicates

Definition at line 1872 of file variablestate.h.

References getNumAtoms(), getValueOfLowAtom(), and printGndPred().

01873   {
01874     truePreds.clear();
01875     for (int i = 0; i < getNumAtoms(); i++)
01876     {
01877       if (getValueOfLowAtom(i + 1))
01878       {
01879         ostringstream oss(ostringstream::out);
01880         printGndPred(i, oss);
01881         truePreds.push_back(oss.str());
01882       }
01883     }
01884   }

void VariableState::setAsEvidence ( const GroundPredicate *const &  predicate,
const bool &  trueEvidence 
) [inline]

Sets a GroundPredicate to be evidence and sets its truth value.

If it is already present as evidence with the given truth value, then nothing happens. If the predicate was a query, then additional clauses may be eliminated. reinit() should be called after this in order to ensure that the clause and atom information is correct.

Parameters:
predicate GroundPredicate to be set as evidence.
trueEvidence The truth value of the predicate is set to this.

Definition at line 1896 of file variablestate.h.

References Array< Type >::compress(), HashArray< Type, HashFn, EqualFn >::compress(), HashArray< Type, HashFn, EqualFn >::find(), Domain::getDB(), getNegOccurenceArray(), getPosOccurenceArray(), Database::getValue(), GroundPredicate::print(), Array< Type >::removeAllNull(), Array< Type >::removeItemFastDisorder(), HashArray< Type, HashFn, EqualFn >::removeItemFastDisorder(), Database::setValue(), HashArray< Type, HashFn, EqualFn >::size(), and Array< Type >::size().

01898   {
01899     if (vsdebug)
01900     {
01901       cout << "Setting to evidence " ;
01902       predicate->print(cout, domain_);
01903       cout << endl;
01904     }
01905     Database* db = domain_->getDB();
01906     int atomIdx = gndPredHashArray_.find((GroundPredicate*)predicate);
01907       // If already evidence, then check its truth value
01908     if (atomIdx <= 0)
01909     {
01910         // If predicate already evidence with same truth value, then do nothing
01911       if (db->getValue(predicate) == trueEvidence)
01912         return;
01913         
01914         // Changing truth value of evidence
01915       if (trueEvidence)
01916         db->setValue(predicate, TRUE);
01917       else
01918         db->setValue(predicate, FALSE);
01919     }
01920     else
01921     {
01922       Array<int> gndClauseIndexes;      
01923       gndClauseIndexes = getNegOccurenceArray(atomIdx + 1);
01924       for (int i = 0; i < gndClauseIndexes.size(); i++)
01925       {
01926           // Atom appears neg. in these clauses, so remove the atom from
01927           // these clauses if true evidence, or remove clause if false evidence
01928           // or a unit clause
01929         if (!trueEvidence ||
01930             (*gndClauses_)[gndClauseIndexes[i]]->getNumGroundPredicates() == 1)
01931         {          
01932           if (vsdebug)
01933             cout << "Deleting ground clause " << gndClauseIndexes[i] << endl;
01934           delete (*gndClauses_)[gndClauseIndexes[i]];
01935           (*gndClauses_)[gndClauseIndexes[i]] = NULL;
01936         }
01937         else
01938         {
01939           if (vsdebug)
01940           {
01941             cout << "Removing gnd pred " << -(atomIdx + 1)
01942                  << " from ground clause " << gndClauseIndexes[i] << endl;
01943           }
01944           (*gndClauses_)[gndClauseIndexes[i]]->removeGndPred(-(atomIdx + 1));
01945         }
01946       }
01947 
01948       gndClauseIndexes = getPosOccurenceArray(atomIdx + 1);
01949       for (int i = 0; i < gndClauseIndexes.size(); i++)
01950       {
01951           // Atom appears pos. in these clauses, so remove the atom from
01952           // these clauses if false evidence, or remove clause if true evidence
01953           // or a unit clause
01954         if (trueEvidence ||
01955             (*gndClauses_)[gndClauseIndexes[i]]->getNumGroundPredicates() == 1)
01956         {
01957           if (vsdebug)
01958             cout << "Deleting ground clause " << gndClauseIndexes[i] << endl;
01959           delete (*gndClauses_)[gndClauseIndexes[i]];
01960           (*gndClauses_)[gndClauseIndexes[i]] = NULL;
01961         }
01962         else
01963         {
01964           if (vsdebug)
01965           {
01966             cout << "Removing gnd pred " << -(atomIdx + 1)
01967                  << " from ground clause " << gndClauseIndexes[i] << endl;
01968           }
01969           (*gndClauses_)[gndClauseIndexes[i]]->removeGndPred(atomIdx + 1);
01970         }
01971       }
01972       
01973       gndPredHashArray_.removeItemFastDisorder(atomIdx);
01974       gndPredHashArray_.compress();
01975       gndPreds_->removeItemFastDisorder(atomIdx);
01976       gndPreds_->compress();
01977         // By removing a pred, the pred at the end of the array gets the
01978         // index of the pred deleted, so we have to update to the new index
01979         // in all clauses
01980       int oldIdx = gndPredHashArray_.size();
01981       replaceAtomIndexInAllClauses(oldIdx, atomIdx);      
01982       gndClauses_->removeAllNull();
01983     }
01984   }

void VariableState::setAsQuery ( const GroundPredicate *const &  predicate  )  [inline]

Sets a GroundPredicate to be query.

If it is already present as query, then nothing happens. If the predicate was evidence, then additional clauses may be added. reinit() should be called after this in order to ensure that the clause and atom information is correct.

Parameters:
predicate GroundPredicate to be set as a query.

Definition at line 1994 of file variablestate.h.

References HashArray< Type, HashFn, EqualFn >::append(), HashArray< Type, HashFn, EqualFn >::contains(), getActiveClauses(), Domain::getDB(), GroundPredicate::print(), and Database::setEvidenceStatus().

01995   {
01996     if (vsdebug)
01997     {
01998       cout << "Setting to query " ;
01999       predicate->print(cout, domain_);
02000       cout << endl;
02001     }
02002     Database* db = domain_->getDB();
02003       // If already non-evidence, then do nothing
02004     if (gndPredHashArray_.contains((GroundPredicate*)predicate))
02005       return;
02006     else
02007     {
02008         // Evidence -> query
02009         // Add predicate to query set and get clauses
02010       gndPredHashArray_.append((GroundPredicate*)predicate);
02011       Predicate* p = predicate->createEquivalentPredicate(domain_);
02012       db->setEvidenceStatus(p, false);
02013       bool ignoreActivePreds = true;
02014       getActiveClauses(p, newClauses_, true, ignoreActivePreds);
02015     }
02016   }

GroundPredicate* VariableState::getGndPred ( const int &  index  )  [inline]

Gets a pointer to a GroundPredicate.

Parameters:
index Index of the GroundPredicate to be retrieved.
Returns:
Pointer to the GroundPredicate

Definition at line 2026 of file variablestate.h.

Referenced by MCMC::getProbabilityOfPred(), MCMC::gndPredFlippedUpdates(), SimulatedTempering::infer(), MCSAT::infer(), GibbsSampler::infer(), and MCMC::performGibbsStep().

02027   {
02028     return (*gndPreds_)[index];
02029   }

GroundClause* VariableState::getGndClause ( const int &  index  )  [inline]

Gets a pointer to a GroundClause.

Parameters:
index Index of the GroundClause to be retrieved.
Returns:
Pointer to the GroundClause

Definition at line 2037 of file variablestate.h.

Referenced by MCMC::gndPredFlippedUpdates(), MCMC::initNumTrueLits(), and MCMC::updateWtsForGndPreds().

02038   {
02039     return (*gndClauses_)[index];
02040   }

const int VariableState::getGndPredIndex ( GroundPredicate *const &  gndPred  )  [inline]

Gets the index of a GroundPredicate in this state.

Parameters:
gndPred GroundPredicate whose index is being found.
Returns:
Index of the GroundPredicate, if found; otherwise -1.

Definition at line 2077 of file variablestate.h.

References Array< Type >::find().

Referenced by UnitPropagation::getProbability(), SAT::getProbability(), and MCMC::getProbability().

02078   {
02079     return gndPreds_->find(gndPred);
02080   }

void VariableState::getActiveClauses ( Predicate inputPred,
Array< GroundClause * > &  activeClauses,
bool const &  active,
bool const &  ignoreActivePreds 
) [inline]

Gets clauses and weights activated by the predicate inputPred, if active is true.

If false, inactive clauses (and their weights) containing inputPred are retrieved. If inputPred is NULL, then all active (or inactive) clauses and their weights are retrieved.

Parameters:
inputPred Only clauses containing this Predicate are looked at. If NULL, then all active clauses are retrieved.
activeClauses New active clauses are put here.
active If true, active clauses are retrieved, otherwise inactive.
ignoreActivePreds If true, active preds are not taken into account. This results in the retrieval of all unsatisfied clauses.

Definition at line 2101 of file variablestate.h.

References Array< Type >::append(), HashArray< Type, HashFn, EqualFn >::append(), GroundClause::appendParentWtPtr(), GroundClause::appendToGndPreds(), Array< Type >::clear(), HashArray< Type, HashFn, EqualFn >::find(), MLN::findClauseIdx(), Clause::getActiveClauses(), MLN::getClause(), MLN::getClausesContainingPred(), Domain::getDB(), Database::getDeactivatedStatus(), Predicate::getId(), MLN::getNumClauses(), GroundClause::getWt(), Clause::getWt(), Clause::getWtPtr(), GroundClause::incrementClauseFrequency(), Clause::isHardClause(), GroundClause::print(), Clause::print(), GroundClause::setWt(), HashArray< Type, HashFn, EqualFn >::size(), and Array< Type >::size().

Referenced by activateAtom(), getActiveClauses(), setAsQuery(), and VariableState().

02105   {
02106     Clause *fclause;
02107     GroundClause* newClause;
02108     int clauseCnt;
02109     GroundClauseHashArray clauseHashArray;
02110 
02111     Array<GroundClause*>* newClauses = new Array<GroundClause*>; 
02112   
02113     const Array<IndexClause*>* indexClauses = NULL;
02114       
02115       // inputPred is null: all active clauses should be retrieved
02116     if (inputPred == NULL)
02117     {
02118       clauseCnt = mln_->getNumClauses();
02119     }
02120       // Otherwise, look at all first order clauses containing the pred
02121     else
02122     {
02123       if (domain_->getDB()->getDeactivatedStatus(inputPred)) return;
02124       int predId = inputPred->getId();
02125       indexClauses = mln_->getClausesContainingPred(predId);
02126       clauseCnt = indexClauses->size();
02127     }
02128 
02129       // Look at each first-order clause and get active groundings
02130     int clauseno = 0;
02131     while (clauseno < clauseCnt)
02132     {
02133       if (inputPred)
02134         fclause = (Clause *) (*indexClauses)[clauseno]->clause;           
02135       else
02136         fclause = (Clause *) mln_->getClause(clauseno);
02137 
02138       if (vsdebug)
02139       {
02140         cout << "Getting active clauses for FO clause: ";
02141         fclause->print(cout, domain_);
02142         cout << endl;
02143       }
02144       
02145       long double wt = fclause->getWt();
02146       const double* parentWtPtr = NULL;
02147       if (!fclause->isHardClause()) parentWtPtr = fclause->getWtPtr();
02148       const int clauseId = mln_->findClauseIdx(fclause);
02149       newClauses->clear();
02150 
02151       fclause->getActiveClauses(inputPred, domain_, newClauses,
02152                                 &gndPredHashArray_, ignoreActivePreds);
02153 
02154       for (int i = 0; i < newClauses->size(); i++)
02155       {
02156         newClause = (*newClauses)[i];
02157         int pos = clauseHashArray.find(newClause);
02158           // If clause already present, then just add weight
02159         if (pos >= 0)
02160         {
02161           if (vsdebug)
02162           {
02163             cout << "Adding weight " << wt << " to clause ";
02164             clauseHashArray[pos]->print(cout, domain_, &gndPredHashArray_);
02165             cout << endl;
02166           }
02167           clauseHashArray[pos]->addWt(wt);
02168           if (parentWtPtr)
02169           {
02170             clauseHashArray[pos]->appendParentWtPtr(parentWtPtr);
02171             clauseHashArray[pos]->incrementClauseFrequency(clauseId, 1);
02172           }
02173           delete newClause;
02174           continue;
02175         }
02176 
02177           // If here, then clause is not yet present        
02178         newClause->setWt(wt);
02179         newClause->appendToGndPreds(&gndPredHashArray_);
02180         if (parentWtPtr)
02181         {
02182           newClause->appendParentWtPtr(parentWtPtr);
02183           newClause->incrementClauseFrequency(clauseId, 1);
02184           assert(newClause->getWt() == *parentWtPtr);
02185         }      
02186 
02187         if (vsdebug)
02188         {
02189           cout << "Appending clause ";
02190           newClause->print(cout, domain_, &gndPredHashArray_);
02191           cout << endl;
02192         }
02193         clauseHashArray.append(newClause);
02194       }
02195       clauseno++; 
02196     } //while (clauseno < clauseCnt)
02197 
02198     for (int i = 0; i < clauseHashArray.size(); i++)
02199     {
02200       newClause = clauseHashArray[i];
02201       activeClauses.append(newClause);
02202     }
02203     delete newClauses;
02204   }

void VariableState::getActiveClauses ( Array< GroundClause * > &  allClauses,
bool const &  ignoreActivePreds 
) [inline]

Get all the active clauses in the database.

Parameters:
allClauses Active clauses are retrieved into this Array.
ignoreActivePreds If true, active preds are ignored; this means all unsatisfied clauses are retrieved.

Definition at line 2213 of file variablestate.h.

References getActiveClauses().

02215   {
02216     getActiveClauses(NULL, allClauses, true, ignoreActivePreds);
02217   }


The documentation for this class was generated from the following file:
Generated on Wed Feb 14 15:15:22 2007 for Alchemy by  doxygen 1.5.1