3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-24 09:11:17 +00:00

add sequential option for SLS, fixes to import/export methods SLS<->SMT

This commit is contained in:
Nikolaj Bjorner 2024-11-14 21:43:26 -08:00
parent 6a9d5910cb
commit 8e3b9f6686
16 changed files with 224 additions and 63 deletions

View file

@ -37,13 +37,12 @@ namespace smt {
return ctx.get_params();
}
void theory_sls::initialize_value(expr* t, expr* v) {
//ctx.user_propagate_initialize_value(t, v);
void theory_sls::set_value(expr* t, expr* v) {
ctx.user_propagate_initialize_value(t, v);
}
void theory_sls::force_phase(sat::literal lit) {
//
// ctx.force_phase(lit);
ctx.force_phase(lit);
}
void theory_sls::set_has_new_best_phase(bool b) {
@ -51,7 +50,7 @@ namespace smt {
}
bool theory_sls::get_best_phase(sat::bool_var v) {
return false;
return ctx.get_assignment(v) == l_true;
}
expr* theory_sls::bool_var2expr(sat::bool_var v) {
@ -61,6 +60,15 @@ namespace smt {
void theory_sls::set_finished() {
ctx.set_sls_completed();
}
bool theory_sls::get_value(expr* v, expr_ref& value) {
auto* n = ctx.get_enode(v);
return n && ctx.get_value(n, value);
}
void theory_sls::inc_activity(sat::bool_var v, double inc) {
ctx.inc_bvar_activity(v, inc);
}
unsigned theory_sls::get_num_bool_vars() const {
return ctx.get_num_bool_vars();
@ -85,7 +93,7 @@ namespace smt {
m_smt_plugin->check(fmls, clauses);
return;
}
if (!m_smt_plugin)
if (!m_smt_plugin || !m_parallel_mode)
return;
if (!m_smt_plugin->completed())
return;
@ -103,18 +111,20 @@ namespace smt {
for (; m_trail_lim < lits.size() && ctx.get_assign_level(lits[m_trail_lim]) == scope_lvl; ++m_trail_lim)
m_smt_plugin->add_unit(lits[m_trail_lim]);
}
++m_difference_score; // blindly assume we backtrack over initial clauses.
#if 0
if (ctx.has_new_best_phase())
m_smt_plugin->import_phase_from_smt();
#endif
// m_smt_plugin->import_from_sls();
#endif
}
void theory_sls::init() {
if (m_smt_plugin)
finalize();
smt_params p(ctx.get_fparams());
m_parallel_mode = p.m_sls_parallel;
m_smt_plugin = alloc(sls::smt_plugin, *this);
m_checking = false;
}
@ -123,11 +133,52 @@ namespace smt {
st.copy(m_st);
}
void theory_sls::display(std::ostream& out) const {
out << "theory-sls\n";
void theory_sls::restart_eh() {
if (m_parallel_mode || !m_smt_plugin)
return;
if (ctx.m_stats.m_num_restarts >= m_threshold + 5) {
m_threshold *= 2;
bounded_run(m_restart_ls_steps);
m_smt_plugin->sls_activity_to_smt();
}
m_difference_score = 0;
m_difference_score_threshold = 1;
}
void theory_sls::bounded_run(unsigned num_steps) {
m_smt_plugin->bounded_run(num_steps);
if (m_smt_plugin->result() == l_true) {
m_smt_plugin->finalize(m_model, m_st);
m_smt_plugin = nullptr;
}
}
final_check_status theory_sls::final_check_eh() {
if (m_parallel_mode || !m_smt_plugin)
return FC_DONE;
if (m_difference_score < m_difference_score_threshold + 100)
return FC_DONE;
++m_difference_score_threshold;
m_difference_score = 0;
++m_num_guided_sls;
m_smt_plugin->smt_phase_to_sls();
m_smt_plugin->smt_values_to_sls();
bounded_run(m_final_check_ls_steps);
dec_final_check_ls_steps();
m_smt_plugin->sls_phase_to_smt();
m_smt_plugin->sls_values_to_smt();
if (m_num_guided_sls % 20 == 0)
m_smt_plugin->sls_activity_to_smt();
return FC_DONE;
}
void theory_sls::display(std::ostream& out) const {
out << "theory-sls\n";
}
#endif
}