#pragma once
+#include <boost/foreach.hpp>
+
+#include "theory/sets/theory_sets.h"
#include "theory/sets/theory_sets_private.h"
namespace CVC4 {
namespace sets {
class TheorySetsScrutinize {
- TheorySetsPrivate* d_theory;
+ /* we don't want to accidentally modify theory data */
+ const TheorySetsPrivate* d_theory;
public:
TheorySetsScrutinize(TheorySetsPrivate* theory): d_theory(theory) {
Debug("sets") << "[sets] scrunitize enabled" << std::endl;
// assume not in conflict, and complete:
// - try building model
// - check it
+
+ TheorySetsPrivate::SettermElementsMap settermElementsMap;
+ TNode true_atom = NodeManager::currentNM()->mkConst<bool>(true);
+ std::set<Node> terms;
+ (d_theory->d_external).computeRelevantTerms(terms);
+ for(eq::EqClassIterator it_eqclasses(true_atom, &d_theory->d_equalityEngine);
+ ! it_eqclasses.isFinished() ; ++it_eqclasses) {
+ TNode n = (*it_eqclasses);
+ if(n.getKind() == kind::MEMBER) {
+ Assert(d_theory->d_equalityEngine.areEqual(n, true_atom));
+ TNode x = d_theory->d_equalityEngine.getRepresentative(n[0]);
+ TNode S = d_theory->d_equalityEngine.getRepresentative(n[1]);
+ settermElementsMap[S].insert(x);
+ }
+ }
+ bool checkPassed = true;
+ BOOST_FOREACH(TNode term, terms) {
+ if( term.getType().isSet() ) {
+ checkPassed &= d_theory->checkModel(settermElementsMap, term);
+ }
+ }
+ if(Debug.isOn("sets-checkmodel-ignore")) {
+ Debug("sets-checkmodel-ignore") << "[sets-checkmodel-ignore] checkPassed value was " << checkPassed << std::endl;
+ } else {
+ Assert( checkPassed,
+ "THEORY_SETS check-model failed. Run with -d sets-model for details." );
+ }
}
};
namespace sets {
class TheorySetsPrivate;
+class TheorySetsScrutinize;
class TheorySets : public Theory {
private:
friend class TheorySetsPrivate;
+ friend class TheorySetsScrutinize;
TheorySetsPrivate* d_internal;
public:
Debug("sets") << "[sets] in conflict = " << d_conflict << std::endl;
Assert( d_conflict ^ d_equalityEngine.consistent() );
- if(d_conflict) {
- if(Debug.isOn("sets-scrutinize")) { d_scrutinize.postCheckInvariants(); }
- return;
- }
+ if(d_conflict) { return; }
Debug("sets") << "[sets] is complete = " << isComplete() << std::endl;
}
if( (Theory::EFFORT_FULL || options::setsEagerLemmas() ) && !isComplete()) {
d_external.d_out->lemma(getLemma());
+ return;
}
- if(Debug.isOn("sets-scrutinize")) { d_scrutinize.postCheckInvariants(); }
+ // if we are here, there is no conflict and we are complete
+ if(Debug.isOn("sets-scrutinize")) { d_scrutinize->postCheckInvariants(); }
return;
}/* TheorySetsPrivate::check() */
const Elements emptySetOfElements;
const Elements& saved =
- d_equalityEngine.getRepresentative(S).getKind() == kind::EMPTYSET ?
+ d_equalityEngine.getRepresentative(S).getKind() == kind::EMPTYSET ||
+ settermElementsMap.find(d_equalityEngine.getRepresentative(S)) == settermElementsMap.end() ?
emptySetOfElements :
settermElementsMap.find(d_equalityEngine.getRepresentative(S))->second;
Debug("sets-model") << "[sets-model] saved : { ";
Elements cur;
const Elements& left =
- d_equalityEngine.getRepresentative(S[0]).getKind() == kind::EMPTYSET ?
+ d_equalityEngine.getRepresentative(S[0]).getKind() == kind::EMPTYSET ||
+ settermElementsMap.find(d_equalityEngine.getRepresentative(S[0])) == settermElementsMap.end() ?
emptySetOfElements :
settermElementsMap.find(d_equalityEngine.getRepresentative(S[0]))->second;
const Elements& right =
- d_equalityEngine.getRepresentative(S[1]).getKind() == kind::EMPTYSET ?
+ d_equalityEngine.getRepresentative(S[1]).getKind() == kind::EMPTYSET ||
+ settermElementsMap.find(d_equalityEngine.getRepresentative(S[1])) == settermElementsMap.end() ?
emptySetOfElements :
settermElementsMap.find(d_equalityEngine.getRepresentative(S[1]))->second;
}
-void Theory::collectTerms(TNode n, set<Node>& termSet)
+void Theory::collectTerms(TNode n, set<Node>& termSet) const
{
if (termSet.find(n) != termSet.end()) {
return;
}
-void Theory::computeRelevantTerms(set<Node>& termSet)
+void Theory::computeRelevantTerms(set<Node>& termSet) const
{
// Collect all terms appearing in assertions
context::CDList<Assertion>::const_iterator assert_it = facts_begin(), assert_it_end = facts_end();
/**
* Helper function for computeRelevantTerms
*/
- void collectTerms(TNode n, std::set<Node>& termSet);
+ void collectTerms(TNode n, std::set<Node>& termSet) const;
/**
- * Scans the current set of assertions and shared terms top-down until a theory-leaf is reached, and adds all terms found to termSet.
- * This is used by collectModelInfo to delimit the set of terms that should be used when constructing a model
+ * Scans the current set of assertions and shared terms top-down
+ * until a theory-leaf is reached, and adds all terms found to
+ * termSet. This is used by collectModelInfo to delimit the set of
+ * terms that should be used when constructing a model
*/
- void computeRelevantTerms(std::set<Node>& termSet);
+ void computeRelevantTerms(std::set<Node>& termSet) const;
/**
* Construct a Theory.