File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -185,17 +185,27 @@ namespace opt {
185185 }
186186
187187 void context::set_hard_constraints (expr_ref_vector const & fmls) {
188- if (m_scoped_state.set (fmls)) {
189- clear_state ();
188+ if (m_calling_on_model) {
189+ for (expr* f : fmls)
190+ add_hard_constraint (f);
191+ return ;
190192 }
193+ if (m_scoped_state.set (fmls))
194+ clear_state ();
191195 }
192196
193- void context::add_hard_constraint (expr* f) {
194- m_scoped_state.add (f);
195- clear_state ();
197+ void context::add_hard_constraint (expr* f) {
198+ if (m_calling_on_model)
199+ get_solver ().assert_expr (f);
200+ else {
201+ m_scoped_state.add (f);
202+ clear_state ();
203+ }
196204 }
197205
198206 void context::add_hard_constraint (expr* f, expr* t) {
207+ if (m_calling_on_model)
208+ throw default_exception (" adding soft constraints is not supported during callbacks" );
199209 m_scoped_state.m_asms .push_back (t);
200210 m_scoped_state.add (m.mk_implies (t, f));
201211 clear_state ();
@@ -389,6 +399,7 @@ namespace opt {
389399 model_ref md = m->copy ();
390400 if (!m_model_fixed.contains (md.get ()))
391401 fix_model (md);
402+ flet<bool > _calling (m_calling_on_model, true );
392403 m_on_model_eh (m_on_model_ctx, md);
393404 m_model_fixed.pop_back ();
394405 }
Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ namespace opt {
165165 ast_manager& m;
166166 on_model_t m_on_model_ctx;
167167 std::function<void (on_model_t &, model_ref&)> m_on_model_eh;
168+ bool m_calling_on_model = false ;
168169 arith_util m_arith;
169170 bv_util m_bv;
170171 expr_ref_vector m_hard_constraints;
You can’t perform that action at this time.
0 commit comments