3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-08 18:31:49 +00:00

enable bounding for various domains

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2013-12-06 19:36:12 -08:00
parent 437a545c3b
commit a617eac010
8 changed files with 39 additions and 19 deletions

View file

@ -190,15 +190,33 @@ namespace opt {
return m_objective_values;
}
expr_ref opt_solver::block_upper_bound(unsigned var, inf_eps const& val) {
expr_ref opt_solver::mk_ge(unsigned var, inf_eps const& val) {
smt::theory_opt& opt = get_optimizer();
SASSERT(typeid(smt::theory_inf_arith) == typeid(opt));
smt::theory_inf_arith& th = dynamic_cast<smt::theory_inf_arith&>(opt);
smt::theory_var v = m_objective_vars[var];
return expr_ref(th.block_upper_bound(v, val), m);
if (typeid(smt::theory_inf_arith) == typeid(opt)) {
smt::theory_inf_arith& th = dynamic_cast<smt::theory_inf_arith&>(opt);
return expr_ref(th.mk_ge(v, val), m);
}
if (typeid(smt::theory_mi_arith) == typeid(opt)) {
smt::theory_mi_arith& th = dynamic_cast<smt::theory_mi_arith&>(opt);
SASSERT(val.get_infinity().is_zero());
return expr_ref(th.mk_ge(v, val.get_numeral()), m);
}
if (typeid(smt::theory_i_arith) == typeid(opt)) {
SASSERT(val.get_infinity().is_zero());
SASSERT(val.get_infinitesimal().is_zero());
smt::theory_i_arith& th = dynamic_cast<smt::theory_i_arith&>(opt);
return expr_ref(th.mk_ge(v, val.get_rational()), m);
}
// difference logic?
return expr_ref(m.mk_true(), m);
}
expr_ref opt_solver::block_lower_bound(unsigned var, inf_eps const& val) {
expr_ref opt_solver::mk_gt(unsigned var, inf_eps const& val) {
if (val.get_infinity().is_pos()) {
return expr_ref(m.mk_false(), m);
}
@ -207,7 +225,7 @@ namespace opt {
}
else {
inf_rational n = val.get_numeral();
return expr_ref(get_optimizer().block_lower_bound(m_objective_vars[var], n), m);
return expr_ref(get_optimizer().mk_gt(m_objective_vars[var], n), m);
}
}

View file

@ -75,8 +75,8 @@ namespace opt {
void reset_objectives();
vector<inf_eps> const& get_objective_values();
expr_ref block_lower_bound(unsigned obj_index, inf_eps const& val);
expr_ref block_upper_bound(unsigned obj_index, inf_eps const& val);
expr_ref mk_gt(unsigned obj_index, inf_eps const& val);
expr_ref mk_ge(unsigned obj_index, inf_eps const& val);
static opt_solver& to_opt(solver& s);
void set_interim_stats(statistics & st);

View file

@ -121,7 +121,7 @@ namespace opt {
for (unsigned i = 0; i < m_lower.size(); ++i) {
inf_eps const& v = m_lower[i];
disj.push_back(s->block_lower_bound(i, v));
disj.push_back(s->mk_gt(i, v));
}
constraint = m.mk_or(disj.size(), disj.c_ptr());
s->assert_expr(constraint);
@ -149,7 +149,7 @@ namespace opt {
smt::theory_var v = m_vars[i];
mid.push_back((m_upper[i]+m_lower[i])/rational(2));
//mid.push_back(m_upper[i]);
bound = th.block_upper_bound(v, mid[i]);
bound = th.mk_ge(v, mid[i]);
bounds.push_back(bound);
}
else {
@ -273,7 +273,7 @@ namespace opt {
m_upper[i] = mid;
TRACE("opt", tout << "set lower bound of "; display_objective(tout, i) << " to: " << mid << "\n";
tout << get_lower(i) << ":" << get_upper(i) << "\n";);
s->assert_expr(s->block_upper_bound(i, mid));
s->assert_expr(s->mk_ge(i, mid));
}
std::ostream& optsmt::display_objective(std::ostream& out, unsigned i) const {

View file

@ -999,8 +999,8 @@ namespace smt {
// -----------------------------------
virtual inf_eps_rational<inf_rational> maximize(theory_var v);
virtual theory_var add_objective(app* term);
virtual expr* block_lower_bound(theory_var v, inf_rational const& val);
expr* block_upper_bound(theory_var v, inf_numeral const& val);
virtual expr* mk_gt(theory_var v, inf_rational const& val);
virtual expr* mk_ge(theory_var v, inf_numeral const& val);
void enable_record_conflict(expr* bound);
void record_conflict(unsigned num_lits, literal const * lits,
unsigned num_eqs, enode_pair const * eqs,

View file

@ -1044,7 +1044,7 @@ namespace smt {
\brief: assert val < v
*/
template<typename Ext>
expr* theory_arith<Ext>::block_lower_bound(theory_var v, inf_rational const& val) {
expr* theory_arith<Ext>::mk_gt(theory_var v, inf_rational const& val) {
ast_manager& m = get_manager();
expr* obj = get_enode(v)->get_owner();
expr_ref e(m);
@ -1062,7 +1062,7 @@ namespace smt {
\brief assert val <= v
*/
template<typename Ext>
expr* theory_arith<Ext>::block_upper_bound(theory_var v, inf_numeral const& val) {
expr* theory_arith<Ext>::mk_ge(theory_var v, inf_numeral const& val) {
ast_manager& m = get_manager();
context& ctx = get_context();
std::ostringstream strm;

View file

@ -310,7 +310,8 @@ namespace smt {
virtual inf_eps_rational<inf_rational> maximize(theory_var v);
virtual theory_var add_objective(app* term);
virtual expr* block_lower_bound(theory_var v, inf_rational const& val);
virtual expr* mk_gt(theory_var v, inf_rational const& val);
virtual expr* mk_ge(theory_var v, inf_rational const& val) { return 0; }
bool internalize_objective(expr * n, rational const& m, rational& r, objective_term & objective);

View file

@ -1146,7 +1146,7 @@ expr* theory_diff_logic<Ext>::block_objective(theory_var v, inf_rational const&
}
template<typename Ext>
expr* theory_diff_logic<Ext>::block_lower_bound(theory_var v, inf_rational const& val) {
expr* theory_diff_logic<Ext>::mk_gt(theory_var v, inf_rational const& val) {
expr * o = block_objective(v, val);
context & ctx = get_context();
model_ref mdl;

View file

@ -28,9 +28,10 @@ namespace smt {
class theory_opt {
public:
typedef inf_eps_rational<inf_rational> inf_eps;
virtual inf_eps_rational<inf_rational> maximize(theory_var v) { UNREACHABLE(); return inf_eps::infinity(); }
virtual inf_eps maximize(theory_var v) { UNREACHABLE(); return inf_eps::infinity(); }
virtual theory_var add_objective(app* term) { UNREACHABLE(); return null_theory_var; }
virtual expr* block_lower_bound(theory_var v, inf_rational const& val) { return 0; }
virtual expr* mk_gt(theory_var v, inf_rational const& val) { UNREACHABLE(); return 0; }
virtual expr* mk_ge(theory_var v, inf_eps const& val) { UNREACHABLE(); return 0; }
};
}