Skip to content

Commit 5fd1231

Browse files
incorporate ls during propagation
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent 836802e commit 5fd1231

File tree

4 files changed

+103
-28
lines changed

4 files changed

+103
-28
lines changed

src/ast/sls/sls_smt_plugin.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ namespace sls {
106106
m_rewards[v] = m_ddfw->get_reward_avg(w);
107107
}
108108
m_completed = true;
109-
m_min_unsat_size = UINT_MAX;
110109
}
111110

112111
void smt_plugin::bounded_run(unsigned max_iterations) {
@@ -140,6 +139,20 @@ namespace sls {
140139
// m_ddfw owns the pointer to smt_plugin and destructs it.
141140
dealloc(d);
142141
}
142+
143+
void smt_plugin::get_shared_clauses(vector<sat::literal_vector>& _clauses) {
144+
_clauses.reset();
145+
for (auto const& clause : clauses()) {
146+
if (!all_of(clause.m_clause, [&](sat::literal lit) {
147+
return m_sls_bool_var2smt_bool_var.get(lit.var(), sat::null_bool_var) != sat::null_bool_var;
148+
}))
149+
continue;
150+
sat::literal_vector cl;
151+
for (auto lit : clause)
152+
cl.push_back(sat::literal(m_sls_bool_var2smt_bool_var[lit.var()], lit.sign()));
153+
_clauses.push_back(cl);
154+
}
155+
}
143156

144157
std::ostream& smt_plugin::display(std::ostream& out) {
145158
m_ddfw->display(out);

src/ast/sls/sls_smt_plugin.h

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ namespace sls {
107107
// interface to calling solver:
108108
void check(expr_ref_vector const& fmls, vector <sat::literal_vector> const& clauses);
109109
void finalize(model_ref& md, ::statistics& st);
110+
void get_shared_clauses(vector<sat::literal_vector>& clauses);
110111
void updt_params(params_ref& p) {}
111112
std::ostream& display(std::ostream& out) override;
112113

src/smt/theory_sls.cpp

+76-27
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,23 @@ namespace smt {
8484
}
8585

8686
void theory_sls::propagate() {
87-
if (m_smt_plugin && !m_checking) {
87+
if (!m_smt_plugin)
88+
return;
89+
if (!m_checking) {
8890
expr_ref_vector fmls(m);
8991
for (unsigned i = 0; i < ctx.get_num_asserted_formulas(); ++i)
9092
fmls.push_back(ctx.get_asserted_formula(i));
9193
m_checking = true;
9294
vector<sat::literal_vector> clauses;
9395
m_smt_plugin->check(fmls, clauses);
94-
return;
96+
m_smt_plugin->get_shared_clauses(m_shared_clauses);
97+
}
98+
else if (!m_parallel_mode)
99+
propagate_local_search();
100+
else if (m_smt_plugin->completed()) {
101+
m_smt_plugin->finalize(m_model, m_st);
102+
m_smt_plugin = nullptr;
95103
}
96-
if (!m_smt_plugin || !m_parallel_mode)
97-
return;
98-
if (!m_smt_plugin->completed())
99-
return;
100-
m_smt_plugin->finalize(m_model, m_st);
101-
m_smt_plugin = nullptr;
102104
}
103105

104106
void theory_sls::pop_scope_eh(unsigned n) {
@@ -111,14 +113,67 @@ namespace smt {
111113
m_smt_plugin->add_unit(lits[m_trail_lim]);
112114
}
113115

114-
++m_difference_score; // blindly assume we backtrack over initial clauses.
116+
check_for_unassigned_clause_after_resolve();
115117
#if 0
116118
if (ctx.has_new_best_phase())
117119
m_smt_plugin->import_phase_from_smt();
118120

119-
#endif
121+
#endif
120122
}
121123

124+
//
125+
// hybrid-smt uses a heuristic to determine when to restart local search.
126+
// it is based on when the assignment to shared clauses has a change in literal assignment.
127+
//
128+
void theory_sls::check_for_unassigned_clause_after_resolve() {
129+
if (m_has_unassigned_clause_after_resolve) {
130+
m_after_resolve_decide_count = 0;
131+
if (m_after_resolve_decide_gap >= 16)
132+
m_after_resolve_decide_gap /= 4;
133+
}
134+
else if (!shared_clauses_are_true()) {
135+
m_resolve_count++;
136+
if (m_resolve_count > m_resolve_gap) {
137+
m_resolve_gap++;
138+
m_has_unassigned_clause_after_resolve = true;
139+
m_resolve_count = 0;
140+
m_after_resolve_decide_count = 0;
141+
m_after_resolve_decide_gap = 4;
142+
}
143+
}
144+
}
145+
146+
void theory_sls::propagate_local_search() {
147+
if (!m_has_unassigned_clause_after_resolve)
148+
return;
149+
if (m_parallel_mode || !m_smt_plugin)
150+
return;
151+
++m_after_resolve_decide_count;
152+
if (100 + m_after_resolve_decide_gap > m_after_resolve_decide_count)
153+
return;
154+
m_after_resolve_decide_gap *= 2;
155+
if (!shared_clauses_are_true())
156+
return;
157+
m_resolve_count = 0;
158+
m_has_unassigned_clause_after_resolve = false;
159+
run_guided_sls();
160+
}
161+
162+
void theory_sls::run_guided_sls() {
163+
++m_num_guided_sls;
164+
m_smt_plugin->smt_phase_to_sls();
165+
m_smt_plugin->smt_units_to_sls();
166+
m_smt_plugin->smt_values_to_sls();
167+
bounded_run(m_final_check_ls_steps);
168+
dec_final_check_ls_steps();
169+
if (m_smt_plugin) {
170+
m_smt_plugin->sls_phase_to_smt();
171+
m_smt_plugin->sls_values_to_smt();
172+
if (m_num_guided_sls % 20 == 0)
173+
m_smt_plugin->sls_activity_to_smt();
174+
}
175+
}
176+
122177
void theory_sls::init() {
123178
if (m_smt_plugin)
124179
finalize();
@@ -158,27 +213,21 @@ namespace smt {
158213
final_check_status theory_sls::final_check_eh() {
159214
if (m_parallel_mode || !m_smt_plugin)
160215
return FC_DONE;
161-
if (m_difference_score < m_difference_score_threshold + 100)
216+
++m_after_resolve_decide_count;
217+
if (m_after_resolve_decide_gap > m_after_resolve_decide_count)
162218
return FC_DONE;
163-
164-
++m_difference_score_threshold;
165-
m_difference_score = 0;
166-
++m_num_guided_sls;
167-
168-
m_smt_plugin->smt_phase_to_sls();
169-
m_smt_plugin->smt_units_to_sls();
170-
m_smt_plugin->smt_values_to_sls();
171-
bounded_run(m_final_check_ls_steps);
172-
dec_final_check_ls_steps();
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-
}
219+
m_after_resolve_decide_gap *= 2;
220+
run_guided_sls();
179221
return FC_DONE;
180222
}
181223

224+
bool theory_sls::shared_clauses_are_true() const {
225+
for (auto const& cl : m_shared_clauses)
226+
if (all_of(cl, [this](sat::literal lit) { return ctx.get_assignment(lit) != l_true; }))
227+
return false;
228+
return true;
229+
}
230+
182231
void theory_sls::display(std::ostream& out) const {
183232
out << "theory-sls\n";
184233
}

src/smt/theory_sls.h

+12
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ namespace smt {
6565
unsigned m_final_check_ls_steps = 30000;
6666
unsigned m_final_check_ls_steps_dec = 10000;
6767
unsigned m_final_check_ls_steps_min = 10000;
68+
bool m_has_unassigned_clause_after_resolve = false;
69+
unsigned m_after_resolve_decide_gap = 4;
70+
unsigned m_after_resolve_decide_count = 0;
71+
unsigned m_resolve_count = 0;
72+
unsigned m_resolve_gap = 0;
6873
::statistics m_st;
74+
vector<sat::literal_vector> m_shared_clauses;
6975

7076
void finalize();
7177
void bounded_run(unsigned num_steps);
@@ -78,6 +84,12 @@ namespace smt {
7884
m_final_check_ls_steps -= m_final_check_ls_steps_dec;
7985
}
8086

87+
bool shared_clauses_are_true() const;
88+
void check_for_unassigned_clause_after_resolve();
89+
void propagate_local_search();
90+
91+
void run_guided_sls();
92+
8193
public:
8294
theory_sls(context& ctx);
8395
~theory_sls() override;

0 commit comments

Comments
 (0)