3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-07 06:33:23 +00:00
This commit is contained in:
Nikolaj Bjorner 2021-05-17 15:41:51 -07:00
parent 1a432529dd
commit 8384f38eb5
5 changed files with 49 additions and 61 deletions

View file

@ -195,24 +195,25 @@ namespace opt {
lbool optsmt::geometric_lex(unsigned obj_index, bool is_maximize) {
TRACE("opt", tout << "index: " << obj_index << " is-max: " << is_maximize << "\n";);
arith_util arith(m);
bool is_int = arith.is_int(m_objs[obj_index].get());
bool is_int = arith.is_int(m_objs.get(obj_index));
lbool is_sat = l_true;
expr_ref bound(m), last_bound(m);
for (unsigned i = 0; i < obj_index; ++i) {
for (unsigned i = 0; i < obj_index; ++i)
commit_assignment(i);
}
unsigned steps = 0;
unsigned step_incs = 0;
rational delta_per_step(1);
unsigned num_scopes = 0;
inf_eps last_objective = inf_eps(rational(-1), inf_rational(0));
while (m.inc()) {
SASSERT(delta_per_step.is_int());
SASSERT(delta_per_step.is_pos());
is_sat = m_s->check_sat(0, nullptr);
TRACE("opt", tout << "check " << is_sat << "\n";
tout << "last bound: " << last_bound << "\n";
tout << "lower: " << m_lower[obj_index] << "\n";
tout << "upper: " << m_upper[obj_index] << "\n";
);
@ -221,6 +222,7 @@ namespace opt {
m_s->get_model(m_model);
SASSERT(m_model);
inf_eps obj = m_s->saved_objective_value(obj_index);
TRACE("opt", tout << "saved objective: " << obj << "\n";);
update_lower_lex(obj_index, obj, is_maximize);
if (!is_int || !m_lower[obj_index].is_finite()) {
delta_per_step = rational(1);
@ -233,12 +235,12 @@ namespace opt {
else {
++steps;
}
if (delta_per_step > rational::one()) {
if (delta_per_step > rational::one() || obj == last_objective) {
m_s->push();
++num_scopes;
bound = m_s->mk_ge(obj_index, obj + inf_eps(delta_per_step));
}
TRACE("opt", tout << "delta: " << delta_per_step << " " << bound << "\n";);
last_objective = obj;
if (bound == last_bound) {
break;
}
@ -357,6 +359,7 @@ namespace opt {
}
void optsmt::update_lower_lex(unsigned idx, inf_eps const& v, bool is_maximize) {
TRACE("opt", tout << v << " lower: " << m_lower[idx] << "\n";);
if (v > m_lower[idx]) {
m_lower[idx] = v;
IF_VERBOSE(1,
@ -368,6 +371,7 @@ namespace opt {
for (unsigned i = idx+1; i < m_vars.size(); ++i) {
m_lower[i] = m_s->saved_objective_value(i);
}
TRACE("opt", tout << "update best model " << *m_model << "\n";);
m_best_model = m_model;
m_s->get_labels(m_labels);
m_context.set_model(m_model);
@ -532,10 +536,6 @@ namespace opt {
return m_lower[i];
}
bool optsmt::objective_is_model_valid(unsigned index) const {
return m_s->objective_is_model_valid(index);
}
inf_eps optsmt::get_upper(unsigned i) const {
if (i >= m_upper.size()) return inf_eps();
return m_upper[i];
@ -543,6 +543,7 @@ namespace opt {
void optsmt::get_model(model_ref& mdl, svector<symbol> & labels) {
mdl = m_best_model.get();
TRACE("opt", tout << *mdl << "\n";);
labels = m_labels;
}