3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-07-21 11:52:05 +00:00

Remove active flag from constraint

Superseded by boolean assignment and pwatch
This commit is contained in:
Jakob Rath 2022-11-22 14:45:21 +01:00
parent da762700d6
commit e4999b07aa
3 changed files with 4 additions and 31 deletions

View file

@ -59,7 +59,6 @@ namespace polysat {
ckind_t m_kind; ckind_t m_kind;
unsigned_vector m_vars; unsigned_vector m_vars;
lbool m_external_sign = l_undef; lbool m_external_sign = l_undef;
bool m_is_active = false;
bool m_is_pwatched = false; bool m_is_pwatched = false;
/** The boolean variable associated to this constraint */ /** The boolean variable associated to this constraint */
sat::bool_var m_bvar = sat::null_bool_var; sat::bool_var m_bvar = sat::null_bool_var;
@ -114,9 +113,6 @@ namespace polysat {
bool is_external() const { return m_external_sign != l_undef; } bool is_external() const { return m_external_sign != l_undef; }
bool external_sign() const { SASSERT(is_external()); return m_external_sign == l_true; } bool external_sign() const { SASSERT(is_external()); return m_external_sign == l_true; }
bool is_active() const { return m_is_active; }
void set_active(bool f) { m_is_active = f; }
bool is_pwatched() const { return m_is_pwatched; } bool is_pwatched() const { return m_is_pwatched; }
void set_pwatched(bool f) { m_is_pwatched = f; } void set_pwatched(bool f) { m_is_pwatched = f; }

View file

@ -208,10 +208,6 @@ namespace polysat {
LOG_H2("Propagate bool " << lit << "@" << m_bvars.level(lit) << " " << m_level << " qhead: " << m_qhead); LOG_H2("Propagate bool " << lit << "@" << m_bvars.level(lit) << " " << m_level << " qhead: " << m_qhead);
LOG("Literal " << lit_pp(*this, lit)); LOG("Literal " << lit_pp(*this, lit));
signed_constraint c = lit2cnstr(lit); signed_constraint c = lit2cnstr(lit);
SASSERT(c);
// TODO: review active and activate_constraint
if (c->is_active())
return;
activate_constraint(c); activate_constraint(c);
auto& wlist = m_bvars.watch(~lit); auto& wlist = m_bvars.watch(~lit);
unsigned i = 0, j = 0, sz = wlist.size(); unsigned i = 0, j = 0, sz = wlist.size();
@ -262,11 +258,9 @@ namespace polysat {
return true; return true;
} }
} }
// at most one poly variable remains unassigned. // at most one pvar remains unassigned
if (m_bvars.is_assigned(c->bvar())) { if (m_bvars.is_assigned(c->bvar())) {
// constraint state: bool-propagated // constraint state: bool-propagated
// // constraint is active, propagate it
// SASSERT(c->is_active()); // TODO: what exactly does 'active' mean now ... use 'pwatched' and similar instead, to make meaning explicit?
signed_constraint sc(c, m_bvars.value(c->bvar()) == l_true); signed_constraint sc(c, m_bvars.value(c->bvar()) == l_true);
if (c->vars().size() >= 2) { if (c->vars().size() >= 2) {
unsigned other_v = c->var(1 - idx); unsigned other_v = c->var(1 - idx);
@ -275,9 +269,7 @@ namespace polysat {
} }
sc.narrow(*this, false); sc.narrow(*this, false);
} else { } else {
// constraint state: active but unassigned (bvalue undef, but pwatch is set and active; e.g., new constraints generated for lemmas) // constraint state: active but unassigned (bvalue undef, but pwatch is set; e.g., new constraints generated for lemmas)
// // constraint is not yet active, try to evaluate it
// SASSERT(!c->is_active());
if (c->vars().size() >= 2) { if (c->vars().size() >= 2) {
unsigned other_v = c->var(1 - idx); unsigned other_v = c->var(1 - idx);
// Wait for the remaining variable to be assigned // Wait for the remaining variable to be assigned
@ -423,7 +415,6 @@ namespace polysat {
case trail_instr_t::pwatch_i: { case trail_instr_t::pwatch_i: {
constraint* c = m_pwatch_trail.back(); constraint* c = m_pwatch_trail.back();
erase_pwatch(c); erase_pwatch(c);
c->set_active(false); // TODO: review meaning of "active"
m_pwatch_trail.pop_back(); m_pwatch_trail.pop_back();
break; break;
} }
@ -475,9 +466,6 @@ namespace polysat {
LOG_V("Undo assign_bool_i: " << lit); LOG_V("Undo assign_bool_i: " << lit);
unsigned active_level = m_bvars.level(lit); unsigned active_level = m_bvars.level(lit);
if (c->is_active())
deactivate_constraint(c);
if (active_level <= target_level) if (active_level <= target_level)
replay.push_back(lit); replay.push_back(lit);
else else
@ -922,7 +910,7 @@ namespace polysat {
// Unfortunately, this isn't always possible. // Unfortunately, this isn't always possible.
// Consider if the first side lemma contains a constraint that comes from a boolean decision: // Consider if the first side lemma contains a constraint that comes from a boolean decision:
// //
// 76: v10 + v7 + -1*v0 + -1 == 0 [ l_true decide@5 pwatched active ] // 76: v10 + v7 + -1*v0 + -1 == 0 [ l_true decide@5 pwatched ]
// //
// When we now backtrack behind the decision level of the literal, then we cannot propagate the side lemma, // When we now backtrack behind the decision level of the literal, then we cannot propagate the side lemma,
// and some literals of the main lemma may still be undef at this point. // and some literals of the main lemma may still be undef at this point.
@ -1005,9 +993,7 @@ namespace polysat {
void solver::activate_constraint(signed_constraint c) { void solver::activate_constraint(signed_constraint c) {
SASSERT(c); SASSERT(c);
LOG("Activating constraint: " << c); LOG("Activating constraint: " << c);
SASSERT(m_bvars.value(c.blit()) == l_true); SASSERT_EQ(m_bvars.value(c.blit()), l_true);
SASSERT(!c->is_active());
c->set_active(true);
add_pwatch(c.get()); add_pwatch(c.get());
if (c->vars().size() == 1) if (c->vars().size() == 1)
m_viable_fallback.push_constraint(c->var(0), c); m_viable_fallback.push_constraint(c->var(0), c);
@ -1017,12 +1003,6 @@ namespace polysat {
#endif #endif
} }
/// Deactivate constraint
void solver::deactivate_constraint(signed_constraint c) {
LOG_V("Deactivating constraint: " << c.blit());
c->set_active(false);
}
void solver::backjump(unsigned new_level) { void solver::backjump(unsigned new_level) {
if (m_level != new_level) { if (m_level != new_level) {
LOG_H3("Backjumping to level " << new_level << " from level " << m_level); LOG_H3("Backjumping to level " << new_level << " from level " << m_level);
@ -1222,8 +1202,6 @@ namespace polysat {
} }
if (c->is_pwatched()) if (c->is_pwatched())
out << " pwatched"; out << " pwatched";
if (c->is_active())
out << " active";
if (c->is_external()) if (c->is_external())
out << " ext"; out << " ext";
out << " ]"; out << " ]";

View file

@ -173,7 +173,6 @@ namespace polysat {
void assign_decision(sat::literal lit); void assign_decision(sat::literal lit);
void assign_eval(sat::literal lit); void assign_eval(sat::literal lit);
void activate_constraint(signed_constraint c); void activate_constraint(signed_constraint c);
void deactivate_constraint(signed_constraint c);
unsigned level(sat::literal lit, clause const& cl); unsigned level(sat::literal lit, clause const& cl);
void assign_propagate(pvar v, rational const& val); void assign_propagate(pvar v, rational const& val);