This PR moves the collectAssertedTerms utility function from the model manager to the theory class. This allows to use the utility also when we are not currently building the model.
return true;
}
-void ModelManager::collectAssertedTerms(TheoryId tid,
- std::set<Node>& termSet,
- bool includeShared) const
-{
- Theory* t = d_te.theoryOf(tid);
- // Collect all terms appearing in assertions
- context::CDList<Assertion>::const_iterator assert_it = t->facts_begin(),
- assert_it_end = t->facts_end();
- for (; assert_it != assert_it_end; ++assert_it)
- {
- collectTerms(tid, *assert_it, termSet);
- }
-
- if (includeShared)
- {
- // Add terms that are shared terms
- context::CDList<TNode>::const_iterator shared_it = t->shared_terms_begin(),
- shared_it_end =
- t->shared_terms_end();
- for (; shared_it != shared_it_end; ++shared_it)
- {
- collectTerms(tid, *shared_it, termSet);
- }
- }
-}
-
-void ModelManager::collectTerms(TheoryId tid,
- TNode n,
- std::set<Node>& termSet) const
-{
- const std::set<Kind>& irrKinds = d_model->getIrrelevantKinds();
- std::vector<TNode> visit;
- TNode cur;
- visit.push_back(n);
- do
- {
- cur = visit.back();
- visit.pop_back();
- if (termSet.find(cur) != termSet.end())
- {
- // already visited
- continue;
- }
- Kind k = cur.getKind();
- // only add to term set if a relevant kind
- if (irrKinds.find(k) == irrKinds.end())
- {
- termSet.insert(cur);
- }
- // traverse owned terms, don't go under quantifiers
- if ((k == kind::NOT || k == kind::EQUAL || Theory::theoryOf(cur) == tid)
- && !cur.isClosure())
- {
- visit.insert(visit.end(), cur.begin(), cur.end());
- }
- } while (!visit.empty());
-}
-
} // namespace theory
} // namespace cvc5
* @return true if we are in conflict.
*/
bool collectModelBooleanVariables();
- /**
- * Collect asserted terms for theory with the given identifier, add to
- * termSet.
- *
- * @param tid The theory whose assertions we are collecting
- * @param termSet The set to add terms to
- * @param includeShared Whether to include the shared terms of the theory
- */
- void collectAssertedTerms(TheoryId tid,
- std::set<Node>& termSet,
- bool includeShared = true) const;
- /**
- * Helper function for collectAssertedTerms, adds all subterms
- * belonging to theory tid to termSet.
- */
- void collectTerms(TheoryId tid, TNode n, std::set<Node>& termSet) const;
+
/** Reference to the theory engine */
TheoryEngine& d_te;
/** Reference to the environment */
continue;
}
Theory* t = d_te.theoryOf(theoryId);
+ if (theoryId == TheoryId::THEORY_BOOL
+ || theoryId == TheoryId::THEORY_BUILTIN)
+ {
+ Trace("model-builder")
+ << " Skipping theory " << theoryId
+ << " as it does not contribute to the model anyway" << std::endl;
+ continue;
+ }
Trace("model-builder") << " CollectModelInfo on theory: " << theoryId
<< std::endl;
// collect the asserted terms
std::set<Node> termSet;
- collectAssertedTerms(theoryId, termSet);
+ t->collectAssertedTerms(termSet);
// also get relevant terms
t->computeRelevantTerms(termSet);
if (!t->collectModelInfo(d_model.get(), termSet))
// by default, there are no additional relevant terms
}
+void Theory::collectAssertedTerms(std::set<Node>& termSet,
+ bool includeShared) const
+{
+ // Collect all terms appearing in assertions
+ context::CDList<Assertion>::const_iterator assert_it = facts_begin(),
+ assert_it_end = facts_end();
+ for (; assert_it != assert_it_end; ++assert_it)
+ {
+ collectTerms(*assert_it, termSet);
+ }
+
+ if (includeShared)
+ {
+ // Add terms that are shared terms
+ context::CDList<TNode>::const_iterator shared_it = shared_terms_begin(),
+ shared_it_end = shared_terms_end();
+ for (; shared_it != shared_it_end; ++shared_it)
+ {
+ collectTerms(*shared_it, termSet);
+ }
+ }
+}
+
+void Theory::collectTerms(TNode n, std::set<Node>& termSet) const
+{
+ const std::set<Kind>& irrKinds =
+ d_theoryState->getModel()->getIrrelevantKinds();
+ std::vector<TNode> visit;
+ TNode cur;
+ visit.push_back(n);
+ do
+ {
+ cur = visit.back();
+ visit.pop_back();
+ if (termSet.find(cur) != termSet.end())
+ {
+ // already visited
+ continue;
+ }
+ Kind k = cur.getKind();
+ // only add to term set if a relevant kind
+ if (irrKinds.find(k) == irrKinds.end())
+ {
+ termSet.insert(cur);
+ }
+ // traverse owned terms, don't go under quantifiers
+ if ((k == kind::NOT || k == kind::EQUAL || Theory::theoryOf(cur) == d_id)
+ && !cur.isClosure())
+ {
+ visit.insert(visit.end(), cur.begin(), cur.end());
+ }
+ } while (!visit.empty());
+}
+
bool Theory::collectModelValues(TheoryModel* m, const std::set<Node>& termSet)
{
return true;
* shared terms that should be considered relevant, add them to termSet.
*/
virtual void computeRelevantTerms(std::set<Node>& termSet);
+ /**
+ * Collect asserted terms for this theory and add them to termSet.
+ *
+ * @param termSet The set to add terms to
+ * @param includeShared Whether to include the shared terms of the theory
+ */
+ void collectAssertedTerms(std::set<Node>& termSet,
+ bool includeShared = true) const;
+ /**
+ * Helper function for collectAssertedTerms, adds all subterms
+ * belonging to this theory to termSet.
+ */
+ void collectTerms(TNode n, std::set<Node>& termSet) const;
/**
* Collect model values, after equality information is added to the model.
* The argument termSet is the set of relevant terms returned by