Skip to content

Commit 405a26c

Browse files
allow adding constraints during on_model
1 parent 005b8e3 commit 405a26c

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

src/opt/maxres.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,10 @@ class maxres : public maxsmt_solver_base {
791791
improve_model(mdl);
792792
mdl->set_model_completion(true);
793793
unsigned correction_set_size = 0;
794-
for (expr* a : m_asms) {
795-
if (mdl->is_false(a)) {
794+
for (expr* a : m_asms)
795+
if (mdl->is_false(a))
796796
++correction_set_size;
797-
}
798-
}
797+
799798
if (!m_csmodel.get() || correction_set_size < m_correction_set_size) {
800799
m_csmodel = mdl;
801800
m_correction_set_size = correction_set_size;
@@ -810,22 +809,22 @@ class maxres : public maxsmt_solver_base {
810809
return;
811810
}
812811

813-
if (!m_c.verify_model(m_index, mdl.get(), upper)) {
812+
if (!m_c.verify_model(m_index, mdl.get(), upper))
814813
return;
815-
}
816814

815+
unsigned num_assertions = s().get_num_assertions();
817816
m_model = mdl;
818817
m_c.model_updated(mdl.get());
819818

820819
TRACE("opt", tout << "updated upper: " << upper << "\n";);
821820

822-
for (soft& s : m_soft) {
821+
for (soft& s : m_soft)
823822
s.set_value(m_model->is_true(s.s));
824-
}
825823

826824
verify_assignment();
827825

828-
m_upper = upper;
826+
if (num_assertions == s().get_num_assertions())
827+
m_upper = upper;
829828

830829
trace();
831830

src/opt/maxsmt.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ namespace opt {
5050

5151
void maxsmt_solver_base::updt_params(params_ref& p) {
5252
m_params.copy(p);
53-
}
53+
}
54+
55+
void maxsmt_solver_base::reset_upper() {
56+
m_upper = m_lower;
57+
for (soft& s : m_soft)
58+
m_upper += s.weight;
59+
}
5460

5561
solver& maxsmt_solver_base::s() {
5662
return m_c.get_solver();
@@ -289,6 +295,12 @@ namespace opt {
289295
}
290296
}
291297

298+
void maxsmt::reset_upper() {
299+
if (m_msolver) {
300+
m_msolver->reset_upper();
301+
m_upper = m_msolver->get_upper();
302+
}
303+
}
292304

293305
void maxsmt::verify_assignment() {
294306
// TBD: have to use a different solver

src/opt/maxsmt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ namespace opt {
103103
};
104104

105105
lbool find_mutexes(obj_map<expr, rational>& new_soft);
106+
107+
void reset_upper();
106108

107109

108110
protected:
@@ -153,6 +155,7 @@ namespace opt {
153155
void display_answer(std::ostream& out) const;
154156
void collect_statistics(statistics& st) const;
155157
void model_updated(model* mdl);
158+
void reset_upper();
156159
private:
157160
bool is_maxsat_problem(weights_t& ws) const;
158161
void verify_assignment();

src/opt/opt_context.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,22 @@ namespace opt {
195195
}
196196

197197
void context::add_hard_constraint(expr* f) {
198-
if (m_calling_on_model)
198+
if (m_calling_on_model) {
199199
get_solver().assert_expr(f);
200+
for (auto const& [k, v] : m_maxsmts)
201+
v->reset_upper();
202+
for (unsigned i = 0; i < num_objectives(); ++i) {
203+
auto const& o = m_scoped_state.m_objectives[i];
204+
if (o.m_type != O_MAXSMT)
205+
m_optsmt.update_upper(o.m_index, inf_eps::infinity());
206+
}
207+
}
200208
else {
201209
m_scoped_state.add(f);
202210
clear_state();
203211
}
204212
}
213+
205214

206215
void context::add_hard_constraint(expr* f, expr* t) {
207216
if (m_calling_on_model)

src/sat/sat_solver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3818,6 +3818,8 @@ namespace sat {
38183818
void solver::move_to_front(bool_var b) {
38193819
if (b >= num_vars())
38203820
return;
3821+
if (m_case_split_queue.empty())
3822+
return;
38213823
bool_var next = m_case_split_queue.min_var();
38223824
auto next_act = m_activity[next];
38233825
set_activity(b, next_act + 1);

0 commit comments

Comments
 (0)