From: Andrew Reynolds Date: Fri, 31 Jan 2020 14:51:17 +0000 (-0600) Subject: Minor refactoring of constructor classes in fast enumerator (#3685) X-Git-Tag: cvc5-1.0.0~3702 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f069ec7aee5a3433b54598defdc4af53e3573670;p=cvc5.git Minor refactoring of constructor classes in fast enumerator (#3685) --- diff --git a/src/theory/quantifiers/sygus/sygus_enumerator.cpp b/src/theory/quantifiers/sygus/sygus_enumerator.cpp index 3a79a526a..ea539cc16 100644 --- a/src/theory/quantifiers/sygus/sygus_enumerator.cpp +++ b/src/theory/quantifiers/sygus/sygus_enumerator.cpp @@ -184,9 +184,8 @@ void SygusEnumerator::TermCache::initialize(Node e, // constructor class 0 is reserved for nullary operators with 0 weight // this is an optimization so that we always skip them for sizes >= 1 - d_ccToCons[0].clear(); - d_ccToTypes[0].clear(); - d_ccToWeight[0] = 0; + ConstructorClass& ccZero = d_cclass[0]; + ccZero.d_weight = 0; d_numConClasses = 1; // we must indicate that we should process zero weight constructor classes weightsToIndices[0].clear(); @@ -216,7 +215,7 @@ void SygusEnumerator::TermCache::initialize(Node e, { if (argTypes[i].empty() && w == 0) { - d_ccToCons[0].push_back(i); + ccZero.d_cons.push_back(i); } else { @@ -241,14 +240,15 @@ void SygusEnumerator::TermCache::initialize(Node e, << dt[i].getSygusOp() << " is " << cclassi << std::endl; // initialize the constructor class - if (d_ccToWeight.find(cclassi) == d_ccToWeight.end()) + if (d_cclass.find(cclassi) == d_cclass.end()) { - d_ccToWeight[cclassi] = w; - d_ccToTypes[cclassi].insert( - d_ccToTypes[cclassi].end(), argTypes[i].begin(), argTypes[i].end()); + d_cclass[cclassi].d_weight = w; + d_cclass[cclassi].d_types.insert(d_cclass[cclassi].d_types.end(), + argTypes[i].begin(), + argTypes[i].end()); } // add to constructor class - d_ccToCons[cclassi].push_back(i); + d_cclass[cclassi].d_cons.push_back(i); } Trace("sygus-enum-debug") << "#cons classes for weight <= " << w << " : " << d_numConClasses << std::endl; @@ -274,26 +274,26 @@ unsigned SygusEnumerator::TermCache::getNumConstructorClasses() const void SygusEnumerator::TermCache::getConstructorClass( unsigned i, std::vector& cclass) const { - std::map>::const_iterator it = - d_ccToCons.find(i); - Assert(it != d_ccToCons.end()); - cclass.insert(cclass.end(), it->second.begin(), it->second.end()); + std::map::const_iterator it = d_cclass.find(i); + Assert(it != d_cclass.end()); + cclass.insert( + cclass.end(), it->second.d_cons.begin(), it->second.d_cons.end()); } void SygusEnumerator::TermCache::getTypesForConstructorClass( unsigned i, std::vector& types) const { - std::map>::const_iterator it = - d_ccToTypes.find(i); - Assert(it != d_ccToTypes.end()); - types.insert(types.end(), it->second.begin(), it->second.end()); + std::map::const_iterator it = d_cclass.find(i); + Assert(it != d_cclass.end()); + types.insert( + types.end(), it->second.d_types.begin(), it->second.d_types.end()); } unsigned SygusEnumerator::TermCache::getWeightForConstructorClass( unsigned i) const { - std::map::const_iterator it = d_ccToWeight.find(i); - Assert(it != d_ccToWeight.end()); - return it->second; + std::map::const_iterator it = d_cclass.find(i); + Assert(it != d_cclass.end()); + return it->second.d_weight; } bool SygusEnumerator::TermCache::addTerm(Node n) diff --git a/src/theory/quantifiers/sygus/sygus_enumerator.h b/src/theory/quantifiers/sygus/sygus_enumerator.h index c9d1d8fca..3f4490b15 100644 --- a/src/theory/quantifiers/sygus/sygus_enumerator.h +++ b/src/theory/quantifiers/sygus/sygus_enumerator.h @@ -156,12 +156,20 @@ class SygusEnumerator : public EnumValGenerator unsigned d_numConClasses; /** Map from weights to the starting constructor class for that weight. */ std::map d_weightToCcIndex; - /** constructor classes */ - std::map> d_ccToCons; - /** maps constructor classes to children types */ - std::map> d_ccToTypes; - /** maps constructor classes to constructor weight */ - std::map d_ccToWeight; + /** Information for each constructor class */ + class ConstructorClass + { + public: + ConstructorClass() : d_weight(0) {} + ~ConstructorClass() {} + /** The indices of the constructors in this constructor class */ + std::vector d_cons; + /** The argument types of the constructor class */ + std::vector d_types; + /** Constructor weight */ + unsigned d_weight; + }; + std::map d_cclass; /** constructor to indices */ std::map> d_cToCIndices; //-------------------------end static information about type