/** * Computes the number of non-evidence atoms for each first-order predicate. */ void Domain::computeNumNonEvidAtoms() { if (numNonEvidAtomsPerPred_) delete numNonEvidAtomsPerPred_; numNonEvidAtomsPerPred_ = new Array<int>(getNumPredicates()); numNonEvidAtomsPerPred_->growToSize(getNumPredicates()); for (int i = 0; i < getNumPredicates(); i++) { (*numNonEvidAtomsPerPred_)[i] = (db_->getNumGroundings(i) - db_->getNumEvidenceGndPreds(i)); } }
size_t PredicateIndexArray::load(unsigned char *ptr, unsigned char *ptrMax, ProgressListener *listener) { size_t count = 0; bitmap = new BitSequence375(); count += bitmap->load(&ptr[count], ptrMax, listener); array = new LogSequence2(); count += array->load(&ptr[count], ptrMax, listener); #if 0 cout << "Predicate index: " << endl; // for(size_t i=0;i<array->getNumberOfElements();i++) { // cout << array->get(i) << " " << bitmap->access(i)<< endl; // } for(size_t i=1;i<=getNumPredicates();i++) { cout << "Predicate "<<i<< " first pos: " << calculatePos(i) << " occurs "<< getNumAppearances(i) << " times. "<<endl; for(size_t j=1; j<=getNumAppearances(i);j++) { size_t pos = getAppearance(i, j); cout << "\t Appearance "<< j<< " at " << pos << " => " << bitmapTriples->arrayY->get(pos) << endl; } } #endif return count; }
/* * Caller is responsible for deleting returned Predicate* if necessary */ Predicate* Domain::getNonEvidenceAtom(const int& index) const { int predId = -1; int numAtomsPerPred; int numAtoms = 0; for (int i = 0; i < getNumPredicates(); i++) { numAtomsPerPred = (*numNonEvidAtomsPerPred_)[i]; if (numAtoms + numAtomsPerPred >= index + 1) { predId = i; break; } numAtoms += numAtomsPerPred; } assert(predId >= 0); // Get the newIndex-th grounding of f.o. pred with id predId Predicate* pred = createPredicate(predId, false); // Not all groundings of pred are non-evidence, so we need the while loop bool foundNE = false; while(!foundNE) { for (int i = 0; i < pred->getNumTerms(); i++) { int termType = pred->getTermTypeAsInt(i); const Array<int>* constantsByType = getConstantsByType(termType); int constIdx = random() % constantsByType->size(); pred->setTermToConstant(i, (*constantsByType)[constIdx]); } assert(pred->isGrounded()); if (!db_->getEvidenceStatus(pred)) foundNE = true; } return pred; }
int Domain::getNumNonEvidenceAtoms() const { int numAtoms = 0; for (int i = 0; i < getNumPredicates(); i++) { numAtoms += (*numNonEvidAtomsPerPred_)[i]; } return numAtoms; }
//Caller is responsible for deleting Array and its contents void Domain::createPredicates(Array<Predicate*>* const & preds, const bool& includeEqualPreds) const { for (int i = 0; i < getNumPredicates(); i++) { Predicate* p = createPredicate(i, includeEqualPreds); if (p) preds->append(p); } }