mirror of
https://github.com/Z3Prover/z3
synced 2026-02-28 10:51:28 +00:00
add model checker to external
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
a0b5f6937b
commit
72a7164e2d
4 changed files with 80 additions and 14 deletions
|
|
@ -1641,7 +1641,6 @@ namespace sat {
|
|||
xr* x = new (mem) xr(next_id(), lits);
|
||||
x->set_learned(learned);
|
||||
add_constraint(x);
|
||||
for (literal l : lits) s().set_external(l.var()); // TBD: determine if goal2sat does this.
|
||||
return x;
|
||||
}
|
||||
|
||||
|
|
@ -1715,7 +1714,6 @@ namespace sat {
|
|||
}
|
||||
|
||||
|
||||
|
||||
void ba_solver::ensure_parity_size(bool_var v) {
|
||||
if (m_parity_marks.size() <= static_cast<unsigned>(v)) {
|
||||
m_parity_marks.resize(static_cast<unsigned>(v) + 1, 0);
|
||||
|
|
@ -2087,6 +2085,17 @@ namespace sat {
|
|||
return l_undef;
|
||||
}
|
||||
|
||||
lbool ba_solver::eval(model const& m, constraint const& c) const {
|
||||
lbool v1 = c.lit() == null_literal ? l_true : value(c.lit());
|
||||
switch (c.tag()) {
|
||||
case card_t: return eval(v1, eval(m, c.to_card()));
|
||||
case pb_t: return eval(v1, eval(m, c.to_pb()));
|
||||
case xr_t: return eval(v1, eval(m, c.to_xr()));
|
||||
default: UNREACHABLE(); break;
|
||||
}
|
||||
return l_undef;
|
||||
}
|
||||
|
||||
lbool ba_solver::eval(lbool a, lbool b) const {
|
||||
if (a == l_undef || b == l_undef) return l_undef;
|
||||
return (a == b) ? l_true : l_false;
|
||||
|
|
@ -2106,6 +2115,34 @@ namespace sat {
|
|||
return l_undef;
|
||||
}
|
||||
|
||||
lbool ba_solver::eval(model const& m, card const& c) const {
|
||||
unsigned trues = 0, undefs = 0;
|
||||
for (literal l : c) {
|
||||
switch (l.sign() ? ~m[l.var()] : m[l.var()]) {
|
||||
case l_true: trues++; break;
|
||||
case l_undef: undefs++; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if (trues + undefs < c.k()) return l_false;
|
||||
if (trues >= c.k()) return l_true;
|
||||
return l_undef;
|
||||
}
|
||||
|
||||
lbool ba_solver::eval(model const& m, pb const& p) const {
|
||||
unsigned trues = 0, undefs = 0;
|
||||
for (wliteral wl : p) {
|
||||
switch (wl.second.sign() ? ~m[wl.second.var()] : m[wl.second.var()]) {
|
||||
case l_true: trues += wl.first; break;
|
||||
case l_undef: undefs += wl.first; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if (trues + undefs < p.k()) return l_false;
|
||||
if (trues >= p.k()) return l_true;
|
||||
return l_undef;
|
||||
}
|
||||
|
||||
lbool ba_solver::eval(pb const& p) const {
|
||||
unsigned trues = 0, undefs = 0;
|
||||
for (wliteral wl : p) {
|
||||
|
|
@ -2133,6 +2170,19 @@ namespace sat {
|
|||
return odd ? l_true : l_false;
|
||||
}
|
||||
|
||||
lbool ba_solver::eval(model const& m, xr const& x) const {
|
||||
bool odd = false;
|
||||
|
||||
for (auto l : x) {
|
||||
switch (l.sign() ? ~m[l.var()] : m[l.var()]) {
|
||||
case l_true: odd = !odd; break;
|
||||
case l_false: break;
|
||||
default: return l_undef;
|
||||
}
|
||||
}
|
||||
return odd ? l_true : l_false;
|
||||
}
|
||||
|
||||
bool ba_solver::validate() {
|
||||
if (!validate_watch_literals()) {
|
||||
return false;
|
||||
|
|
@ -2903,7 +2953,6 @@ namespace sat {
|
|||
remove_constraint(c, "contains eliminated var");
|
||||
break;
|
||||
}
|
||||
s().set_external(v);
|
||||
}
|
||||
}
|
||||
return ext;
|
||||
|
|
@ -2984,14 +3033,6 @@ namespace sat {
|
|||
m_constraint_removed = false;
|
||||
}
|
||||
|
||||
void ba_solver::ensure_external(constraint const& c) {
|
||||
literal_vector lits(c.literals());
|
||||
for (literal l : lits) {
|
||||
s().set_external(l.var());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ba_solver::cleanup_constraints(ptr_vector<constraint>& cs, bool learned) {
|
||||
ptr_vector<constraint>::iterator it = cs.begin();
|
||||
ptr_vector<constraint>::iterator it2 = it;
|
||||
|
|
@ -3004,7 +3045,6 @@ namespace sat {
|
|||
m_allocator.deallocate(c.obj_size(), &c);
|
||||
}
|
||||
else if (learned && !c.learned()) {
|
||||
ensure_external(c);
|
||||
m_constraints.push_back(&c);
|
||||
}
|
||||
else {
|
||||
|
|
@ -4051,6 +4091,23 @@ namespace sat {
|
|||
return value < p.m_k;
|
||||
}
|
||||
|
||||
bool ba_solver::check_model(model const& m) const {
|
||||
bool ok = true;
|
||||
for (constraint const* c : m_constraints) {
|
||||
if (!check_model(m, *c)) ok = false;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ba_solver::check_model(model const& m, constraint const& c) const {
|
||||
if (eval(m, c) != l_true) {
|
||||
IF_VERBOSE(0, verbose_stream() << "failed checking " << c.id() << ": " << c << "\n";);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue