3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 01:25:31 +00:00

push blocking code to optimizer context

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2013-10-29 20:26:54 -07:00
parent b0fddd8e60
commit bc44bcad10
11 changed files with 152 additions and 49 deletions

View file

@ -996,6 +996,7 @@ namespace smt {
virtual bool maximize(theory_var v);
virtual theory_var add_objective(app* term);
virtual inf_eps_rational<inf_rational> get_objective_value(theory_var v);
virtual expr* block_lower_bound(theory_var v, inf_rational const& val);
inf_rational m_objective_value;
// -----------------------------------

View file

@ -965,11 +965,12 @@ namespace smt {
}
//
// set_objective(expr* term) internalizes the arithmetic term and creates
// add_objective(expr* term) internalizes the arithmetic term and creates
// a row for it if it is not already internalized.
// Then return the variable corresponding to the term.
//
template<typename Ext>
theory_var theory_arith<Ext>::add_objective(app* term) {
return internalize_term_core(term);
@ -981,6 +982,20 @@ namespace smt {
return r || at_upper(v);
}
template<typename Ext>
expr* theory_arith<Ext>::block_lower_bound(theory_var v, inf_rational const& val) {
ast_manager& m = get_manager();
expr* obj = get_enode(v)->get_owner();
expr_ref e(m);
e = m_util.mk_numeral(val.get_rational(), m.get_sort(obj));
if (val.get_infinitesimal().is_neg()) {
return m_util.mk_ge(obj, e);
}
else {
return m_util.mk_gt(obj, e);
}
}
template<typename Ext>
inf_eps_rational<inf_rational> theory_arith<Ext>::get_objective_value(theory_var v) {

View file

@ -307,7 +307,11 @@ namespace smt {
virtual bool maximize(theory_var v);
virtual theory_var add_objective(app* term);
virtual inf_eps_rational<inf_rational> get_objective_value(theory_var v);
numeral m_objective_value;
virtual expr* block_lower_bound(theory_var v, inf_rational const& val);
// TBD: why are these public?:
numeral m_objective_value;
typedef vector <std::pair<theory_var, rational> > objective_term;
vector<objective_term> m_objectives;

View file

@ -1053,6 +1053,42 @@ inf_eps_rational<inf_rational> theory_diff_logic<Ext>::get_objective_value(theor
return inf_eps_rational<inf_rational>(inf_rational(r, i));
}
template<typename Ext>
expr* theory_diff_logic<Ext>::block_lower_bound(theory_var v, inf_rational const& val) {
ast_manager& m = get_manager();
objective_term const& t = m_objectives[v];
expr_ref e(m), f(m), f2(m);
// hacky implementation for now.
if (t.size() == 1 && t[0].second.is_one()) {
f = get_enode(t[0].first)->get_owner();
}
else if (t.size() == 1 && t[0].second.is_minus_one()) {
f = m_util.mk_uminus(get_enode(t[0].first)->get_owner());
}
else if (t.size() == 2 && t[0].second.is_one() && t[1].second.is_minus_one()) {
f = get_enode(t[0].first)->get_owner();
f2 = get_enode(t[1].first)->get_owner();
f = m_util.mk_sub(f, f2);
}
else if (t.size() == 2 && t[1].second.is_one() && t[0].second.is_minus_one()) {
f = get_enode(t[1].first)->get_owner();
f2 = get_enode(t[0].first)->get_owner();
f = m_util.mk_sub(f, f2);
}
else {
NOT_IMPLEMENTED_YET();
}
inf_rational new_val = val - inf_rational(m_objective_consts[v]);
e = m_util.mk_numeral(new_val.get_rational(), m.get_sort(f));
if (new_val.get_infinitesimal().is_neg()) {
return m_util.mk_ge(f, e);
}
else {
return m_util.mk_gt(f, e);
}
}
template<typename Ext>
bool theory_diff_logic<Ext>::internalize_objective(expr * n, rational const& m, rational& q, objective_term & objective) {

View file

@ -34,6 +34,7 @@ namespace smt {
inf_eps_rational<inf_rational> r(rational(1), inf_rational(0));
return r;
}
virtual expr* block_lower_bound(theory_var v, inf_rational const& val) { return 0; }
};
}