}
void DefaultVarBB (TNode node, Bits& bits, Bitblaster* bb) {
- // Assert (node.getKind() == kind::VARIABLE);
Assert(bits.size() == 0);
-
for (unsigned i = 0; i < utils::getSize(node); ++i) {
bits.push_back(utils::mkBitOf(node, i));
}
BVDebug("bitvector-bb") << "theory::bv::DefaultVarBB bitblasting " << node << "\n";
BVDebug("bitvector-bb") << " with bits " << toString(bits);
}
+ // this is not necessairily a variable, but it is a term the theory of bitvectors treads as one
+ // e.g. a select over a bv array
+ bb->storeVariable(node);
+
}
void DefaultConstBB (TNode node, Bits& bits, Bitblaster* bb) {
#include "theory/bv/theory_bv_rewrite_rules_simplification.h"
#include "theory/bv/theory_bv.h"
#include "theory/bv/options.h"
+#include "theory/model.h"
using namespace std;
}
}
+Node Bitblaster::getVarValue(TNode a) {
+ Assert (d_termCache.find(a) != d_termCache.end());
+ Bits bits = d_termCache[a];
+ Integer value(0);
+ for (int i = bits.size() -1; i >= 0; --i) {
+ SatValue bit_value;
+ if (d_cnfStream->hasLiteral(bits[i])) {
+ SatLiteral bit = d_cnfStream->getLiteral(bits[i]);
+ bit_value = d_satSolver->value(bit);
+ Assert (bit_value != SAT_VALUE_UNKNOWN);
+ } else {
+ // the bit is unconstrainted so we can give it an arbitrary value
+ bit_value = SAT_VALUE_FALSE;
+ }
+ Integer bit_int = bit_value == SAT_VALUE_TRUE ? Integer(1) : Integer(0);
+ value = value * 2 + bit_int;
+ }
+ return utils::mkConst(BitVector(bits.size(), value));
+}
+
+void Bitblaster::collectModelInfo(TheoryModel* m) {
+ __gnu_cxx::hash_set<TNode, TNodeHashFunction>::iterator it = d_variables.begin();
+ for (; it!= d_variables.end(); ++it) {
+ TNode var = *it;
+ Node const_value = getVarValue(var);
+ m->assertEquality(var, const_value, true);
+ }
+}
+
} /*bv namespace */
} /* theory namespace */
} /* CVC4 namespace*/
namespace theory {
class OutputChannel;
+class TheoryModel;
namespace bv {
};
typedef __gnu_cxx::hash_map <Node, Bits, TNodeHashFunction > TermDefMap;
- typedef __gnu_cxx::hash_set<TNode, TNodeHashFunction> AtomSet;
+ typedef __gnu_cxx::hash_set<TNode, TNodeHashFunction> AtomSet;
+ typedef __gnu_cxx::hash_set<TNode, TNodeHashFunction> VarSet;
typedef void (*TermBBStrategy) (TNode, Bits&, Bitblaster*);
typedef Node (*AtomBBStrategy) (TNode, Bitblaster*);
// caches and mappings
TermDefMap d_termCache;
AtomSet d_bitblastedAtoms;
-
+ VarSet d_variables;
context::CDList<prop::SatLiteral> d_assertedAtoms; /**< context dependent list storing the atoms
currently asserted by the DPLL SAT solver. */
void explain(TNode atom, std::vector<TNode>& explanation);
EqualityStatus getEqualityStatus(TNode a, TNode b);
-
+ /**
+ * Return a constant Node representing the value of a variable
+ * in the current model.
+ * @param a
+ *
+ * @return
+ */
+ Node getVarValue(TNode a);
+ /**
+ * Adds a constant value for each bit-blasted variable in the model.
+ *
+ * @param m the model
+ */
+ void collectModelInfo(TheoryModel* m);
+ /**
+ * Stores the variable (or non-bv term) and its corresponding bits.
+ *
+ * @param var
+ * @param bits
+ */
+ void storeVariable(TNode var) {
+ d_variables.insert(var);
+ }
private:
namespace CVC4 {
namespace theory {
+
+class TheoryModel;
+
namespace bv {
enum SubTheory {
virtual bool addAssertions(const std::vector<TNode>& assertions, Theory::Effort e) = 0;
virtual void explain(TNode literal, std::vector<TNode>& assumptions) = 0;
virtual void preRegister(TNode node) {}
-
+ virtual void collectModelInfo(TheoryModel* m) = 0;
};
}
EqualityStatus BitblastSolver::getEqualityStatus(TNode a, TNode b) {
return d_bitblaster->getEqualityStatus(a, b);
}
+
+void BitblastSolver::collectModelInfo(TheoryModel* m) {
+ return d_bitblaster->collectModelInfo(m);
+}
bool addAssertions(const std::vector<TNode>& assertions, Theory::Effort e);
void explain(TNode literal, std::vector<TNode>& assumptions);
EqualityStatus getEqualityStatus(TNode a, TNode b);
+ void collectModelInfo(TheoryModel* m);
};
}
#include "theory/bv/bv_subtheory_eq.h"
#include "theory/bv/theory_bv.h"
#include "theory/bv/theory_bv_utils.h"
-
+#include "theory/model.h"
using namespace std;
using namespace CVC4;
using namespace CVC4::context;
d_bv->setConflict(mkAnd(assumptions));
}
+void EqualitySolver::collectModelInfo(TheoryModel* m) {
+ m->assertEqualityEngine(&d_equalityEngine);
+}
#pragma once
#include "cvc4_private.h"
-
#include "theory/bv/bv_subtheory.h"
namespace CVC4 {
void preRegister(TNode node);
bool addAssertions(const std::vector<TNode>& assertions, Theory::Effort e);
void explain(TNode literal, std::vector<TNode>& assumptions);
+ void collectModelInfo(TheoryModel* m);
void addSharedTerm(TNode t) {
d_equalityEngine.addTriggerTerm(t, THEORY_BV);
}
#include "theory/bv/bitblaster.h"
#include "theory/bv/options.h"
#include "theory/bv/theory_bv_rewrite_rules_normalization.h"
-
+#include "theory/model.h"
using namespace CVC4;
using namespace CVC4::theory;
using namespace CVC4::theory::bv;
}
void TheoryBV::collectModelInfo( TheoryModel* m, bool fullModel ){
-
+ Assert(!inConflict());
+ Assert (fullModel); // can only query full model
+ d_equalitySolver.collectModelInfo(m);
+ d_bitblastSolver.collectModelInfo(m);
+
}
void TheoryBV::propagate(Effort e) {