/** * The constants of this domain are replaced by new constants. The new set of * constants must be a superset of the original one. New constants are marked * as external. */ void Domain::updatePerOldToNewIds(MLN* const & mln, hash_map<int,int> & oldToNewConstIds) { //ensure that the constants in MLN clauses have the new ids const ClauseHashArray* clauses = mln->getClauses(); for (int i = 0; i < clauses->size(); i++) { Clause* c = (*clauses)[i]; for (int i = 0; i < c->getNumPredicates(); i++) changePredTermsToNewIds(c->getPredicate(i), oldToNewConstIds); } const Array<Clause*>* hclauses = mln->getHybridClauses(); for (int i = 0; i < hclauses->size(); i++) { Clause* c = (*hclauses)[i]; for (int i = 0; i < c->getNumPredicates(); i++) changePredTermsToNewIds(c->getPredicate(i), oldToNewConstIds); } // Change the const ids in the pred blocks for (int i = 0; i < predBlocks_->size(); i++) { changePredTermsToNewIds((*predBlocks_)[i], oldToNewConstIds); } for (int i = 0; i < truePredsInBlock_->size(); i++) { changePredTermsToNewIds((*truePredsInBlock_)[i], oldToNewConstIds); } // Change the const ids in the database if (db_) { db_->changeConstantsToNewIds(oldToNewConstIds); } }
//add a constant tuple to the list of constant tuples inline void Clause::addConstantTuple(const Domain* const & domain, const Database* const & db, const Clause * const & varClause, Array<int> * const & constants, Array<Variable *> * const & eqVars, ClauseToSuperClauseMap* const & clauseToSuperClause, bool useImplicit) { // used to detect duplicates PredicateSet predSet; PredicateSet::iterator iter; Predicate *predicate; Clause *clause = new Clause(); //first make sure the clause is not satisfied (because of presence of two //identical gnd preds with opposite senses) for (int i = 0; i < predicates_->size(); i++) { predicate = (*predicates_)[i]; assert(predicate->isGrounded()); /* if (db->getValue(predicate) == UNKNOWN) { clause->appendPredicate(varClause->getPredicate(i)); if ( (iter=predSet.find(predicate)) != predSet.end() ) { // the two gnd preds are of opp sense, so clause must be satisfied if ((*iter)->getSense() != predicate->getSense()) { clause->removeAllPredicates(); delete clause; return; } // since the two gnd preds are identical, no point adding a dup continue; } else predSet.insert(predicate); } */ //- this so that it matches the hypercube representation. //There is no real need to simplify the clause! if (db->getValue(predicate) == UNKNOWN) { clause->appendPredicate(varClause->getPredicate(i)); } } SuperClause *superClause; ClauseToSuperClauseMap::iterator itr; Clause *keyClause; Array<int> * varIdToCanonicalVarId; Array<int> * canonicalConstants; Array<Variable *> * canonicalEqVars; //Slightly different Imeplementation for SuperClause bool useCT = false; IntArrayHashArray *neqConstraints = NULL; //nothing to do if the clause has no predicate if (clause->getNumPredicates() == 0) { delete clause; return; } itr = clauseToSuperClause->find(clause); if (itr == clauseToSuperClause->end()) { //it is best to create a completely new copy of the clause //at this point keyClause = new Clause(*clause); keyClause->setWt(this->getWt()); keyClause->setUtil(this->getUtil()); keyClause->setAction(this->isActionFactor()); //keyClause->setWt(1); int varCnt = constants->size(); varIdToCanonicalVarId = new Array<int>(varCnt, -1); keyClause->canonicalize(varIdToCanonicalVarId); canonicalEqVars = getCanonicalArray(eqVars, varIdToCanonicalVarId); //Slightly different Imeplementation for SuperClause superClause = new SuperClause(keyClause, neqConstraints, varIdToCanonicalVarId, useCT, wt_); (*clauseToSuperClause)[clause] = superClause; delete canonicalEqVars; //delete varIdToCanonicalVarId; } else { superClause = itr->second; //sort of a hack, but it works: //may need to increase the size of varIdToCanonicalVarId map int varCnt = constants->size(); varIdToCanonicalVarId = superClause->getVarIdToCanonicalVarId(); varIdToCanonicalVarId->growToSize(varCnt,-1); //delete the clause. Predicates should not be deleted, as //they belong to the varClause clause->removeAllPredicates(); delete clause; } varIdToCanonicalVarId = superClause->getVarIdToCanonicalVarId(); canonicalConstants = getCanonicalArray(constants, varIdToCanonicalVarId); //superClause->addNewConstantsAndIncrementCount(canonicalConstants,this->getWt()); superClause->addNewConstantsAndIncrementCount(canonicalConstants,1); //clean up delete canonicalConstants; }