Public Member Functions | |
LazyInfo (MLN *mln, Domain *domain) | |
~LazyInfo () | |
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) |
Predicate * | getVar (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 |
Definition at line 79 of file lazyinfo.h.
void LazyInfo::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 406 of file lazyinfo.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(), and propagateFixedAtoms().
00410 { 00411 // Randomizer 00412 int seed; 00413 struct timeval tv; 00414 struct timezone tzp; 00415 gettimeofday(&tv,&tzp); 00416 seed = (unsigned int)((( tv.tv_sec & 0177 ) * 1000000) + tv.tv_usec); 00417 srandom(seed); 00418 00419 Clause *fclause; 00420 IntClause *intClause; 00421 int clauseCnt; 00422 IntClauseHashArray clauseHashArray; 00423 00424 Array<IntClause *>* intClauses = new Array<IntClause *>; 00425 00426 const Array<IndexClause*>* indexClauses = NULL; 00427 00428 if(inputPred == NULL) 00429 { 00430 clauseCnt = mln_->getNumClauses(); 00431 } 00432 else 00433 { 00434 if (domain_->getDB()->getDeactivatedStatus(inputPred)) return; 00435 int predid = inputPred->getId(); 00436 indexClauses = mln_->getClausesContainingPred(predid); 00437 clauseCnt = indexClauses->size(); 00438 } 00439 00440 int clauseno = 0; 00441 while(clauseno < clauseCnt) 00442 { 00443 if(inputPred) 00444 fclause = (Clause *) (*indexClauses)[clauseno]->clause; 00445 else 00446 fclause = (Clause *) mln_->getClause(clauseno); 00447 00448 double wt = fclause->getWt(); 00449 intClauses->clear(); 00450 bool ignoreActivePreds = false; 00451 00452 if (active) 00453 { 00454 fclause->getActiveClauses(inputPred, domain_, intClauses, 00455 &predHashArray_, ignoreActivePreds); 00456 } 00457 else 00458 { 00459 fclause->getInactiveClauses(inputPred, domain_, intClauses, 00460 &predHashArray_); 00461 } 00462 updatePredArray(); 00463 cout << "intClauses size " << intClauses->size() << endl; 00464 for (int i = 0; i < intClauses->size(); i++) 00465 { 00466 intClause = (*intClauses)[i]; 00467 00468 // If using samplesat, then do clause selection 00469 if (sampleSat_) 00470 { 00471 assert(prevDB_); 00472 00473 // Pos. clause not satisfied in prev. iteration: don't activate 00474 // Neg. clause satisfied in prev. iteration: don't activate 00475 bool sat = intClause->isSatisfied(&predHashArray_, prevDB_); 00476 if ((wt >= 0 && !sat) || 00477 (wt < 0 && sat)) 00478 { 00479 intClause->deleteIntPredicates(); 00480 delete intClause; 00481 continue; 00482 } 00483 00484 // In dead clauses: don't activate 00485 if (deadClauses_.contains(intClause)) 00486 { 00487 intClause->deleteIntPredicates(); 00488 delete intClause; 00489 continue; 00490 } 00491 00492 // With prob. exp(-wt) don't ever activate it 00493 double threshold = 00494 fclause->isHardClause() ? RAND_MAX : RAND_MAX*(1-exp(-abs(wt))); 00495 00496 if (random() > threshold) 00497 { 00498 deadClauses_.append(intClause); 00499 continue; 00500 } 00501 } 00502 00503 int pos = clauseHashArray.find(intClause); 00504 if(pos >= 0) 00505 { 00506 clauseHashArray[pos]->addWt(wt); 00507 intClause->deleteIntPredicates(); 00508 delete intClause; 00509 continue; 00510 } 00511 00512 intClause->setWt(wt); 00513 clauseHashArray.append(intClause); 00514 } 00515 clauseno++; 00516 } //while(clauseno < clauseCnt) 00517 00518 Array<int>* litClause; 00519 for(int i = 0; i < clauseHashArray.size(); i++) 00520 { 00521 intClause = clauseHashArray[i]; 00522 double weight = intClause->getWt(); 00523 litClause = (Array<int> *)intClause->getIntPredicates(); 00524 walksatClauses.append(litClause); 00525 if (sampleSat_) 00526 { 00527 if (weight >= 0) walksatClauseWts.append(1); 00528 else walksatClauseWts.append(-1); 00529 } 00530 else 00531 { 00532 if (weight >= 0) 00533 walksatClauseWts.append((int)(weight*LazyInfo::WSCALE + 0.5)); 00534 else 00535 walksatClauseWts.append((int)(weight*LazyInfo::WSCALE - 0.5)); 00536 } 00537 00538 delete intClause; 00539 } 00540 00541 delete intClauses; 00542 }