mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 01:25:31 +00:00
adding lookahead and lemmas
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
7d245be4e1
commit
4e65c13726
13 changed files with 203 additions and 1 deletions
|
@ -384,6 +384,7 @@ namespace sat {
|
|||
candidate(bool_var v, float r): m_var(v), m_rating(r) {}
|
||||
};
|
||||
svector<candidate> m_candidates;
|
||||
uint_set m_select_lookahead_vars;
|
||||
|
||||
float get_rating(bool_var v) const { return m_rating[v]; }
|
||||
float get_rating(literal l) const { return get_rating(l.var()); }
|
||||
|
@ -468,7 +469,11 @@ namespace sat {
|
|||
for (bool_var const* it = m_freevars.begin(), * end = m_freevars.end(); it != end; ++it) {
|
||||
SASSERT(is_undef(*it));
|
||||
bool_var x = *it;
|
||||
if (newbies || active_prefix(x)) {
|
||||
if (!m_select_lookahead_vars.empty() && m_select_lookahead_vars.contains(x)) {
|
||||
m_candidates.push_back(candidate(x, m_rating[x]));
|
||||
sum += m_rating[x];
|
||||
}
|
||||
else if (newbies || active_prefix(x)) {
|
||||
m_candidates.push_back(candidate(x, m_rating[x]));
|
||||
sum += m_rating[x];
|
||||
}
|
||||
|
@ -1853,6 +1858,31 @@ namespace sat {
|
|||
return search();
|
||||
}
|
||||
|
||||
literal select_lookahead(bool_var_vector const& vars) {
|
||||
m_search_mode = lookahead_mode::searching;
|
||||
scoped_level _sl(*this, c_fixed_truth);
|
||||
init();
|
||||
if (inconsistent()) return null_literal;
|
||||
inc_istamp();
|
||||
for (auto v : vars) {
|
||||
m_select_lookahead_vars.insert(v);
|
||||
}
|
||||
literal l = choose();
|
||||
m_select_lookahead_vars.reset();
|
||||
if (inconsistent()) return null_literal;
|
||||
|
||||
// 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_VERBOSE(1, verbose_stream() << "(sat-lookahead :units " << num_assigned << ")\n";);
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief simplify set of clauses by extracting units from a lookahead at base level.
|
||||
*/
|
||||
|
|
|
@ -809,6 +809,16 @@ namespace sat {
|
|||
return r;
|
||||
}
|
||||
|
||||
literal solver::select_lookahead(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;
|
||||
}
|
||||
|
||||
// -----------------------
|
||||
//
|
||||
// Search
|
||||
|
|
|
@ -352,6 +352,8 @@ namespace sat {
|
|||
model_converter const & get_model_converter() const { return m_mc; }
|
||||
void set_model(model const& mdl);
|
||||
|
||||
literal select_lookahead(bool_var_vector const& vars);
|
||||
|
||||
protected:
|
||||
unsigned m_conflicts;
|
||||
unsigned m_restarts;
|
||||
|
|
|
@ -255,6 +255,28 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
virtual expr_ref lookahead(expr_ref_vector const& candidates) {
|
||||
sat::bool_var_vector vars;
|
||||
u_map<expr*> var2candidate;
|
||||
for (auto c : candidates) {
|
||||
// TBD: check membership
|
||||
sat::bool_var v = m_map.to_bool_var(c);
|
||||
SASSERT(v != sat::null_bool_var);
|
||||
vars.push_back(v);
|
||||
var2candidate.insert(v, c);
|
||||
}
|
||||
sat::literal l = m_solver.select_lookahead(vars);
|
||||
if (l == sat::null_literal) {
|
||||
return expr_ref(m.mk_true(), m);
|
||||
}
|
||||
expr* e;
|
||||
if (!var2candidate.find(l.var(), e)) {
|
||||
// TBD: if candidate set is empty, then do something else.
|
||||
e = m.mk_true();
|
||||
}
|
||||
return expr_ref(l.sign() ? m.mk_not(e) : e, m);
|
||||
}
|
||||
|
||||
virtual lbool get_consequences_core(expr_ref_vector const& assumptions, expr_ref_vector const& vars, expr_ref_vector& conseq) {
|
||||
init_preprocess();
|
||||
TRACE("sat", tout << assumptions << "\n" << vars << "\n";);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue