3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 09:05:31 +00:00

remove min/max, use qmax; disable cancellation during model evaluation

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2016-05-19 13:04:20 -07:00
parent d2622da747
commit 1aa3fdab8a
12 changed files with 19 additions and 234 deletions

View file

@ -137,81 +137,12 @@ public:
}
};
class alternate_min_max_cmd : public cmd {
app_ref_vector* m_vars;
svector<bool> m_is_max;
unsigned m_position;
app_ref_vector& vars(cmd_context& ctx) {
if (!m_vars) {
m_vars = alloc(app_ref_vector, ctx.m());
}
return *m_vars;
}
public:
alternate_min_max_cmd():
cmd("min-max"),
m_vars(0),
m_position(0)
{}
virtual void reset(cmd_context & ctx) {
dealloc(m_vars);
m_vars = 0;
m_is_max.reset();
m_position = 0;
}
virtual char const * get_usage() const { return "(min | max | var)+ <term>"; }
virtual char const * get_descr(cmd_context & ctx) const { return "check sat modulo alternating min-max objectives";}
virtual unsigned get_arity() const { return 2; }
virtual void prepare(cmd_context & ctx) {}
virtual cmd_arg_kind next_arg_kind(cmd_context & ctx) const {
switch (m_position) {
case 0: return CPK_SYMBOL_LIST;
case 1: return CPK_EXPR;
default: return CPK_SYMBOL;
}
}
virtual void set_next_arg(cmd_context & ctx, unsigned num, symbol const * slist) {
bool is_max = false;
for (unsigned i = 0; i < num; ++i) {
if (slist[i] == symbol("max")) {
is_max = true;
}
else if (slist[i] == symbol("min")) {
is_max = false;
}
else {
m_is_max.push_back(is_max);
vars(ctx).push_back(ctx.m().mk_const(ctx.find_func_decl(slist[i])));
}
}
++m_position;
}
virtual void set_next_arg(cmd_context & ctx, expr * t) {
if (!is_app(t)) {
throw cmd_exception("malformed objective term: it cannot be a quantifier or bound variable");
}
++m_position;
get_opt(ctx).min_max(to_app(t), vars(ctx), m_is_max);
reset(ctx);
}
virtual void failure_cleanup(cmd_context & ctx) {
reset(ctx);
}
virtual void execute(cmd_context & ctx) { }
};
void install_opt_cmds(cmd_context & ctx) {
ctx.insert(alloc(assert_soft_cmd));
ctx.insert(alloc(min_maximize_cmd, true));
ctx.insert(alloc(min_maximize_cmd, false));
ctx.insert(alloc(alternate_min_max_cmd));
}

View file

@ -212,18 +212,6 @@ namespace opt {
m_hard_constraints.append(s.m_hard);
}
lbool context::min_max(app* t, app_ref_vector const& vars, svector<bool> const& is_max) {
clear_state();
init_solver();
import_scoped_state();
normalize();
internalize();
qe::max_min_opt max_min(m, m_params);
max_min.add(m_hard_constraints);
return max_min.check(is_max, vars, t);
}
lbool context::optimize() {
if (m_pareto) {
return execute_pareto();
@ -236,12 +224,12 @@ namespace opt {
import_scoped_state();
normalize();
internalize();
update_solver();
#if 0
if (is_qsat_opt()) {
return run_qsat_opt();
}
#endif
update_solver();
solver& s = get_solver();
s.assert_expr(m_hard_constraints);
display_benchmark();
@ -1473,6 +1461,7 @@ namespace opt {
value.neg();
}
if (result != l_undef) {
m_optsmt.setup(*m_opt_solver.get());
m_optsmt.update_lower(obj.m_index, value);
m_optsmt.update_upper(obj.m_index, value);
}

View file

@ -172,7 +172,6 @@ namespace opt {
virtual ~context();
unsigned add_soft_constraint(expr* f, rational const& w, symbol const& id);
unsigned add_objective(app* t, bool is_max);
lbool min_max(app* t, app_ref_vector const& vars, svector<bool> const& is_max);
void add_hard_constraint(expr* f);

View file

@ -344,6 +344,10 @@ namespace opt {
}
expr_ref opt_solver::mk_ge(unsigned var, inf_eps const& val) {
if (!val.is_finite())
{
return expr_ref(val.is_pos() ? m.mk_false() : m.mk_true(), m);
}
smt::theory_opt& opt = get_optimizer();
smt::theory_var v = m_objective_vars[var];