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

A rudimentary version of MathSAT optimization

Remarks:
(1) The core procedure accepts maximization only
(2) Add lazy initialization to min_maximize_cmd
(3) The procedure isn't working with composite objective yet.
This commit is contained in:
Anh-Dung Phan 2013-10-18 18:00:24 -07:00
parent 898609a3ef
commit a44044fb15
8 changed files with 114 additions and 33 deletions

View file

@ -855,6 +855,7 @@ namespace smt {
theory_var pick_var_to_leave(theory_var x_j, bool inc, numeral & a_ij, inf_numeral & gain);
template<bool invert>
void add_tmp_row_entry(row & r, numeral const & coeff, theory_var v);
bool max_min(theory_var v, bool max);
bool max_min(row & r, bool max);
bool max_min(svector<theory_var> const & vars);
@ -991,8 +992,10 @@ namespace smt {
// Optimization
//
// -----------------------------------
virtual bool max_min(theory_var v, bool max);
virtual bool max(theory_var v) { return max_min(v, true); }
virtual theory_var add_objective(app* term);
virtual optional<rational> get_objective_value(theory_var v);
inf_rational m_objective;
// -----------------------------------
//

View file

@ -956,7 +956,16 @@ namespace smt {
template<typename Ext>
theory_var theory_arith<Ext>::add_objective(app* term) {
return internalize_term(term);
return internalize_term_core(term);
}
template<typename Ext>
optional<rational> theory_arith<Ext>::get_objective_value(theory_var v) {
optional<rational> rat;
if (m_objective.is_rational()) {
rat = m_objective.get_rational();
};
return rat;
}
/**
@ -1106,7 +1115,7 @@ namespace smt {
\brief Maximize/Minimize the given variable. The bounds of v are update if procedure succeeds.
*/
template<typename Ext>
bool theory_arith<Ext>::max_min(theory_var v, bool max) {
bool theory_arith<Ext>::max_min(theory_var v, bool max) {
TRACE("maximize", tout << (max ? "maximizing" : "minimizing") << " v" << v << "...\n";);
SASSERT(valid_row_assignment());
SASSERT(satisfy_bounds());
@ -1130,7 +1139,10 @@ namespace smt {
TRACE("maximize", tout << "v" << v << " " << (max ? "max" : "min") << " value is: " << get_value(v) << "\n";
display_row(tout, m_tmp_row, true); display_row_info(tout, m_tmp_row););
m_objective = get_value(v);
mk_bound_from_row(v, get_value(v), max ? B_UPPER : B_LOWER, m_tmp_row);
return true;
}
return false;

View file

@ -24,8 +24,9 @@ Notes:
namespace smt {
class theory_opt {
public:
virtual bool max_min(theory_var v, bool max) { UNREACHABLE(); return false; };
virtual bool max(theory_var v) { UNREACHABLE(); return false; };
virtual theory_var add_objective(app* term) { UNREACHABLE(); return null_theory_var; }
virtual optional<rational> get_objective_value(theory_var v) { UNREACHABLE(); optional<rational> r; return r;}
};
}