mirror of
https://github.com/Z3Prover/z3
synced 2025-06-23 06:13:40 +00:00
enable bounding for various domains
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
437a545c3b
commit
a617eac010
8 changed files with 39 additions and 19 deletions
|
@ -190,15 +190,33 @@ namespace opt {
|
||||||
return m_objective_values;
|
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();
|
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];
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_ref opt_solver::block_lower_bound(unsigned var, inf_eps const& val) {
|
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::mk_gt(unsigned var, inf_eps const& val) {
|
||||||
if (val.get_infinity().is_pos()) {
|
if (val.get_infinity().is_pos()) {
|
||||||
return expr_ref(m.mk_false(), m);
|
return expr_ref(m.mk_false(), m);
|
||||||
}
|
}
|
||||||
|
@ -207,7 +225,7 @@ namespace opt {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
inf_rational n = val.get_numeral();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,8 +75,8 @@ namespace opt {
|
||||||
void reset_objectives();
|
void reset_objectives();
|
||||||
|
|
||||||
vector<inf_eps> const& get_objective_values();
|
vector<inf_eps> const& get_objective_values();
|
||||||
expr_ref block_lower_bound(unsigned obj_index, inf_eps const& val);
|
expr_ref mk_gt(unsigned obj_index, inf_eps const& val);
|
||||||
expr_ref block_upper_bound(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);
|
static opt_solver& to_opt(solver& s);
|
||||||
void set_interim_stats(statistics & st);
|
void set_interim_stats(statistics & st);
|
||||||
|
|
|
@ -121,7 +121,7 @@ namespace opt {
|
||||||
|
|
||||||
for (unsigned i = 0; i < m_lower.size(); ++i) {
|
for (unsigned i = 0; i < m_lower.size(); ++i) {
|
||||||
inf_eps const& v = m_lower[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());
|
constraint = m.mk_or(disj.size(), disj.c_ptr());
|
||||||
s->assert_expr(constraint);
|
s->assert_expr(constraint);
|
||||||
|
@ -149,7 +149,7 @@ namespace opt {
|
||||||
smt::theory_var v = m_vars[i];
|
smt::theory_var v = m_vars[i];
|
||||||
mid.push_back((m_upper[i]+m_lower[i])/rational(2));
|
mid.push_back((m_upper[i]+m_lower[i])/rational(2));
|
||||||
//mid.push_back(m_upper[i]);
|
//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);
|
bounds.push_back(bound);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -273,7 +273,7 @@ namespace opt {
|
||||||
m_upper[i] = mid;
|
m_upper[i] = mid;
|
||||||
TRACE("opt", tout << "set lower bound of "; display_objective(tout, i) << " to: " << mid << "\n";
|
TRACE("opt", tout << "set lower bound of "; display_objective(tout, i) << " to: " << mid << "\n";
|
||||||
tout << get_lower(i) << ":" << get_upper(i) << "\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 {
|
std::ostream& optsmt::display_objective(std::ostream& out, unsigned i) const {
|
||||||
|
|
|
@ -999,8 +999,8 @@ namespace smt {
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
virtual inf_eps_rational<inf_rational> maximize(theory_var v);
|
virtual inf_eps_rational<inf_rational> maximize(theory_var v);
|
||||||
virtual theory_var add_objective(app* term);
|
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);
|
||||||
expr* block_upper_bound(theory_var v, inf_numeral const& val);
|
virtual expr* mk_ge(theory_var v, inf_numeral const& val);
|
||||||
void enable_record_conflict(expr* bound);
|
void enable_record_conflict(expr* bound);
|
||||||
void record_conflict(unsigned num_lits, literal const * lits,
|
void record_conflict(unsigned num_lits, literal const * lits,
|
||||||
unsigned num_eqs, enode_pair const * eqs,
|
unsigned num_eqs, enode_pair const * eqs,
|
||||||
|
|
|
@ -1044,7 +1044,7 @@ namespace smt {
|
||||||
\brief: assert val < v
|
\brief: assert val < v
|
||||||
*/
|
*/
|
||||||
template<typename Ext>
|
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();
|
ast_manager& m = get_manager();
|
||||||
expr* obj = get_enode(v)->get_owner();
|
expr* obj = get_enode(v)->get_owner();
|
||||||
expr_ref e(m);
|
expr_ref e(m);
|
||||||
|
@ -1062,7 +1062,7 @@ namespace smt {
|
||||||
\brief assert val <= v
|
\brief assert val <= v
|
||||||
*/
|
*/
|
||||||
template<typename Ext>
|
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();
|
ast_manager& m = get_manager();
|
||||||
context& ctx = get_context();
|
context& ctx = get_context();
|
||||||
std::ostringstream strm;
|
std::ostringstream strm;
|
||||||
|
|
|
@ -310,7 +310,8 @@ namespace smt {
|
||||||
|
|
||||||
virtual inf_eps_rational<inf_rational> maximize(theory_var v);
|
virtual inf_eps_rational<inf_rational> maximize(theory_var v);
|
||||||
virtual theory_var add_objective(app* term);
|
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);
|
bool internalize_objective(expr * n, rational const& m, rational& r, objective_term & objective);
|
||||||
|
|
||||||
|
|
|
@ -1146,7 +1146,7 @@ expr* theory_diff_logic<Ext>::block_objective(theory_var v, inf_rational const&
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Ext>
|
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);
|
expr * o = block_objective(v, val);
|
||||||
context & ctx = get_context();
|
context & ctx = get_context();
|
||||||
model_ref mdl;
|
model_ref mdl;
|
||||||
|
|
|
@ -28,9 +28,10 @@ namespace smt {
|
||||||
class theory_opt {
|
class theory_opt {
|
||||||
public:
|
public:
|
||||||
typedef inf_eps_rational<inf_rational> inf_eps;
|
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 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; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue