mirror of
https://github.com/Z3Prover/z3
synced 2025-07-03 03:15:41 +00:00
Check invariant on pvars
This commit is contained in:
parent
208f166934
commit
69b41a7e70
4 changed files with 30 additions and 3 deletions
|
@ -77,7 +77,7 @@ namespace polysat {
|
||||||
/** Full variable assignment, may include variables of varying bit widths. */
|
/** Full variable assignment, may include variables of varying bit widths. */
|
||||||
class assignment {
|
class assignment {
|
||||||
solver* m_solver;
|
solver* m_solver;
|
||||||
vector<assignment_item_t> m_pairs; // TODO: do we still need this?
|
vector<assignment_item_t> m_pairs;
|
||||||
mutable scoped_ptr_vector<substitution> m_subst;
|
mutable scoped_ptr_vector<substitution> m_subst;
|
||||||
vector<substitution> m_subst_trail;
|
vector<substitution> m_subst_trail;
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@ namespace polysat {
|
||||||
LOG("Assignment: " << assignments_pp(*this));
|
LOG("Assignment: " << assignments_pp(*this));
|
||||||
if (is_conflict()) LOG("Conflict: " << m_conflict);
|
if (is_conflict()) LOG("Conflict: " << m_conflict);
|
||||||
IF_LOGGING(m_viable.log());
|
IF_LOGGING(m_viable.log());
|
||||||
|
SASSERT(var_queue_invariant());
|
||||||
if (is_conflict() && at_base_level()) { LOG_H2("UNSAT"); return l_false; }
|
if (is_conflict() && at_base_level()) { LOG_H2("UNSAT"); return l_false; }
|
||||||
else if (is_conflict()) resolve_conflict();
|
else if (is_conflict()) resolve_conflict();
|
||||||
else if (should_add_pwatch()) add_pwatch();
|
else if (should_add_pwatch()) add_pwatch();
|
||||||
|
@ -1445,7 +1446,7 @@ namespace polysat {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check that boolean assignment and constraint evaluation are consistent */
|
/** Check that boolean assignment and constraint evaluation are consistent */
|
||||||
bool solver::assignment_invariant() {
|
bool solver::assignment_invariant() const {
|
||||||
if (is_conflict())
|
if (is_conflict())
|
||||||
return true;
|
return true;
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
@ -1464,6 +1465,25 @@ namespace polysat {
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check that each variable is either assigned or queued for decisions */
|
||||||
|
bool solver::var_queue_invariant() const {
|
||||||
|
if (is_conflict())
|
||||||
|
return true;
|
||||||
|
uint_set active;
|
||||||
|
for (pvar v : m_free_pvars)
|
||||||
|
active.insert(v);
|
||||||
|
for (auto const& [v, val] : assignment())
|
||||||
|
active.insert(v);
|
||||||
|
bool ok = true;
|
||||||
|
for (pvar v = 0; v < num_vars(); ++v) {
|
||||||
|
if (!active.contains(v)) {
|
||||||
|
ok = false;
|
||||||
|
LOG("Lost variable v" << v << " (it is neither assigned nor free)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
/// Check that all constraints on the stack are satisfied by the current model.
|
/// Check that all constraints on the stack are satisfied by the current model.
|
||||||
bool solver::verify_sat() {
|
bool solver::verify_sat() {
|
||||||
LOG_H1("Checking current model...");
|
LOG_H1("Checking current model...");
|
||||||
|
|
|
@ -211,6 +211,8 @@ namespace polysat {
|
||||||
dd::pdd_manager& sz2pdd(unsigned sz) const;
|
dd::pdd_manager& sz2pdd(unsigned sz) const;
|
||||||
dd::pdd_manager& var2pdd(pvar v) const;
|
dd::pdd_manager& var2pdd(pvar v) const;
|
||||||
|
|
||||||
|
pvar num_vars() const { return m_value.size(); }
|
||||||
|
|
||||||
assignment_t const& assignment() const { return m_search.assignment(); }
|
assignment_t const& assignment() const { return m_search.assignment(); }
|
||||||
|
|
||||||
void push_level();
|
void push_level();
|
||||||
|
@ -306,7 +308,8 @@ namespace polysat {
|
||||||
static bool invariant(signed_constraints const& cs);
|
static bool invariant(signed_constraints const& cs);
|
||||||
bool wlist_invariant() const;
|
bool wlist_invariant() const;
|
||||||
bool bool_watch_invariant() const;
|
bool bool_watch_invariant() const;
|
||||||
bool assignment_invariant();
|
bool assignment_invariant() const;
|
||||||
|
bool var_queue_invariant() const;
|
||||||
bool verify_sat();
|
bool verify_sat();
|
||||||
|
|
||||||
bool can_propagate();
|
bool can_propagate();
|
||||||
|
|
|
@ -89,6 +89,10 @@ public:
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using const_iterator = decltype(m_queue)::const_iterator;
|
||||||
|
const_iterator begin() const { return m_queue.begin(); }
|
||||||
|
const_iterator end() const { return m_queue.end(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& out, var_queue const& queue) {
|
inline std::ostream& operator<<(std::ostream& out, var_queue const& queue) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue