3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-07-18 02:16:40 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2017-07-27 17:02:27 -07:00
commit b482dbd589
379 changed files with 7440 additions and 3352 deletions

21
src/opt/CMakeLists.txt Normal file
View file

@ -0,0 +1,21 @@
z3_add_component(opt
SOURCES
maxres.cpp
maxsmt.cpp
mss.cpp
opt_cmds.cpp
opt_context.cpp
opt_pareto.cpp
optsmt.cpp
opt_solver.cpp
pb_sls.cpp
sortmax.cpp
wmax.cpp
COMPONENT_DEPENDENCIES
sat_solver
sls_tactic
smt
smtlogic_tactics
PYG_FILES
opt_params.pyg
)

View file

@ -100,6 +100,7 @@ public:
rational weight = ps().get_rat(symbol("weight"), rational::one());
symbol id = ps().get_sym(symbol("id"), symbol::null);
get_opt(ctx, m_opt).add_soft_constraint(m_formula, weight, id);
ctx.print_success();
reset(ctx);
}
@ -131,6 +132,7 @@ public:
throw cmd_exception("malformed objective term: it cannot be a quantifier or bound variable");
}
get_opt(ctx, m_opt).add_objective(to_app(t), m_is_max);
ctx.print_success();
}
virtual void failure_cleanup(cmd_context & ctx) {
@ -141,12 +143,35 @@ public:
}
};
class get_objectives_cmd : public cmd {
opt::context* m_opt;
public:
get_objectives_cmd(opt::context* opt):
cmd("get-objectives"),
m_opt(opt)
{}
virtual void reset(cmd_context & ctx) { }
virtual char const * get_usage() const { return "(get-objectives)"; }
virtual char const * get_descr(cmd_context & ctx) const { return "retrieve the objective values (after optimization)"; }
virtual unsigned get_arity() const { return 0; }
virtual void prepare(cmd_context & ctx) {}
virtual void failure_cleanup(cmd_context & ctx) {
reset(ctx);
}
virtual void execute(cmd_context & ctx) {
get_opt(ctx, m_opt).display_assignment(ctx.regular_stream());
}
};
void install_opt_cmds(cmd_context & ctx, opt::context* opt) {
ctx.insert(alloc(assert_soft_cmd, opt));
ctx.insert(alloc(min_maximize_cmd, true, opt));
ctx.insert(alloc(min_maximize_cmd, false, opt));
ctx.insert(alloc(get_objectives_cmd, opt));
}

View file

@ -1317,17 +1317,18 @@ namespace opt {
rational r = n.get_rational();
rational eps = n.get_infinitesimal();
expr_ref_vector args(m);
bool is_int = eps.is_zero() && r.is_int();
if (!inf.is_zero()) {
expr* oo = m.mk_const(symbol("oo"), m_arith.mk_int());
expr* oo = m.mk_const(symbol("oo"), is_int ? m_arith.mk_int() : m_arith.mk_real());
if (inf.is_one()) {
args.push_back(oo);
}
else {
args.push_back(m_arith.mk_mul(m_arith.mk_numeral(inf, inf.is_int()), oo));
args.push_back(m_arith.mk_mul(m_arith.mk_numeral(inf, is_int), oo));
}
}
if (!r.is_zero()) {
args.push_back(m_arith.mk_numeral(r, r.is_int()));
args.push_back(m_arith.mk_numeral(r, is_int));
}
if (!eps.is_zero()) {
expr* ep = m.mk_const(symbol("epsilon"), m_arith.mk_real());
@ -1335,7 +1336,7 @@ namespace opt {
args.push_back(ep);
}
else {
args.push_back(m_arith.mk_mul(m_arith.mk_numeral(eps, eps.is_int()), ep));
args.push_back(m_arith.mk_mul(m_arith.mk_numeral(eps, is_int), ep));
}
}
switch(args.size()) {

View file

@ -216,7 +216,7 @@ namespace opt {
rational remove_negations(smt::theory_wmaxsat& th, expr_ref_vector const& core, ptr_vector<expr>& keys, vector<rational>& weights) {
rational min_weight(-1);
for (unsigned i = 0; i < core.size(); ++i) {
expr* e;
expr* e = 0;
VERIFY(m.is_not(core[i], e));
keys.push_back(m_keys[e]);
rational weight = m_weights[e];