LWInfo Class Reference

List of all members.

Public Member Functions

 LWInfo (MLN *mln, Domain *domain)
 ~LWInfo ()
int getVarCount ()
void copyMLN ()
void setHardClauseWeight ()
void removeSoftClauses ()
void reset ()
bool isActive (int atom)
bool isDeactivated (int atom)
void setActive (int atom)
void setInactive (int atom)
void updatePredArray ()
void getSupersetClauses (Array< IntClause * > &supersetClauses)
void selectClauses (const Array< IntClause * > &supersetClauses, Array< Array< int > * > &walksatClauses, Array< int > &walksatClauseWts)
void getWalksatClauses (Predicate *inputPred, Array< Array< int > * > &walksatClauses, Array< int > &walksatClauseWts, bool const &active)
 Get clauses and weights activated by the predicate inputPred, if active is true.
void getWalksatClauses (Array< Array< int > * > &allClauses, Array< int > &allClauseWeights)
void getWalksatClausesWhenFlipped (int atom, Array< Array< int > * > &walksatClauses, Array< int > &walksatClauseWts)
int getUnSatCostPerPred (Predicate *pred, Array< Array< int > * > &walksatClauses, Array< int > &walksatClauseWts)
int getUnSatCostWhenFlipped (int atom, Array< Array< int > * > &walksatClauses, Array< int > &walksatClauseWts)
void setVarVals (int newVals[])
void flipVar (int atom)
bool getVarVal (int atom)
void setVarVal (int atom, bool val)
PredicategetVar (int atom)
void setAllActive ()
void setAllInactive ()
void setAllFalse ()
void removeVars (Array< int > indices)
void setSampleSat (bool s)
bool getSampleSat ()
void setPrevDB ()
int getNumDBAtoms ()
bool activateRandomAtom (Array< Array< int > * > &walksatClauses, Array< int > &walksatClauseWts, int &toflip)
void chooseOtherToFlip (int atom, Array< Array< int > * > &walksatClauses, Array< int > &walksatClauseWts)
void setOthersInBlockToFalse (const int &atomIdx, const int &blockIdx)
void initBlocks ()
int getBlock (int atom)
bool inBlock (int atom)
bool inBlockWithEvidence (int atom)
bool getInBlock ()
void setInBlock (const bool val)
int getOtherAtom ()
void setOtherAtom (const int val)
void setEvidence (const int atom, const bool val)
bool getEvidence (const int atom)
void incrementNumDBAtoms ()
void decrementNumDBAtoms ()
void printIntClauses (Array< IntClause * > clauses)
void propagateFixedAtoms (Array< Array< int > * > &clauses, Array< int > &clauseWeights, bool *fixedAtoms, int maxFixedAtoms)

Static Public Attributes

static double HARD_WT
static double WSCALE

Detailed Description

Definition at line 14 of file lwinfo.h.


Member Function Documentation

void LWInfo::getWalksatClauses ( Predicate inputPred,
Array< Array< int > * > &  walksatClauses,
Array< int > &  walksatClauseWts,
bool const &  active 
) [inline]

Get 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.

Definition at line 341 of file lwinfo.h.

References Array< Type >::append(), HashArray< Type, HashFn, EqualFn >::append(), Array< Type >::clear(), HashArray< Type, HashFn, EqualFn >::contains(), IntClause::deleteIntPredicates(), HashArray< Type, HashFn, EqualFn >::find(), Clause::getActiveClauses(), MLN::getClause(), MLN::getClausesContainingPred(), Domain::getDB(), Database::getDeactivatedStatus(), Predicate::getId(), Clause::getInactiveClauses(), IntClause::getIntPredicates(), MLN::getNumClauses(), IntClause::getWt(), Clause::getWt(), Clause::isHardClause(), IntClause::isSatisfied(), IntClause::setWt(), HashArray< Type, HashFn, EqualFn >::size(), Array< Type >::size(), updatePredArray(), and WSCALE.

Referenced by activateRandomAtom(), chooseOtherToFlip(), getWalksatClauses(), getWalksatClausesWhenFlipped(), propagateFixedAtoms(), and LazyWalksat::randomizeActiveAtoms().

