diff options
author | Andrew Reynolds <andrew.j.reynolds@gmail.com> | 2020-10-16 13:32:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-16 13:32:42 -0500 |
commit | 7c249b3efdeeb51fd3dfc2571bc529c55880cf5c (patch) | |
tree | 220a1c3f2aa53b047c2a52260fce3bd2dce22429 /src/theory | |
parent | 547df7cd146091674562dfa4812f10bae7765934 (diff) |
Refactor SMT-level model object (#5277)
This refactors the SMT-level model object so that it is a wrapper around TheoryModel instead of a base class. This inheritance was unnecessary.
Moreover, it removes the virtual base models of the SMT-level model which were based on Expr. Now the interface is more minimal and in terms of Node only.
This PR further simplifies a few places in the code that interface with the SmtEngine with things related to models.
Diffstat (limited to 'src/theory')
-rw-r--r-- | src/theory/theory_model.cpp | 87 | ||||
-rw-r--r-- | src/theory/theory_model.h | 25 | ||||
-rw-r--r-- | src/theory/theory_model_builder.cpp | 7 | ||||
-rw-r--r-- | src/theory/theory_model_builder.h | 2 |
4 files changed, 43 insertions, 78 deletions
diff --git a/src/theory/theory_model.cpp b/src/theory/theory_model.cpp index b8cbdf6b3..f240d5113 100644 --- a/src/theory/theory_model.cpp +++ b/src/theory/theory_model.cpp @@ -109,48 +109,27 @@ bool TheoryModel::getHeapModel(Node& h, Node& neq) const return true; } -bool TheoryModel::getHeapModel( Expr& h, Expr& neq ) const { - if( d_sep_heap.isNull() || d_sep_nil_eq.isNull() ){ - return false; - }else{ - h = d_sep_heap.toExpr(); - neq = d_sep_nil_eq.toExpr(); - return true; - } -} - bool TheoryModel::hasApproximations() const { return !d_approx_list.empty(); } -std::vector<std::pair<Expr, Expr> > TheoryModel::getApproximations() const +std::vector<std::pair<Node, Node> > TheoryModel::getApproximations() const { - std::vector<std::pair<Expr, Expr> > approx; - for (const std::pair<Node, Node>& ap : d_approx_list) - { - approx.push_back( - std::pair<Expr, Expr>(ap.first.toExpr(), ap.second.toExpr())); - } - return approx; + return d_approx_list; } -std::vector<Expr> TheoryModel::getDomainElements(Type t) const +std::vector<Node> TheoryModel::getDomainElements(TypeNode tn) const { // must be an uninterpreted sort - Assert(t.isSort()); - std::vector<Expr> elements; - TypeNode tn = TypeNode::fromType(t); + Assert(tn.isSort()); + std::vector<Node> elements; const std::vector<Node>* type_refs = d_rep_set.getTypeRepsOrNull(tn); if (type_refs == nullptr || type_refs->empty()) { // This is called when t is a sort that does not occur in this model. // Sorts are always interpreted as non-empty, thus we add a single element. - elements.push_back(t.mkGroundTerm()); + elements.push_back(tn.mkGroundTerm()); return elements; } - for (const Node& n : *type_refs) - { - elements.push_back(n.toExpr()); - } - return elements; + return *type_refs; } Node TheoryModel::getValue(TNode n) const @@ -170,39 +149,35 @@ Node TheoryModel::getValue(TNode n) const return nn; } -bool TheoryModel::isModelCoreSymbol(Expr sym) const +bool TheoryModel::isModelCoreSymbol(Node s) const { if (!d_using_model_core) { return true; } - Node s = Node::fromExpr(sym); Assert(s.isVar() && s.getKind() != BOUND_VARIABLE); return d_model_core.find(s) != d_model_core.end(); } -Expr TheoryModel::getValue( Expr expr ) const{ - Node n = Node::fromExpr( expr ); - Node ret = getValue( n ); - return ret.toExpr(); -} - -/** get cardinality for sort */ -Cardinality TheoryModel::getCardinality( Type t ) const{ - TypeNode tn = TypeNode::fromType( t ); +Cardinality TheoryModel::getCardinality(TypeNode tn) const +{ //for now, we only handle cardinalities for uninterpreted sorts - if( tn.isSort() ){ - if( d_rep_set.hasType( tn ) ){ - Debug("model-getvalue-debug") << "Get cardinality sort, #rep : " << d_rep_set.getNumRepresentatives( tn ) << std::endl; - return Cardinality( d_rep_set.getNumRepresentatives( tn ) ); - }else{ - Debug("model-getvalue-debug") << "Get cardinality sort, unconstrained, return 1." << std::endl; - return Cardinality( 1 ); - } - }else{ - Debug("model-getvalue-debug") << "Get cardinality other sort, unknown." << std::endl; + if (!tn.isSort()) + { + Debug("model-getvalue-debug") + << "Get cardinality other sort, unknown." << std::endl; return Cardinality( CardinalityUnknown() ); } + if (d_rep_set.hasType(tn)) + { + Debug("model-getvalue-debug") + << "Get cardinality sort, #rep : " + << d_rep_set.getNumRepresentatives(tn) << std::endl; + return Cardinality(d_rep_set.getNumRepresentatives(tn)); + } + Debug("model-getvalue-debug") + << "Get cardinality sort, unconstrained, return 1." << std::endl; + return Cardinality(1); } Node TheoryModel::getModelValue(TNode n) const @@ -258,16 +233,15 @@ Node TheoryModel::getModelValue(TNode n) const { Debug("model-getvalue-debug") << "get cardinality constraint " << ret[0].getType() << std::endl; - ret = nm->mkConst( - getCardinality(ret[0].getType().toType()).getFiniteCardinality() - <= ret[1].getConst<Rational>().getNumerator()); + ret = nm->mkConst(getCardinality(ret[0].getType()).getFiniteCardinality() + <= ret[1].getConst<Rational>().getNumerator()); } else if (ret.getKind() == kind::CARDINALITY_VALUE) { Debug("model-getvalue-debug") << "get cardinality value " << ret[0].getType() << std::endl; - ret = nm->mkConst(Rational( - getCardinality(ret[0].getType().toType()).getFiniteCardinality())); + ret = nm->mkConst( + Rational(getCardinality(ret[0].getType()).getFiniteCardinality())); } d_modelCache[n] = ret; return ret; @@ -621,10 +595,7 @@ void TheoryModel::setUsingModelCore() d_model_core.clear(); } -void TheoryModel::recordModelCoreSymbol(Expr sym) -{ - d_model_core.insert(Node::fromExpr(sym)); -} +void TheoryModel::recordModelCoreSymbol(Node sym) { d_model_core.insert(sym); } void TheoryModel::setUnevaluatedKind(Kind k) { d_unevaluated_kinds.insert(k); } diff --git a/src/theory/theory_model.h b/src/theory/theory_model.h index 9f330ff6c..e8665bb83 100644 --- a/src/theory/theory_model.h +++ b/src/theory/theory_model.h @@ -20,7 +20,6 @@ #include <unordered_map> #include <unordered_set> -#include "smt/model.h" #include "theory/ee_setup_info.h" #include "theory/rep_set.h" #include "theory/substitutions.h" @@ -76,12 +75,12 @@ namespace theory { * above functions such as getRepresentative() when assigning total * interpretations for uninterpreted functions. */ -class TheoryModel : public Model +class TheoryModel { friend class TheoryEngineModelBuilder; public: TheoryModel(context::Context* c, std::string name, bool enableFuncModels); - ~TheoryModel() override; + virtual ~TheoryModel(); /** * Finish init, where ee is the equality engine the model should use. */ @@ -295,23 +294,21 @@ public: */ Node getValue(TNode n) const; /** get comments */ - void getComments(std::ostream& out) const override; + void getComments(std::ostream& out) const; //---------------------------- separation logic /** set the heap and value sep.nil is equal to */ void setHeapModel(Node h, Node neq); /** get the heap and value sep.nil is equal to */ bool getHeapModel(Node& h, Node& neq) const; - /** get the heap and value sep.nil is equal to */ - bool getHeapModel(Expr& h, Expr& neq) const override; //---------------------------- end separation logic /** is the list of approximations non-empty? */ - bool hasApproximations() const override; + bool hasApproximations() const; /** get approximations */ - std::vector<std::pair<Expr, Expr> > getApproximations() const override; + std::vector<std::pair<Node, Node> > getApproximations() const; /** get domain elements for uninterpreted sort t */ - std::vector<Expr> getDomainElements(Type t) const override; + std::vector<Node> getDomainElements(TypeNode t) const; /** get the representative set object */ const RepSet* getRepSet() const { return &d_rep_set; } /** get the representative set object (FIXME: remove this, see #1199) */ @@ -319,17 +316,15 @@ public: //---------------------------- model cores /** set using model core */ - void setUsingModelCore() override; + void setUsingModelCore(); /** record model core symbol */ - void recordModelCoreSymbol(Expr sym) override; + void recordModelCoreSymbol(Node sym); /** Return whether symbol expr is in the model core. */ - bool isModelCoreSymbol(Expr sym) const override; + bool isModelCoreSymbol(Node sym) const; //---------------------------- end model cores - /** get value function for Exprs. */ - Expr getValue(Expr expr) const override; /** get cardinality for sort */ - Cardinality getCardinality(Type t) const override; + Cardinality getCardinality(TypeNode t) const; //---------------------------- function values /** a map from functions f to a list of all APPLY_UF terms with operator f */ diff --git a/src/theory/theory_model_builder.cpp b/src/theory/theory_model_builder.cpp index 0f69566d6..2f9e168c9 100644 --- a/src/theory/theory_model_builder.cpp +++ b/src/theory/theory_model_builder.cpp @@ -1082,7 +1082,7 @@ void TheoryEngineModelBuilder::computeAssignableInfo( } } -void TheoryEngineModelBuilder::postProcessModel(bool incomplete, Model* m) +void TheoryEngineModelBuilder::postProcessModel(bool incomplete, TheoryModel* m) { // if we are incomplete, there is no guarantee on the model. // thus, we do not check the model here. @@ -1090,12 +1090,11 @@ void TheoryEngineModelBuilder::postProcessModel(bool incomplete, Model* m) { return; } - TheoryModel* tm = static_cast<TheoryModel*>(m); - Assert(tm != nullptr); + Assert(m != nullptr); // debug-check the model if the checkModels() is enabled. if (options::debugCheckModels()) { - debugCheckModel(tm); + debugCheckModel(m); } } diff --git a/src/theory/theory_model_builder.h b/src/theory/theory_model_builder.h index 996609dd3..4ffcbeee7 100644 --- a/src/theory/theory_model_builder.h +++ b/src/theory/theory_model_builder.h @@ -81,7 +81,7 @@ class TheoryEngineModelBuilder * method checks the internal consistency of the model if we are in a debug * build. */ - void postProcessModel(bool incomplete, Model* m); + void postProcessModel(bool incomplete, TheoryModel* m); protected: /** pointer to theory engine */ |