var DspInstance::getInfo() const { if (object != nullptr) { String info; info << "Name: " + moduleName << "\n"; info << "Parameters: " << String(object->getNumParameters()) << "\n"; for (int i = 0; i < object->getNumParameters(); i++) { const String line = String("Parameter #" + String(i) + String(": current value: ") + String(object->getParameter(i)) + String("\n")); info << line; } info << "\n"; info << "Constants: " << String(object->getNumConstants()) << "\n"; for (int i = 0; i < object->getNumConstants(); i++) { info << "Constant #" << String(i) << ": " << getConstantName(i).toString() << +" = " << getConstantValue(i).toString() << "\n"; } return var(info); } return var("No module loaded"); }
// for domain0 - postprocess void Domain::reorderConstants(MLN* const & mln) { hash_map<int,int> oldToNewConstIds; ConstDualMap* newConstDualMap = new ConstDualMap; Array<Array<int>*>* newConstantsByType = new Array<Array<int>*>; Array<Array<int>*>* newExternalConstantsByType = new Array<Array<int>*>; int prevNewConstId = -1; (void) prevNewConstId; bool constChanged = false; assert(constantsByType_->size() == externalConstantsByType_->size()); for (int i = 0; i < constantsByType_->size(); i++) { newConstantsByType->append(new Array<int>); Array<int>* constIds = (*constantsByType_)[i]; for (int j = 0; j < constIds->size(); j++) { int constId = (*constIds)[j]; const char* constName = getConstantName(constId); int newConstId = newConstDualMap->insert(constName, i); prevNewConstId = newConstId; (*newConstantsByType)[i]->append(newConstId); oldToNewConstIds[constId] = newConstId; if (constId != newConstId) constChanged = true; } newExternalConstantsByType->append(new Array<int>); Array<int>* extConstIds = (*externalConstantsByType_)[i]; for (int j = 0; j < extConstIds->size(); j++) { int constId = (*extConstIds)[j]; const char* constName = getConstantName(constId); int newConstId = newConstDualMap->insert(constName, i); prevNewConstId = newConstId; (*newExternalConstantsByType)[i]->append(newConstId); oldToNewConstIds[constId] = newConstId; if (constId != newConstId) constChanged = true; } } if (!constChanged) { delete newConstDualMap; for (int i = 0; i < newConstantsByType->size(); i++) delete (*newConstantsByType)[i]; delete newConstantsByType; for (int i = 0; i < newExternalConstantsByType->size(); i++) delete (*newExternalConstantsByType)[i]; delete newExternalConstantsByType; return; } delete constDualMap_; for (int i = 0; i < constantsByType_->size(); i++) delete (*constantsByType_)[i]; delete constantsByType_; for (int i = 0; i < externalConstantsByType_->size(); i++) delete (*externalConstantsByType_)[i]; delete externalConstantsByType_; constDualMap_ = newConstDualMap; constantsByType_ = newConstantsByType; externalConstantsByType_ = newExternalConstantsByType; constantsByType_->compress(); for (int i = 0; i < constantsByType_->size(); i++) (*constantsByType_)[i]->compress(); externalConstantsByType_->compress(); for (int i = 0; i < externalConstantsByType_->size(); i++) (*externalConstantsByType_)[i]->compress(); constDualMap_->compress(); // update updatePerOldToNewIds(mln, oldToNewConstIds); //clauses and hence their hash values have changed, and they need to be //inserted into the MLN mln->rehashClauses(); }
// for parser void Domain::reorderConstants(MLN* const & mln, hash_map<int, PredicateHashArray*>& predIdToPredsMap) { hash_map<int,int> oldToNewConstIds; ConstDualMap* newConstDualMap = new ConstDualMap; Array<Array<int>*>* newConstantsByType = new Array<Array<int>*>; Array<Array<int>*>* newExternalConstantsByType = new Array<Array<int>*>; int prevNewConstId = -1; (void) prevNewConstId; bool constChanged = false; for (int i = 0; i < constantsByType_->size(); i++) { newConstantsByType->append(new Array<int>); Array<int>* constIds = (*constantsByType_)[i]; for (int j = 0; j < constIds->size(); j++) { int constId = (*constIds)[j]; const char* constName = getConstantName(constId); int newConstId = newConstDualMap->insert(constName, i); prevNewConstId = newConstId; (*newConstantsByType)[i]->append(newConstId); oldToNewConstIds[constId] = newConstId; if (constId != newConstId) constChanged = true; } } for (int i = 0; i < externalConstantsByType_->size(); i++) { newExternalConstantsByType->append(new Array<int>); Array<int>* constIds = (*externalConstantsByType_)[i]; for (int j = 0; j < constIds->size(); j++) { int constId = (*constIds)[j]; const char* constName = getConstantName(constId); int newConstId = newConstDualMap->insert(constName, i); prevNewConstId = newConstId; (*newExternalConstantsByType)[i]->append(newConstId); oldToNewConstIds[constId] = newConstId; if (constId != newConstId) constChanged = true; } } if (!constChanged) { delete newConstDualMap; for (int i = 0; i < newConstantsByType->size(); i++) delete (*newConstantsByType)[i]; delete newConstantsByType; for (int i = 0; i < newExternalConstantsByType->size(); i++) delete (*newExternalConstantsByType)[i]; delete newExternalConstantsByType; return; } delete constDualMap_; for (int i = 0; i < constantsByType_->size(); i++) delete (*constantsByType_)[i]; delete constantsByType_; for (int i = 0; i < externalConstantsByType_->size(); i++) delete (*externalConstantsByType_)[i]; delete externalConstantsByType_; constDualMap_ = newConstDualMap; constantsByType_ = newConstantsByType; externalConstantsByType_ = newExternalConstantsByType; constantsByType_->compress(); for (int i = 0; i < constantsByType_->size(); i++) (*constantsByType_)[i]->compress(); externalConstantsByType_->compress(); for (int i = 0; i < externalConstantsByType_->size(); i++) (*externalConstantsByType_)[i]->compress(); constDualMap_->compress(); // update updatePerOldToNewIds(mln, oldToNewConstIds); // predIdToPredMap hash_map<int, PredicateHashArray*>::iterator mit = predIdToPredsMap.begin(); for (; mit != predIdToPredsMap.end(); mit++) { PredicateHashArray* pha = (*mit).second; for (int i = 0; i < pha->size(); i++ ) changePredTermsToNewIds((*pha)[i], oldToNewConstIds); } //clauses and hence their hash values have changed, and they need to be //inserted into the MLN mln->rehashClauses(); }