00345 {
00346     // Randomizer
00347   int seed;
00348   struct timeval tv;
00349   struct timezone tzp;
00350   gettimeofday(&tv,&tzp);
00351   seed = (unsigned int)((( tv.tv_sec & 0177 ) * 1000000) + tv.tv_usec);
00352   srandom(seed);
00353   
00354   Clause *fclause;
00355   IntClause *intClause;
00356   int clauseCnt;
00357   IntClauseHashArray clauseHashArray;
00358 
00359   Array<IntClause *>* intClauses = new Array<IntClause *>; 
00360   
00361   const Array<IndexClause*>* indexClauses = NULL;
00362       
00363   if(inputPred == NULL)
00364   {
00365         clauseCnt = mln_->getNumClauses();
00366   }
00367   else
00368   {
00369         if (domain_->getDB()->getDeactivatedStatus(inputPred)) return;
00370         int predid = inputPred->getId(); 
00371         indexClauses = mln_->getClausesContainingPred(predid);
00372         clauseCnt = indexClauses->size();
00373   }
00374 
00375   int clauseno = 0;
00376   while(clauseno < clauseCnt)
00377   {
00378         if(inputPred)
00379           fclause = (Clause *) (*indexClauses)[clauseno]->clause;                       
00380         else
00381           fclause = (Clause *) mln_->getClause(clauseno);
00382         
00383         double wt = fclause->getWt();
00384     intClauses->clear();
00385         bool ignoreActivePreds = false;
00386 
00387     if (active)
00388     {
00389           fclause->getActiveClauses(inputPred, domain_, intClauses,
00390                                     &predHashArray_, ignoreActivePreds);
00391     }
00392     else
00393     {
00394       fclause->getInactiveClauses(inputPred, domain_, intClauses,
00395                                   &predHashArray_);
00396     }
00397     updatePredArray();
00398 cout << "intClauses size " << intClauses->size() << endl;
00399         for (int i = 0; i < intClauses->size(); i++)
00400     {
00401       intClause = (*intClauses)[i];
00402 
00403                 // If using samplesat, then do clause selection
00404           if (sampleSat_)
00405           {
00406                 assert(prevDB_);
00407 
00408                   // Pos. clause not satisfied in prev. iteration: don't activate
00409           // Neg. clause satisfied in prev. iteration: don't activate
00410         bool sat = intClause->isSatisfied(&predHashArray_, prevDB_);
00411                 if ((wt >= 0 && !sat) ||
00412             (wt < 0 && sat))
00413                 {
00414                   intClause->deleteIntPredicates();
00415                   delete intClause;
00416                   continue;
00417                 }
00418 
00419           // In dead clauses: don't activate
00420         if (deadClauses_.contains(intClause))
00421         {
00422           intClause->deleteIntPredicates();
00423           delete intClause;
00424           continue;
00425         }
00426 
00427           // With prob. exp(-wt) don't ever activate it
00428                 double threshold =
00429                   fclause->isHardClause() ? RAND_MAX : RAND_MAX*(1-exp(-abs(wt)));
00430 
00431                 if (random() > threshold)
00432                 {
00433                   deadClauses_.append(intClause);
00434                   continue;
00435                 }
00436           }
00437 
00438           int pos = clauseHashArray.find(intClause);
00439           if(pos >= 0)
00440           {
00441                 clauseHashArray[pos]->addWt(wt);
00442                 intClause->deleteIntPredicates();
00443                 delete intClause;
00444                 continue;
00445           }
00446            
00447           intClause->setWt(wt);
00448           clauseHashArray.append(intClause);
00449         }
00450         clauseno++;     
00451   } //while(clauseno < clauseCnt)
00452           
00453   Array<int>* litClause;
00454   for(int i = 0; i < clauseHashArray.size(); i++)
00455   {
00456         intClause = clauseHashArray[i];
00457         double weight = intClause->getWt();
00458         litClause = (Array<int> *)intClause->getIntPredicates();
00459         walksatClauses.append(litClause);
00460         if (sampleSat_)
00461     {
00462       if (weight >= 0) walksatClauseWts.append(1);
00463       else walksatClauseWts.append(-1);
00464     }
00465         else
00466         {
00467       if (weight >= 0)
00468         walksatClauseWts.append((int)(weight*LWInfo::WSCALE + 0.5));
00469       else
00470         walksatClauseWts.append((int)(weight*LWInfo::WSCALE - 0.5));
00471         }
00472         
00473     delete intClause;
00474   }
00475                  
00476   delete intClauses;
00477 }


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