3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-29 11:55:51 +00:00

integrate opt with push/pop/check-sat

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2014-03-22 16:15:50 -07:00
parent 7c4bd23b3d
commit fdaeb9bb73
7 changed files with 207 additions and 191 deletions

View file

@ -353,6 +353,17 @@ void cmd_context::set_cancel(bool f) {
m().set_cancel(f);
}
opt_wrapper* cmd_context::get_opt() {
return m_opt.get();
}
void cmd_context::set_opt(opt_wrapper* opt) {
m_opt = opt;
for (unsigned i = 0; i < m_scopes.size(); ++i) {
m_opt->push();
}
}
void cmd_context::global_params_updated() {
m_params.updt_params();
if (m_params.m_smtlib2_compliant)
@ -1161,6 +1172,7 @@ void cmd_context::reset(bool finalize) {
restore_assertions(0);
if (m_solver)
m_solver = 0;
m_opt = 0;
m_pp_env = 0;
m_dt_eh = 0;
if (m_manager) {
@ -1226,6 +1238,8 @@ void cmd_context::push() {
s.m_assertions_lim = m_assertions.size();
if (m_solver)
m_solver->push();
if (m_opt)
m_opt->push();
}
void cmd_context::push(unsigned n) {
@ -1321,6 +1335,8 @@ void cmd_context::pop(unsigned n) {
if (m_solver) {
m_solver->pop(n);
}
if (m_opt)
m_opt->pop(n);
unsigned new_lvl = lvl - n;
scope & s = m_scopes[new_lvl];
restore_func_decls(s.m_func_decls_stack_lim);
@ -1338,15 +1354,35 @@ void cmd_context::check_sat(unsigned num_assumptions, expr * const * assumptions
TRACE("before_check_sat", dump_assertions(tout););
if (!has_manager())
init_manager();
if (m_solver) {
unsigned timeout = m_params.m_timeout;
scoped_watch sw(*this);
lbool r;
if (m_opt && !m_opt->empty()) {
m_check_sat_result = get_opt();
cancel_eh<opt_wrapper> eh(*get_opt());
scoped_ctrl_c ctrlc(eh);
scoped_timer timer(timeout, &eh);
ptr_vector<expr> cnstr(m_assertions);
cnstr.append(num_assumptions, assumptions);
get_opt()->set_hard_constraints(cnstr);
try {
r = get_opt()->optimize();
}
catch (z3_error & ex) {
throw ex;
}
catch (z3_exception & ex) {
throw cmd_exception(ex.msg());
}
get_opt()->set_status(r);
}
else if (m_solver) {
m_check_sat_result = m_solver.get(); // solver itself stores the result.
m_solver->set_progress_callback(this);
unsigned timeout = m_params.m_timeout;
scoped_watch sw(*this);
cancel_eh<solver> eh(*m_solver);
scoped_ctrl_c ctrlc(eh);
scoped_timer timer(timeout, &eh);
lbool r;
try {
r = m_solver->check_sat(num_assumptions, assumptions);
}
@ -1357,15 +1393,17 @@ void cmd_context::check_sat(unsigned num_assumptions, expr * const * assumptions
throw cmd_exception(ex.msg());
}
m_solver->set_status(r);
display_sat_result(r);
validate_check_sat_result(r);
if (r == l_true)
validate_model();
}
else {
// There is no solver installed in the command context.
regular_stream() << "unknown" << std::endl;
return;
}
display_sat_result(r);
validate_check_sat_result(r);
if (r == l_true)
validate_model();
}
void cmd_context::display_sat_result(lbool r) {