mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 01:25:31 +00:00
init search before returning
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
b266af3e08
commit
af6ebbcd92
16 changed files with 90 additions and 37 deletions
|
@ -30,6 +30,18 @@ namespace sat {
|
|||
if (p.m_s.m_ext) p.m_s.m_ext->set_lookahead(0);
|
||||
}
|
||||
|
||||
lookahead::scoped_assumptions::scoped_assumptions(lookahead& p, literal_vector const& lits): p(p), lits(lits) {
|
||||
for (auto l : lits) {
|
||||
p.push(l, p.c_fixed_truth);
|
||||
}
|
||||
}
|
||||
lookahead::scoped_assumptions::~scoped_assumptions() {
|
||||
for (auto l : lits) {
|
||||
p.pop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void lookahead::flip_prefix() {
|
||||
if (m_trail_lim.size() < 64) {
|
||||
uint64 mask = (1ull << m_trail_lim.size());
|
||||
|
@ -1612,7 +1624,7 @@ namespace sat {
|
|||
}
|
||||
|
||||
|
||||
literal lookahead::select_lookahead(bool_var_vector const& vars) {
|
||||
literal lookahead::select_lookahead(literal_vector const& assumptions, bool_var_vector const& vars) {
|
||||
IF_VERBOSE(1, verbose_stream() << "(sat-select " << vars.size() << ")\n";);
|
||||
scoped_ext _sext(*this);
|
||||
m_search_mode = lookahead_mode::searching;
|
||||
|
@ -1623,19 +1635,25 @@ namespace sat {
|
|||
for (auto v : vars) {
|
||||
m_select_lookahead_vars.insert(v);
|
||||
}
|
||||
|
||||
scoped_assumptions _sa(*this, assumptions);
|
||||
literal l = choose();
|
||||
m_select_lookahead_vars.reset();
|
||||
if (inconsistent()) return null_literal;
|
||||
if (inconsistent()) l = null_literal;
|
||||
|
||||
#if 0
|
||||
// assign unit literals that were found during search for lookahead.
|
||||
unsigned num_assigned = 0;
|
||||
for (literal lit : m_trail) {
|
||||
if (!m_s.was_eliminated(lit.var()) && m_s.value(lit) != l_true) {
|
||||
m_s.assign(lit, justification());
|
||||
++num_assigned;
|
||||
if (assumptions.empty()) {
|
||||
unsigned num_assigned = 0;
|
||||
for (literal lit : m_trail) {
|
||||
if (!m_s.was_eliminated(lit.var()) && m_s.value(lit) != l_true) {
|
||||
m_s.assign(lit, justification());
|
||||
++num_assigned;
|
||||
}
|
||||
}
|
||||
IF_VERBOSE(1, verbose_stream() << "(sat-lookahead :units " << num_assigned << ")\n";);
|
||||
}
|
||||
IF_VERBOSE(1, verbose_stream() << "(sat-lookahead :units " << num_assigned << ")\n";);
|
||||
#endif
|
||||
return l;
|
||||
}
|
||||
|
||||
|
|
|
@ -199,6 +199,14 @@ namespace sat {
|
|||
~scoped_ext();
|
||||
};
|
||||
|
||||
class scoped_assumptions {
|
||||
lookahead& p;
|
||||
literal_vector lits;
|
||||
public:
|
||||
scoped_assumptions(lookahead& p, literal_vector const& lits);
|
||||
~scoped_assumptions();
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
// prefix updates. I use low order bits.
|
||||
|
||||
|
@ -447,7 +455,7 @@ namespace sat {
|
|||
return search();
|
||||
}
|
||||
|
||||
literal select_lookahead(bool_var_vector const& vars);
|
||||
literal select_lookahead(literal_vector const& assumptions, bool_var_vector const& vars);
|
||||
/**
|
||||
\brief simplify set of clauses by extracting units from a lookahead at base level.
|
||||
*/
|
||||
|
|
|
@ -811,14 +811,9 @@ namespace sat {
|
|||
return r;
|
||||
}
|
||||
|
||||
literal solver::select_lookahead(bool_var_vector const& vars) {
|
||||
literal solver::select_lookahead(literal_vector const& assumptions, bool_var_vector const& vars) {
|
||||
lookahead lh(*this);
|
||||
literal result = lh.select_lookahead(vars);
|
||||
if (result == null_literal) {
|
||||
set_conflict(justification());
|
||||
}
|
||||
// extract unit literals from lh
|
||||
return result;
|
||||
return lh.select_lookahead(assumptions, vars);
|
||||
}
|
||||
|
||||
// -----------------------
|
||||
|
@ -851,8 +846,8 @@ namespace sat {
|
|||
}
|
||||
#endif
|
||||
try {
|
||||
if (inconsistent()) return l_false;
|
||||
init_search();
|
||||
if (inconsistent()) return l_false;
|
||||
propagate(false);
|
||||
if (inconsistent()) return l_false;
|
||||
init_assumptions(num_lits, lits);
|
||||
|
|
|
@ -355,7 +355,7 @@ namespace sat {
|
|||
void set_model(model const& mdl);
|
||||
char const* get_reason_unknown() const { return m_reason_unknown.c_str(); }
|
||||
|
||||
literal select_lookahead(bool_var_vector const& vars);
|
||||
literal select_lookahead(literal_vector const& assumptions, bool_var_vector const& vars);
|
||||
|
||||
protected:
|
||||
unsigned m_conflicts;
|
||||
|
|
|
@ -148,6 +148,8 @@ public:
|
|||
|
||||
virtual lbool check_sat(unsigned sz, expr * const * assumptions) {
|
||||
m_solver.pop_to_base_level();
|
||||
m_core.reset();
|
||||
if (m_solver.inconsistent()) return l_false;
|
||||
expr_ref_vector _assumptions(m);
|
||||
obj_map<expr, expr*> asm2fml;
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
|
@ -280,9 +282,10 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
virtual expr_ref lookahead(expr_ref_vector const& candidates) {
|
||||
virtual expr_ref lookahead(expr_ref_vector const& assumptions, expr_ref_vector const& candidates) {
|
||||
IF_VERBOSE(1, verbose_stream() << "(sat-lookahead " << candidates.size() << ")\n";);
|
||||
sat::bool_var_vector vars;
|
||||
sat::literal_vector lits;
|
||||
expr_ref_vector lit2expr(m);
|
||||
lit2expr.resize(m_solver.num_vars() * 2);
|
||||
m_map.mk_inv(lit2expr);
|
||||
|
@ -292,11 +295,29 @@ public:
|
|||
vars.push_back(v);
|
||||
}
|
||||
}
|
||||
for (auto c : assumptions) {
|
||||
SASSERT(is_literal(c));
|
||||
sat::bool_var v = sat::null_bool_var;
|
||||
bool sign = false;
|
||||
expr* e = c;
|
||||
while (m.is_not(e, e)) {
|
||||
sign = !sign;
|
||||
}
|
||||
if (is_uninterp_const(e)) {
|
||||
v = m_map.to_bool_var(e);
|
||||
}
|
||||
if (v != sat::null_bool_var) {
|
||||
lits.push_back(sat::literal(v, sign));
|
||||
}
|
||||
else {
|
||||
IF_VERBOSE(0, verbose_stream() << "WARNING: could not handle " << mk_pp(c, m) << "\n";);
|
||||
}
|
||||
}
|
||||
IF_VERBOSE(1, verbose_stream() << "vars: " << vars.size() << "\n";);
|
||||
if (vars.empty()) {
|
||||
return expr_ref(m.mk_true(), m);
|
||||
}
|
||||
sat::literal l = m_solver.select_lookahead(vars);
|
||||
sat::literal l = m_solver.select_lookahead(lits, vars);
|
||||
if (m_solver.inconsistent()) {
|
||||
IF_VERBOSE(1, verbose_stream() << "(sat-lookahead inconsistent)\n";);
|
||||
return expr_ref(m.mk_false(), m);
|
||||
|
@ -715,7 +736,7 @@ private:
|
|||
if (asm2fml.contains(e)) {
|
||||
e = asm2fml.find(e);
|
||||
}
|
||||
m_core.push_back(e);
|
||||
m_core.push_back(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue