mirror of
https://github.com/Z3Prover/z3
synced 2025-07-30 16:03:16 +00:00
adding incremental cubing from API
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
260c27d58a
commit
e507a6ccd1
18 changed files with 194 additions and 9 deletions
|
@ -2353,6 +2353,16 @@ namespace sat {
|
|||
}
|
||||
|
||||
lbool lookahead::cube() {
|
||||
#if 0
|
||||
literal_vector lits;
|
||||
while (true) {
|
||||
lbool result = cube(lits);
|
||||
if (lits.empty() || result != l_undef) {
|
||||
return result;
|
||||
}
|
||||
display_cube(std::cout, cube);
|
||||
}
|
||||
#endif
|
||||
lbool result = l_false;
|
||||
init_search();
|
||||
m_model.reset();
|
||||
|
@ -2394,6 +2404,58 @@ namespace sat {
|
|||
}
|
||||
}
|
||||
|
||||
lbool lookahead::cube(literal_vector& lits) {
|
||||
lits.reset();
|
||||
bool is_first = (m_cube_state.m_lit == null_literal);
|
||||
if (is_first) {
|
||||
init_search();
|
||||
m_model.reset();
|
||||
}
|
||||
scoped_level _sl(*this, c_fixed_truth);
|
||||
m_search_mode = lookahead_mode::searching;
|
||||
unsigned depth = 0;
|
||||
|
||||
if (!is_first) {
|
||||
goto pick_up_work;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
TRACE("sat", display(tout););
|
||||
inc_istamp();
|
||||
checkpoint();
|
||||
m_cube_state.m_lit = choose();
|
||||
if (inconsistent()) {
|
||||
TRACE("sat", tout << "inconsistent: " << cube << "\n";);
|
||||
m_cube_state.m_freevars_threshold = m_freevars.size();
|
||||
if (!backtrack(m_cube_state.m_cube, m_cube_state.m_is_decision)) return m_cube_state.m_result;
|
||||
continue;
|
||||
}
|
||||
if (m_cube_state.m_lit == null_literal) {
|
||||
return l_true;
|
||||
}
|
||||
depth = m_cube_state.m_cube.size();
|
||||
if ((m_config.m_cube_cutoff != 0 && depth == m_config.m_cube_cutoff) ||
|
||||
(m_config.m_cube_cutoff == 0 && m_freevars.size() < m_cube_state.m_freevars_threshold)) {
|
||||
m_cube_state.m_freevars_threshold *= (1.0 - pow(m_config.m_cube_fraction, depth));
|
||||
m_cube_state.m_result = l_undef;
|
||||
set_conflict();
|
||||
if (!backtrack(m_cube_state.m_cube, m_cube_state.m_is_decision)) return m_cube_state.m_result;
|
||||
lits.append(m_cube_state.m_cube);
|
||||
return l_undef;
|
||||
}
|
||||
pick_up_work:
|
||||
TRACE("sat", tout << "choose: " << m_cube_state.m_lit << " cube: " << m_cube_state.m_cube << "\n";);
|
||||
++m_stats.m_decisions;
|
||||
push(m_cube_state.m_lit, c_fixed_truth);
|
||||
m_cube_state.m_cube.push_back(m_cube_state.m_lit);
|
||||
m_cube_state.m_is_decision.push_back(true);
|
||||
SASSERT(inconsistent() || !is_unsat());
|
||||
}
|
||||
lbool result = m_cube_state.m_result;
|
||||
m_cube_state.reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
void lookahead::init_model() {
|
||||
m_model.reset();
|
||||
for (unsigned i = 0; i < m_num_vars; ++i) {
|
||||
|
|
|
@ -139,6 +139,22 @@ namespace sat {
|
|||
};
|
||||
#endif
|
||||
|
||||
struct cube_state {
|
||||
svector<bool> m_is_decision;
|
||||
literal_vector m_cube;
|
||||
literal m_lit;
|
||||
lbool m_result;
|
||||
double m_freevars_threshold;
|
||||
cube_state() { reset(); }
|
||||
void reset() {
|
||||
m_is_decision.reset();
|
||||
m_cube.reset();
|
||||
m_lit = null_literal;
|
||||
m_result = l_false;
|
||||
m_freevars_threshold = 0;
|
||||
}
|
||||
};
|
||||
|
||||
config m_config;
|
||||
double m_delta_trigger;
|
||||
|
||||
|
@ -202,6 +218,7 @@ namespace sat {
|
|||
lookahead_mode m_search_mode; // mode of search
|
||||
stats m_stats;
|
||||
model m_model;
|
||||
cube_state m_cube_state;
|
||||
|
||||
// ---------------------------------------
|
||||
// truth values
|
||||
|
@ -537,6 +554,8 @@ namespace sat {
|
|||
*/
|
||||
lbool cube();
|
||||
|
||||
lbool cube(literal_vector& lits);
|
||||
|
||||
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.
|
||||
|
|
|
@ -63,6 +63,7 @@ namespace sat {
|
|||
m_next_simplify = 0;
|
||||
m_num_checkpoints = 0;
|
||||
m_simplifications = 0;
|
||||
m_cuber = nullptr;
|
||||
}
|
||||
|
||||
solver::~solver() {
|
||||
|
@ -836,6 +837,19 @@ namespace sat {
|
|||
return lh.select_lookahead(assumptions, vars);
|
||||
}
|
||||
|
||||
lbool solver::cube(literal_vector& lits) {
|
||||
if (!m_cuber) {
|
||||
m_cuber = alloc(lookahead, *this);
|
||||
}
|
||||
lbool result = m_cuber->cube(lits);
|
||||
if (result == l_false) {
|
||||
dealloc(m_cuber);
|
||||
m_cuber = nullptr;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------
|
||||
//
|
||||
// Search
|
||||
|
|
|
@ -156,6 +156,8 @@ namespace sat {
|
|||
unsigned m_par_num_vars;
|
||||
bool m_par_syncing_clauses;
|
||||
|
||||
class lookahead* m_cuber;
|
||||
|
||||
statistics m_aux_stats;
|
||||
|
||||
void del_clauses(clause * const * begin, clause * const * end);
|
||||
|
@ -362,6 +364,7 @@ namespace sat {
|
|||
char const* get_reason_unknown() const { return m_reason_unknown.c_str(); }
|
||||
|
||||
literal select_lookahead(literal_vector const& assumptions, bool_var_vector const& vars);
|
||||
lbool cube(literal_vector& lits);
|
||||
|
||||
protected:
|
||||
unsigned m_conflicts_since_init;
|
||||
|
@ -404,7 +407,7 @@ namespace sat {
|
|||
void exchange_par();
|
||||
lbool check_par(unsigned num_lits, literal const* lits);
|
||||
lbool lookahead_search();
|
||||
lbool lookahead_cube();
|
||||
lbool lookahead_cube();
|
||||
lbool do_local_search(unsigned num_lits, literal const* lits);
|
||||
lbool do_ccc();
|
||||
|
||||
|
|
|
@ -344,6 +344,25 @@ public:
|
|||
expr_ref result(lit2expr[l.index()].get(), m);
|
||||
return result;
|
||||
}
|
||||
virtual expr_ref cube() {
|
||||
sat::literal_vector lits;
|
||||
lbool result = m_solver.cube(lits);
|
||||
if (result == l_false || lits.empty()) {
|
||||
return expr_ref(m.mk_false(), m);
|
||||
}
|
||||
if (result == l_true) {
|
||||
return expr_ref(m.mk_true(), m);
|
||||
}
|
||||
expr_ref_vector fmls(m);
|
||||
expr_ref_vector lit2expr(m);
|
||||
lit2expr.resize(m_solver.num_vars() * 2);
|
||||
m_map.mk_inv(lit2expr);
|
||||
for (sat::literal l : lits) {
|
||||
fmls.push_back(lit2expr[l.index()].get());
|
||||
}
|
||||
return mk_and(fmls);
|
||||
}
|
||||
|
||||
virtual void get_lemmas(expr_ref_vector & lemmas) {
|
||||
if (!m_internalized) return;
|
||||
sat2goal s2g;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue