mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
integrating diff opt
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
80ba830091
commit
99b4ce037d
10 changed files with 67 additions and 59 deletions
|
@ -998,9 +998,8 @@ namespace smt {
|
|||
// Optimization
|
||||
//
|
||||
// -----------------------------------
|
||||
virtual inf_eps_rational<inf_rational> maximize(theory_var v);
|
||||
virtual inf_eps_rational<inf_rational> maximize(theory_var v, expr_ref& blocker);
|
||||
virtual theory_var add_objective(app* term);
|
||||
virtual expr* mk_gt(theory_var v, inf_rational const& val);
|
||||
virtual expr* mk_ge(filter_model_converter& fm, theory_var v, inf_numeral const& val);
|
||||
void enable_record_conflict(expr* bound);
|
||||
void record_conflict(unsigned num_lits, literal const * lits,
|
||||
|
@ -1008,6 +1007,8 @@ namespace smt {
|
|||
unsigned num_params, parameter* params);
|
||||
inf_eps_rational<inf_rational> conflict_minimize();
|
||||
private:
|
||||
virtual expr_ref mk_gt(theory_var v);
|
||||
|
||||
bool_var m_bound_watch;
|
||||
inf_eps_rational<inf_rational> m_upper_bound;
|
||||
bool get_theory_vars(expr * n, uint_set & vars);
|
||||
|
|
|
@ -1065,13 +1065,17 @@ namespace smt {
|
|||
}
|
||||
|
||||
template<typename Ext>
|
||||
inf_eps_rational<inf_rational> theory_arith<Ext>::maximize(theory_var v) {
|
||||
inf_eps_rational<inf_rational> theory_arith<Ext>::maximize(theory_var v, expr_ref& blocker) {
|
||||
TRACE("opt", tout << "data-size: " << m_data.size() << "\n";);
|
||||
max_min_t r = max_min(v, true);
|
||||
if (r == UNBOUNDED) {
|
||||
blocker = get_manager().mk_false();
|
||||
return inf_eps_rational<inf_rational>::infinity();
|
||||
}
|
||||
return inf_eps_rational<inf_rational>(get_value(v));
|
||||
else {
|
||||
blocker = mk_gt(v);
|
||||
return inf_eps_rational<inf_rational>(get_value(v));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1081,8 +1085,9 @@ namespace smt {
|
|||
for the theory of aritmetic.
|
||||
*/
|
||||
template<typename Ext>
|
||||
expr* theory_arith<Ext>::mk_gt(theory_var v, inf_rational const& val) {
|
||||
expr_ref theory_arith<Ext>::mk_gt(theory_var v) {
|
||||
ast_manager& m = get_manager();
|
||||
inf_numeral const& val = get_value(v);
|
||||
expr* obj = get_enode(v)->get_owner();
|
||||
expr_ref e(m);
|
||||
rational r = val.get_rational();
|
||||
|
@ -1094,19 +1099,20 @@ namespace smt {
|
|||
r = ceil(r);
|
||||
}
|
||||
e = m_util.mk_numeral(r, m.get_sort(obj));
|
||||
return m_util.mk_ge(obj, e);
|
||||
e = m_util.mk_ge(obj, e);
|
||||
}
|
||||
else {
|
||||
// obj is over the reals.
|
||||
e = m_util.mk_numeral(r, m.get_sort(obj));
|
||||
|
||||
if (val.get_infinitesimal().is_neg()) {
|
||||
return m_util.mk_ge(obj, e);
|
||||
e = m_util.mk_ge(obj, e);
|
||||
}
|
||||
else {
|
||||
return m_util.mk_gt(obj, e);
|
||||
e = m_util.mk_gt(obj, e);
|
||||
}
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -308,9 +308,9 @@ namespace smt {
|
|||
//
|
||||
// -----------------------------------
|
||||
|
||||
virtual inf_eps_rational<inf_rational> maximize(theory_var v);
|
||||
virtual inf_eps_rational<inf_rational> maximize(theory_var v, expr_ref& blocker);
|
||||
virtual theory_var add_objective(app* term);
|
||||
virtual expr* mk_gt(theory_var v, inf_rational const& val);
|
||||
virtual expr_ref 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);
|
||||
|
|
|
@ -999,10 +999,11 @@ void theory_diff_logic<Ext>::get_implied_bound_antecedents(edge_id bridge_edge,
|
|||
}
|
||||
|
||||
template<typename Ext>
|
||||
inf_eps_rational<inf_rational> theory_diff_logic<Ext>::maximize(theory_var v) {
|
||||
inf_eps_rational<inf_rational> theory_diff_logic<Ext>::maximize(theory_var v, expr_ref& blocker) {
|
||||
|
||||
typedef simplex::simplex<simplex::mpq_ext> Simplex;
|
||||
Simplex S;
|
||||
ast_manager& m = get_manager();
|
||||
objective_term const& objective = m_objectives[v];
|
||||
|
||||
IF_VERBOSE(1,
|
||||
|
@ -1067,30 +1068,37 @@ inf_eps_rational<inf_rational> theory_diff_logic<Ext>::maximize(theory_var v) {
|
|||
// optimize
|
||||
lbool is_sat = S.make_feasible();
|
||||
if (is_sat == l_undef) {
|
||||
blocker = m.mk_false();
|
||||
return inf_eps_rational<inf_rational>::infinity();
|
||||
}
|
||||
TRACE("opt", S.display(tout); );
|
||||
TRACE("opt", S.display(tout); );
|
||||
SASSERT(is_sat != l_false);
|
||||
lbool is_fin = S.minimize(w);
|
||||
switch (is_fin) {
|
||||
case l_true: {
|
||||
simplex::mpq_ext::eps_numeral const& val = S.get_value(w);
|
||||
inf_rational r(-rational(val.first), -rational(val.second));
|
||||
TRACE("opt", tout << r << " " << "\n"; );
|
||||
TRACE("opt", tout << r << " " << "\n";
|
||||
S.display_row(tout, row, true););
|
||||
Simplex::row_iterator it = S.row_begin(row), end = S.row_end(row);
|
||||
S.display_row(std::cout, row, true);
|
||||
expr_ref_vector& core = m_objective_assignments[v];
|
||||
expr_ref tmp(m);
|
||||
core.reset();
|
||||
for (; it != end; ++it) {
|
||||
unsigned v = it->m_var;
|
||||
if (num_nodes <= v && v < num_nodes + num_edges) {
|
||||
unsigned edge_id = v - num_nodes;
|
||||
literal lit = m_graph.get_explanation(edge_id);
|
||||
std::cout << lit << "\n";
|
||||
get_context().literal2expr(lit, tmp);
|
||||
core.push_back(tmp);
|
||||
}
|
||||
}
|
||||
blocker = mk_gt(v, r);
|
||||
return inf_eps_rational<inf_rational>(rational(0), r);
|
||||
}
|
||||
default:
|
||||
TRACE("opt", tout << "unbounded\n"; );
|
||||
blocker = m.mk_false();
|
||||
return inf_eps_rational<inf_rational>::infinity();
|
||||
}
|
||||
}
|
||||
|
@ -1135,7 +1143,9 @@ expr_ref theory_diff_logic<Ext>::block_objective(theory_var v, inf_rational cons
|
|||
}
|
||||
else {
|
||||
//
|
||||
f = m.mk_true();
|
||||
expr_ref_vector const& core = m_objective_assignments[v];
|
||||
f = m.mk_not(m.mk_and(core.size(), core.c_ptr()));
|
||||
TRACE("arith", tout << "block: " << f << "\n";);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
@ -1152,8 +1162,10 @@ expr_ref theory_diff_logic<Ext>::block_objective(theory_var v, inf_rational cons
|
|||
}
|
||||
|
||||
template<typename Ext>
|
||||
expr* theory_diff_logic<Ext>::mk_gt(theory_var v, inf_rational const& val) {
|
||||
expr_ref theory_diff_logic<Ext>::mk_gt(theory_var v, inf_rational const& val) {
|
||||
expr_ref o = block_objective(v, val);
|
||||
return o;
|
||||
#if 0
|
||||
context & ctx = get_context();
|
||||
model_ref mdl;
|
||||
ctx.get_model(mdl);
|
||||
|
@ -1162,6 +1174,7 @@ expr* theory_diff_logic<Ext>::mk_gt(theory_var v, inf_rational const& val) {
|
|||
model_implicant impl_extractor(m);
|
||||
expr_ref_vector implicants = impl_extractor.minimize_literals(formulas, mdl);
|
||||
return m.mk_and(o, m.mk_not(m.mk_and(implicants.size(), implicants.c_ptr())));
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename Ext>
|
||||
|
|
|
@ -29,9 +29,8 @@ namespace smt {
|
|||
class theory_opt {
|
||||
public:
|
||||
typedef inf_eps_rational<inf_rational> inf_eps;
|
||||
virtual inf_eps maximize(theory_var v) { UNREACHABLE(); return inf_eps::infinity(); }
|
||||
virtual inf_eps maximize(theory_var v, expr_ref& blocker) = 0; // { UNREACHABLE(); return inf_eps::infinity(); }
|
||||
virtual theory_var add_objective(app* term) { UNREACHABLE(); return null_theory_var; }
|
||||
virtual expr* mk_gt(theory_var v, inf_rational const& val) { UNREACHABLE(); return 0; }
|
||||
virtual expr* mk_ge(filter_model_converter& fm, theory_var v, inf_eps const& val) { UNREACHABLE(); return 0; }
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue