@@ -84,21 +84,23 @@ namespace smt {
84
84
}
85
85
86
86
void theory_sls::propagate () {
87
- if (m_smt_plugin && !m_checking) {
87
+ if (!m_smt_plugin)
88
+ return ;
89
+ if (!m_checking) {
88
90
expr_ref_vector fmls (m);
89
91
for (unsigned i = 0 ; i < ctx.get_num_asserted_formulas (); ++i)
90
92
fmls.push_back (ctx.get_asserted_formula (i));
91
93
m_checking = true ;
92
94
vector<sat::literal_vector> clauses;
93
95
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 ;
95
103
}
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 ;
102
104
}
103
105
104
106
void theory_sls::pop_scope_eh (unsigned n) {
@@ -111,14 +113,67 @@ namespace smt {
111
113
m_smt_plugin->add_unit (lits[m_trail_lim]);
112
114
}
113
115
114
- ++m_difference_score; // blindly assume we backtrack over initial clauses.
116
+ check_for_unassigned_clause_after_resolve ();
115
117
#if 0
116
118
if (ctx.has_new_best_phase())
117
119
m_smt_plugin->import_phase_from_smt();
118
120
119
- #endif
121
+ #endif
120
122
}
121
123
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
+
122
177
void theory_sls::init () {
123
178
if (m_smt_plugin)
124
179
finalize ();
@@ -158,27 +213,21 @@ namespace smt {
158
213
final_check_status theory_sls::final_check_eh () {
159
214
if (m_parallel_mode || !m_smt_plugin)
160
215
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)
162
218
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 ();
179
221
return FC_DONE;
180
222
}
181
223
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
+
182
231
void theory_sls::display (std::ostream& out) const {
183
232
out << " theory-sls\n " ;
184
233
}
0 commit comments