// count sort - asc // input: 0 ~ MAX_INTEGER std::vector<unsigned int> countSort(std::vector<unsigned int> inArr) { int size = inArr.size(); if (size <= 1) return inArr; unsigned int maxValue=inArr[0], minValue = inArr[0]; for(int i=1; i<size; ++i) { if(maxValue < inArr[i]) maxValue = inArr[i]; if(minValue > inArr[i]) minValue = inArr[i]; } std::vector<unsigned int> tmpArr(maxValue+1); for(int i=0; i<size; ++i) tmpArr[inArr[i]] += 1; std::vector<unsigned int> result; for(int i=minValue; i<int(tmpArr.size()); ++i) { int count = tmpArr[i]; while(count > 0) { result.push_back(i); --count; } } return result; }
void LiftedAlgsConvertor::addEvidence(vector<vector<int> >& evidenceIntRep) { set<int> completedIds; for(int i=0;i<mln_->getNumClauses();i++) { for(int j=0;j<mln_->getClause(i)->getNumPredicates();j++) { if(completedIds.count(mln_->getClause(i)->getPredicate(j)->getId()) == 0) { completedIds.insert(mln_->getClause(i)->getPredicate(j)->getId()); Array<Predicate*>* indexedGndings = new Array<Predicate*>(); domain_->getDB()->getTrueGndings(mln_->getClause(i)->getPredicate(j)->getId() ,indexedGndings); for(int k=0;k<indexedGndings->size();k++) { GroundPredicate* gpTmp = new GroundPredicate((*indexedGndings)[k]); vector<int> tmpArr(gpTmp->getIntArrRep()->size()); for(unsigned int jj=0;jj<tmpArr.size();jj++) tmpArr[jj] = (*gpTmp->getIntArrRep())[jj]; evidenceIntRep.push_back(tmpArr); PredicateSymbol* ps = createPredicateSymbol((*indexedGndings)[k]); vector<LvrTerm*> atomTerms((*indexedGndings)[k]->getNumTerms()); for (int termno = 0; termno < (*indexedGndings)[k]->getNumTerms(); termno++) { vector<int> domValues(1); const Term* term = (*indexedGndings)[k]->getTerm(termno); domValues[0] = term->getId(); LvrTerm* lvrTerm = new LvrTerm(0,domValues); atomTerms[termno]=lvrTerm; } Atom* atom = new Atom(ps,atomTerms); WClause* nClause = new WClause(); nClause->atoms.push_back(atom); nClause->sign.push_back(false); lvrMln->clauses.push_back(nClause); //evidenceAtoms.push_back(atom); } } } } }