mirror of
https://github.com/Z3Prover/z3
synced 2025-08-19 17:50:23 +00:00
enabling upper bound test
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
637b63cbe1
commit
72e82532b2
9 changed files with 82 additions and 51 deletions
|
@ -77,6 +77,9 @@ namespace opt {
|
|||
else if (typeid(smt::theory_i_arith) == typeid(*arith_theory)) {
|
||||
return dynamic_cast<smt::theory_i_arith&>(*arith_theory);
|
||||
}
|
||||
else if (typeid(smt::theory_inf_arith) == typeid(*arith_theory)) {
|
||||
return dynamic_cast<smt::theory_inf_arith&>(*arith_theory);
|
||||
}
|
||||
else if (typeid(smt::theory_rdl&) == typeid(*arith_theory)) {
|
||||
return dynamic_cast<smt::theory_rdl&>(*arith_theory);
|
||||
}
|
||||
|
@ -172,7 +175,8 @@ namespace opt {
|
|||
return expr_ref(m.mk_true(), m);
|
||||
}
|
||||
else {
|
||||
return expr_ref(get_optimizer().block_lower_bound(m_objective_vars[var], val.get_numeral()), m);
|
||||
inf_rational n = val.get_numeral();
|
||||
return expr_ref(get_optimizer().block_lower_bound(m_objective_vars[var], n), m);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,6 @@ namespace opt {
|
|||
|
||||
smt::context& get_context() { return m_context.get_context(); } // used by weighted maxsat.
|
||||
|
||||
private:
|
||||
smt::theory_opt& get_optimizer();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -66,24 +66,16 @@ namespace opt {
|
|||
*/
|
||||
lbool optimize_objectives::basic_opt(app_ref_vector& objectives) {
|
||||
arith_util autil(m);
|
||||
s->reset_objectives();
|
||||
m_lower.reset();
|
||||
m_upper.reset();
|
||||
// First check_sat call to initialize theories
|
||||
lbool is_sat = s->check_sat(0, 0);
|
||||
if (is_sat != l_true) {
|
||||
return is_sat;
|
||||
}
|
||||
|
||||
opt_solver::scoped_push _push(*s);
|
||||
opt_solver::toggle_objective _t(*s, true);
|
||||
|
||||
for (unsigned i = 0; i < objectives.size(); ++i) {
|
||||
s->add_objective(objectives[i].get());
|
||||
m_lower.push_back(inf_eps(rational(-1),inf_rational(0)));
|
||||
m_upper.push_back(inf_eps(rational(1), inf_rational(0)));
|
||||
m_vars.push_back(s->add_objective(objectives[i].get()));
|
||||
}
|
||||
|
||||
|
||||
lbool is_sat = l_true;
|
||||
// ready to test: is_sat = update_upper();
|
||||
while (is_sat == l_true && !m_cancel) {
|
||||
is_sat = update_lower();
|
||||
}
|
||||
|
@ -117,8 +109,31 @@ namespace opt {
|
|||
}
|
||||
|
||||
lbool optimize_objectives::update_upper() {
|
||||
NOT_IMPLEMENTED_YET();
|
||||
return l_undef;
|
||||
smt::theory_opt& opt = s->get_optimizer();
|
||||
|
||||
if (typeid(smt::theory_inf_arith) != typeid(opt)) {
|
||||
return l_true;
|
||||
}
|
||||
smt::theory_inf_arith& th = dynamic_cast<smt::theory_inf_arith&>(opt);
|
||||
|
||||
expr_ref bound(m);
|
||||
lbool is_sat = l_true;
|
||||
|
||||
for (unsigned i = 0; i < m_lower.size(); ++i) {
|
||||
if (m_lower[i] < m_upper[i]) {
|
||||
opt_solver::scoped_push _push(*s);
|
||||
smt::theory_var v = m_vars[i];
|
||||
bound = th.block_upper_bound(v, m_upper[i]);
|
||||
expr* bounds[1] = { bound };
|
||||
is_sat = s->check_sat(1, bounds);
|
||||
if (is_sat) {
|
||||
IF_VERBOSE(1, verbose_stream() << "Setting lower bound for " << v << " to " << m_upper[i] << "\n";);
|
||||
m_lower[i] = m_upper[i];
|
||||
}
|
||||
// else: TBD extract Farkas coefficients.
|
||||
}
|
||||
}
|
||||
return l_true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,10 +142,22 @@ namespace opt {
|
|||
*/
|
||||
lbool optimize_objectives::operator()(opt_solver& solver, app_ref_vector& objectives, vector<inf_eps>& values) {
|
||||
s = &solver;
|
||||
lbool result = basic_opt(objectives);
|
||||
values.reset();
|
||||
values.append(m_lower);
|
||||
return result;
|
||||
s->reset_objectives();
|
||||
m_lower.reset();
|
||||
m_upper.reset();
|
||||
for (unsigned i = 0; i < objectives.size(); ++i) {
|
||||
m_lower.push_back(inf_eps(rational(-1),inf_rational(0)));
|
||||
m_upper.push_back(inf_eps(rational(1), inf_rational(0)));
|
||||
}
|
||||
|
||||
// First check_sat call to initialize theories
|
||||
lbool is_sat = s->check_sat(0, 0);
|
||||
if (is_sat == l_true) {
|
||||
is_sat = basic_opt(objectives);
|
||||
values.reset();
|
||||
values.append(m_lower);
|
||||
}
|
||||
return is_sat;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace opt {
|
|||
volatile bool m_cancel;
|
||||
vector<inf_eps> m_lower;
|
||||
vector<inf_eps> m_upper;
|
||||
svector<smt::theory_var> m_vars;
|
||||
public:
|
||||
optimize_objectives(ast_manager& m): m(m), s(0), m_cancel(false) {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue