Skip to content

Commit

Permalink
wip experiments with sls
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolajBjorner committed Feb 14, 2023
1 parent 9ce5fe7 commit 44fcf60
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/sat/smt/arith_sls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ namespace arith {
unsigned num_steps = 0;
for (unsigned v = 0; v < s.s().num_vars(); ++v)
init_bool_var_assignment(v);
m_best_min_unsat = unsat().size();
verbose_stream() << "max arith steps " << m_max_arith_steps << "\n";
//m_max_arith_steps = 10000;
m_max_arith_steps = std::max(1000u, m_max_arith_steps);
while (m.inc() && m_best_min_unsat > 0 && num_steps < m_max_arith_steps) {
if (!flip())
break;
Expand All @@ -50,6 +49,7 @@ namespace arith {
save_best_values();
}
}
store_best_values();
log();
return unsat().empty() ? l_true : l_undef;
}
Expand All @@ -59,6 +59,11 @@ namespace arith {
}

void sls::save_best_values() {
for (unsigned v = 0; v < s.get_num_vars(); ++v)
m_vars[v].m_best_value = m_vars[v].m_value;
}

void sls::store_best_values() {
// first compute assignment to terms
// then update non-basic variables in tableau.
for (auto const& [t, v] : m_terms) {
Expand All @@ -80,7 +85,7 @@ namespace arith {
int64_t old_value = 0;
if (s.is_registered_var(v))
old_value = to_numeral(s.get_ivalue(v).x);
int64_t new_value = value(v);
int64_t new_value = m_vars[v].m_best_value;
if (old_value == new_value)
continue;
s.ensure_column(v);
Expand All @@ -104,6 +109,9 @@ namespace arith {
for (unsigned i = 0; i < d->num_clauses(); ++i)
for (sat::literal lit : *d->get_clause_info(i).m_clause)
init_literal(lit);
for (unsigned v = 0; v < s.s().num_vars(); ++v)
init_bool_var_assignment(v);
m_best_min_unsat = std::numeric_limits<unsigned>::max();
}

void sls::set_bounds_begin() {
Expand All @@ -115,7 +123,7 @@ namespace arith {
}

void sls::set_bounds_end(unsigned num_literals) {
m_max_arith_steps = (m_config.L * m_max_arith_steps) / num_literals;
m_max_arith_steps = (m_config.L * m_max_arith_steps); // / num_literals;
}

bool sls::flip() {
Expand Down Expand Up @@ -323,6 +331,9 @@ namespace arith {
int64_t dtt_old = dtt(ineq);
int64_t delta = coeff * (new_value - old_value);
int64_t dtt_new = dtt(ineq.m_args_value + delta, ineq);

if (dtt_old == dtt_new)
continue;

for (auto cl : m_bool_search->get_use_list(lit)) {
auto const& clause = get_clause_info(cl);
Expand Down
1 change: 1 addition & 0 deletions src/sat/smt/arith_sls.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ namespace arith {
void paws();
int64_t dscore(var_t v, int64_t new_value) const;
void save_best_values();
void store_best_values();
void add_vars();
sls::ineq& new_ineq(ineq_kind op, int64_t const& bound);
void add_arg(sat::literal lit, ineq& ineq, int64_t const& c, var_t v);
Expand Down
14 changes: 13 additions & 1 deletion src/sat/smt/euf_local_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ namespace euf {

// Non-boolean literals are assumptions to Boolean search
literal_vector assumptions;
#if 0
for (unsigned v = 0; v < phase.size(); ++v)
if (!is_propositional(literal(v)))
assumptions.push_back(literal(v, !bool_search.get_value(v)));
#endif

verbose_stream() << "assumptions " << assumptions.size() << "\n";

Expand All @@ -51,6 +53,14 @@ namespace euf {
lbool r = bool_search.check(assumptions.size(), assumptions.data(), nullptr);
bool_search.rlimit().pop();

#if 0
// restore state to optimal model
auto const& mdl = bool_search.get_model();
for (unsigned i = 0; i < mdl.size(); ++i)
if ((mdl[i] == l_true) != bool_search.get_value(i))
bool_search.flip(i);
#endif

for (auto* th : m_solvers)
th->local_search(phase);

Expand Down Expand Up @@ -92,7 +102,9 @@ namespace euf {
count_literal(l);
}

m_max_bool_steps = (m_ls_config.L * num_bool) / num_literals;
m_max_bool_steps = (m_ls_config.L * num_bool); // / num_literals;
m_max_bool_steps = std::max(10000u, m_max_bool_steps);
verbose_stream() << "num literals " << num_literals << " num bool " << num_bool << " max bool steps " << m_max_bool_steps << "\n";

for (auto* th : m_solvers)
th->set_bounds_end(num_literals);
Expand Down

0 comments on commit 44fcf60

Please sign in to comment.