Skip to content

Commit 197951c

Browse files
fixes to sls
1 parent 7c5ff7c commit 197951c

8 files changed

+33
-46
lines changed

src/ast/sls/sat_ddfw.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace sat {
4343
check_without_plugin();
4444
remove_assumptions();
4545
log();
46-
return m_min_sz == 0 ? l_true : l_undef;
46+
return m_min_sz == 0 && m_limit.inc() ? m_last_result : l_undef;
4747
}
4848

4949
void ddfw::check_without_plugin() {
@@ -401,7 +401,7 @@ namespace sat {
401401
m_model[i] = to_lbool(value(i));
402402
save_priorities();
403403
if (m_plugin)
404-
m_plugin->on_save_model();
404+
m_last_result = m_plugin->on_save_model();
405405
}
406406

407407
void ddfw::save_best_values() {

src/ast/sls/sat_ddfw.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace sat {
3939
//virtual void init_search() = 0;
4040
//virtual void finish_search() = 0;
4141
virtual void on_rescale() = 0;
42-
virtual void on_save_model() = 0;
42+
virtual lbool on_save_model() = 0;
4343
virtual void on_restart() = 0;
4444
};
4545

@@ -90,6 +90,7 @@ namespace sat {
9090
unsigned_vector m_flat_use_list;
9191
unsigned_vector m_use_list_index;
9292
unsigned m_use_list_vars = 0, m_use_list_clauses = 0;
93+
lbool m_last_result = l_true;
9394

9495
indexed_uint_set m_unsat;
9596
indexed_uint_set m_unsat_vars; // set of variables that are in unsat clauses

src/ast/sls/sls_arith_base.cpp

-18
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,6 @@ namespace sls {
256256
num_t eps(1);
257257
if (!is_int(x) && abs(rh - lh) <= eps)
258258
eps = abs(rh - lh) / num_t(2);
259-
// verbose_stream() << a << " " << b << " " << c << "\n";
260-
// verbose_stream() << (-b - root) << " " << (2 * a) << " " << ll << " " << lh << "\n";
261-
// verbose_stream() << (-b + root) << " " << (2 * a) << " " << rl << " " << rh << "\n";
262259
SASSERT(ll <= lh && ll + 1 >= lh);
263260
SASSERT(rl <= rh && rl + 1 >= rh);
264261
SASSERT(!is_square || ll != lh || a * ll * ll + b * ll + c == 0);
@@ -571,8 +568,6 @@ namespace sls {
571568
template<typename num_t>
572569
bool arith_base<num_t>::repair(sat::literal lit) {
573570

574-
//verbose_stream() << "repair " << lit << " " << (ctx.is_unit(lit)?"unit":"") << " " << mk_bounded_pp(ctx.atom(lit.var()), m) << "\n";
575-
//verbose_stream() << *atom(lit.var()) << "\n";
576571
m_last_literal = lit;
577572
if (find_nl_moves(lit))
578573
return true;
@@ -673,8 +668,6 @@ namespace sls {
673668
return false;
674669
}
675670

676-
// IF_VERBOSE(0, display(verbose_stream(), v) << " := " << new_value << "\n");
677-
678671

679672

680673
#if 0
@@ -690,7 +683,6 @@ namespace sls {
690683
SASSERT(ctx.is_true(lit));
691684
ineq.m_args_value += coeff * (new_value - old_value);
692685
num_t dtt_new = dtt(old_sign, ineq);
693-
// verbose_stream() << "dtt " << lit << " " << ineq << " " << dtt_new << "\n";
694686
if (dtt_new != 0)
695687
ctx.flip(bv);
696688
SASSERT(dtt(sign(bv), ineq) == 0);
@@ -800,7 +792,6 @@ namespace sls {
800792
SASSERT(ctx.is_true(lit));
801793
ineq.m_args_value += coeff * (new_value - old_value);
802794
num_t dtt_new = dtt(old_sign, ineq);
803-
// verbose_stream() << "dtt " << lit << " " << ineq << " " << dtt_new << "\n";
804795
if (dtt_new != 0)
805796
ctx.flip(bv);
806797
SASSERT(dtt(sign(bv), ineq) == 0);
@@ -1006,7 +997,6 @@ namespace sls {
1006997
typename arith_base<num_t>::var_t arith_base<num_t>::mk_var(expr* e) {
1007998
var_t v = m_expr2var.get(e->get_id(), UINT_MAX);
1008999
if (v == UINT_MAX) {
1009-
// verbose_stream() << "mk-var " << mk_bounded_pp(e, m) << "\n";
10101000
v = m_vars.size();
10111001
m_expr2var.setx(e->get_id(), v, UINT_MAX);
10121002
m_vars.push_back(var_info(e, a.is_int(e) ? var_sort::INT : var_sort::REAL));
@@ -1245,7 +1235,6 @@ namespace sls {
12451235
return false;
12461236
flet<bool> _tabu(m_use_tabu, false);
12471237
TRACE("sls", tout << "repair def " << mk_bounded_pp(vi.m_expr, m) << "\n");
1248-
// verbose_stream() << "repair down " << mk_bounded_pp(e, m) << "\n";
12491238
switch (vi.m_op) {
12501239
case arith_op_kind::LAST_ARITH_OP:
12511240
break;
@@ -1522,11 +1511,8 @@ namespace sls {
15221511
if (old_value == sum)
15231512
return true;
15241513

1525-
//display(verbose_stream() << "repair add v" << v << " ", ad) << " " << old_value << " sum " << sum << "\n";
15261514

15271515
m_updates.reset();
1528-
// display(verbose_stream(), v) << " ";
1529-
// verbose_stream() << mk_bounded_pp(m_vars[v].m_expr, m) << " := " << old_value << " " << sum << "\n";
15301516

15311517
for (auto const& [coeff, w] : coeffs) {
15321518
auto delta = divide(w, sum - old_value, coeff);
@@ -1590,8 +1576,6 @@ namespace sls {
15901576
}
15911577
}
15921578

1593-
// verbose_stream() << "repair product v" << v << "\n";
1594-
15951579
if (apply_update())
15961580
return eval_is_correct(v);
15971581

@@ -1957,7 +1941,6 @@ namespace sls {
19571941
}
19581942
else
19591943
new_value = val;
1960-
//verbose_stream() << v << " " << vi.m_value << " -> " << new_value << "\n";
19611944
vi.m_value = new_value;
19621945
}
19631946
else {
@@ -2308,7 +2291,6 @@ namespace sls {
23082291
num_t val = i.m_coeff;
23092292
for (auto const& [c, v] : i.m_args)
23102293
val += c * value(v);
2311-
//verbose_stream() << "invariant " << i << "\n";
23122294
if (val != i.m_args_value)
23132295
verbose_stream() << i << "\n";
23142296
SASSERT(val == i.m_args_value);

src/ast/sls/sls_smt_plugin.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@ namespace sls {
156156
if (!e)
157157
return false;
158158
bv_util bv(m);
159-
if (bv.is_bit2bool(e, t) && m_shared_terms.contains(t->get_id())) {
160-
verbose_stream() << "shared bit2bool " << mk_bounded_pp(e, ctx.get_manager()) << "\n";
161-
return true;
162-
}
159+
if (bv.is_bit2bool(e, t) && m_shared_terms.contains(t->get_id()))
160+
return true;
163161

164162
// if arith.is_le(e, s, t) && t is a numeral, s is shared-term....
165163
return false;
@@ -175,7 +173,6 @@ namespace sls {
175173
}
176174

177175
void smt_plugin::add_unit(sat::literal lit) {
178-
verbose_stream() << "add unit " << lit << " " << is_shared(lit) << "\n";
179176
if (!is_shared(lit))
180177
return;
181178
std::lock_guard<std::mutex> lock(m_mutex);
@@ -222,6 +219,7 @@ namespace sls {
222219
}
223220

224221
void smt_plugin::smt_phase_to_sls() {
222+
IF_VERBOSE(2, verbose_stream() << "SMT -> SLS phase\n");
225223
for (auto v : m_shared_bool_vars) {
226224
auto w = m_smt_bool_var2sls_bool_var[v];
227225
auto phase = ctx.get_best_phase(v);
@@ -232,6 +230,7 @@ namespace sls {
232230
}
233231

234232
void smt_plugin::smt_values_to_sls() {
233+
IF_VERBOSE(2, verbose_stream() << "SMT -> SLS values\n");
235234
for (auto const& [t, t_sync] : m_smt2sync_uninterp) {
236235
expr_ref val_t(m);
237236
if (!ctx.get_smt_value(t, val_t))
@@ -261,7 +260,9 @@ namespace sls {
261260
if (m_shared_bool_vars.contains(v)) {
262261
auto w = m_smt_bool_var2sls_bool_var[v];
263262
sat::literal sls_lit(w, lit.sign());
264-
IF_VERBOSE(2, verbose_stream() << "unit " << sls_lit << "\n");
263+
if (m_context.is_unit(sls_lit))
264+
continue;
265+
IF_VERBOSE(3, verbose_stream() << "unit " << sls_lit << "\n");
265266
m_ddfw->add(1, &sls_lit);
266267
}
267268
else {
@@ -350,15 +351,17 @@ namespace sls {
350351
m_sls2sync_uninterp.insert(sls_t, sync_t);
351352
}
352353

353-
void smt_plugin::on_save_model() {
354+
lbool smt_plugin::on_save_model() {
354355
TRACE("sls", display(tout));
356+
lbool r = l_true;
355357
while (unsat().empty()) {
356-
m_context.check();
358+
r = m_context.check();
357359
if (!m_new_clause_added)
358360
break;
359361
m_ddfw->reinit();
360362
m_new_clause_added = false;
361363
}
362364
export_from_sls();
365+
return r;
363366
}
364367
}

src/ast/sls/sls_smt_plugin.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ namespace sls {
124124
m_ddfw->reinit();
125125
}
126126

127-
void on_save_model() override;
127+
lbool on_save_model() override;
128128

129129
void on_model(model_ref& mdl) override {
130-
IF_VERBOSE(3, verbose_stream() << "on-model " << "\n");
130+
IF_VERBOSE(2, verbose_stream() << "on-model " << "\n");
131131
m_sls_model = mdl;
132132
}
133133

src/ast/sls/sls_smt_solver.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,25 @@ namespace sls {
4949
}
5050

5151
bool m_on_save_model = false;
52-
void on_save_model() override {
52+
lbool on_save_model() override {
53+
lbool r = l_true;
5354
if (m_on_save_model)
54-
return;
55+
return r;
5556
flet<bool> _on_save_model(m_on_save_model, true);
5657
CTRACE("sls", unsat().empty(), display(tout));
5758
while (unsat().empty()) {
58-
m_context.check();
59+
r = m_context.check();
5960
if (!m_new_constraint)
6061
break;
6162
TRACE("sls", display(tout));
6263
//m_ddfw.simplify();
6364
m_ddfw.reinit();
6465
m_new_constraint = false;
6566
}
67+
return r;
6668
}
6769

68-
void on_model(model_ref& mdl) override {
69-
IF_VERBOSE(1, verbose_stream() << "on-model " << "\n");
70+
void on_model(model_ref& mdl) override {
7071
m_model = mdl;
7172
}
7273

src/smt/theory_sls.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ namespace smt {
105105
if (!m_smt_plugin)
106106
return;
107107

108-
unsigned scope_lvl = ctx.get_scope_level();
109-
if (ctx.get_search_level() == scope_lvl - n) {
108+
if (ctx.get_search_level() == ctx.get_scope_level() - n) {
110109
auto& lits = ctx.assigned_literals();
111-
for (; m_trail_lim < lits.size() && ctx.get_assign_level(lits[m_trail_lim]) == scope_lvl; ++m_trail_lim)
110+
for (; m_trail_lim < lits.size() && ctx.get_assign_level(lits[m_trail_lim]) == ctx.get_search_level(); ++m_trail_lim)
112111
m_smt_plugin->add_unit(lits[m_trail_lim]);
113112
}
114113

@@ -141,7 +140,8 @@ namespace smt {
141140
m_threshold *= 2;
142141
m_smt_plugin->smt_units_to_sls();
143142
bounded_run(m_restart_ls_steps);
144-
m_smt_plugin->sls_activity_to_smt();
143+
if (m_smt_plugin)
144+
m_smt_plugin->sls_activity_to_smt();
145145
}
146146
m_difference_score = 0;
147147
m_difference_score_threshold = 1;
@@ -170,11 +170,12 @@ namespace smt {
170170
m_smt_plugin->smt_values_to_sls();
171171
bounded_run(m_final_check_ls_steps);
172172
dec_final_check_ls_steps();
173-
m_smt_plugin->sls_phase_to_smt();
174-
m_smt_plugin->sls_values_to_smt();
175-
if (m_num_guided_sls % 20 == 0)
176-
m_smt_plugin->sls_activity_to_smt();
177-
173+
if (m_smt_plugin) {
174+
m_smt_plugin->sls_phase_to_smt();
175+
m_smt_plugin->sls_values_to_smt();
176+
if (m_num_guided_sls % 20 == 0)
177+
m_smt_plugin->sls_activity_to_smt();
178+
}
178179
return FC_DONE;
179180
}
180181

src/smt/theory_sls.h

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ namespace smt {
5656
bool m_checking = false;
5757
bool m_parallel_mode = true;
5858
unsigned m_threshold = 1;
59-
unsigned m_restart_sls_count = 0;
6059
unsigned m_difference_score = 0;
6160
unsigned m_difference_score_threshold = 0;
6261
unsigned m_num_guided_sls = 0;

0 commit comments

Comments
 (0)