mirror of
https://github.com/Z3Prover/z3
synced 2025-05-13 18:54:43 +00:00
fix up pareto callback mechanism
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
1ea376e310
commit
03979fd580
8 changed files with 178 additions and 144 deletions
|
@ -20,6 +20,7 @@ Notes:
|
|||
|
||||
#include "opt_pareto.h"
|
||||
#include "ast_pp.h"
|
||||
#include "model_smt2_pp.h"
|
||||
|
||||
namespace opt {
|
||||
|
||||
|
@ -27,43 +28,39 @@ namespace opt {
|
|||
// GIA pareto algorithm
|
||||
|
||||
lbool gia_pareto::operator()() {
|
||||
model_ref model;
|
||||
expr_ref fml(m);
|
||||
lbool is_sat = m_solver->check_sat(0, 0);
|
||||
while (is_sat == l_true) {
|
||||
if (is_sat == l_true) {
|
||||
{
|
||||
solver::scoped_push _s(*m_solver.get());
|
||||
while (is_sat == l_true) {
|
||||
if (m_cancel) {
|
||||
return l_undef;
|
||||
}
|
||||
m_solver->get_model(model);
|
||||
m_solver->get_model(m_model);
|
||||
IF_VERBOSE(1, model_smt2_pp(verbose_stream() << "new model:\n", m, *m_model, 0););
|
||||
// TBD: we can also use local search to tune solution coordinate-wise.
|
||||
mk_dominates(model);
|
||||
mk_dominates();
|
||||
is_sat = m_solver->check_sat(0, 0);
|
||||
}
|
||||
if (is_sat == l_undef) {
|
||||
return l_undef;
|
||||
}
|
||||
is_sat = l_true;
|
||||
}
|
||||
cb.yield(model);
|
||||
mk_not_dominated_by(model);
|
||||
is_sat = m_solver->check_sat(0, 0);
|
||||
if (is_sat == l_undef) {
|
||||
return l_undef;
|
||||
}
|
||||
SASSERT(is_sat == l_false);
|
||||
is_sat = l_true;
|
||||
mk_not_dominated_by();
|
||||
}
|
||||
if (is_sat == l_undef) {
|
||||
return l_undef;
|
||||
}
|
||||
return l_true;
|
||||
return is_sat;
|
||||
}
|
||||
|
||||
void pareto_base::mk_dominates(model_ref& model) {
|
||||
void pareto_base::mk_dominates() {
|
||||
unsigned sz = cb.num_objectives();
|
||||
expr_ref fml(m);
|
||||
expr_ref_vector gt(m), fmls(m);
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
fmls.push_back(cb.mk_ge(i, model));
|
||||
gt.push_back(cb.mk_gt(i, model));
|
||||
fmls.push_back(cb.mk_ge(i, m_model));
|
||||
gt.push_back(cb.mk_gt(i, m_model));
|
||||
}
|
||||
fmls.push_back(m.mk_or(gt.size(), gt.c_ptr()));
|
||||
fml = m.mk_and(fmls.size(), fmls.c_ptr());
|
||||
|
@ -71,12 +68,12 @@ namespace opt {
|
|||
m_solver->assert_expr(fml);
|
||||
}
|
||||
|
||||
void pareto_base::mk_not_dominated_by(model_ref& model) {
|
||||
void pareto_base::mk_not_dominated_by() {
|
||||
unsigned sz = cb.num_objectives();
|
||||
expr_ref fml(m);
|
||||
expr_ref_vector le(m);
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
le.push_back(cb.mk_le(i, model));
|
||||
le.push_back(cb.mk_le(i, m_model));
|
||||
}
|
||||
fml = m.mk_not(m.mk_and(le.size(), le.c_ptr()));
|
||||
IF_VERBOSE(10, verbose_stream() << "not dominated by: " << fml << "\n";);
|
||||
|
@ -87,25 +84,16 @@ namespace opt {
|
|||
// OIA algorithm (without filtering)
|
||||
|
||||
lbool oia_pareto::operator()() {
|
||||
model_ref model;
|
||||
solver::scoped_push _s(*m_solver.get());
|
||||
lbool is_sat = m_solver->check_sat(0, 0);
|
||||
if (is_sat != l_true) {
|
||||
return is_sat;
|
||||
}
|
||||
while (is_sat == l_true) {
|
||||
if (m_cancel) {
|
||||
return l_undef;
|
||||
}
|
||||
m_solver->get_model(model);
|
||||
cb.yield(model);
|
||||
mk_not_dominated_by(model);
|
||||
is_sat = m_solver->check_sat(0, 0);
|
||||
}
|
||||
if (m_cancel) {
|
||||
return l_undef;
|
||||
is_sat = l_undef;
|
||||
}
|
||||
return l_true;
|
||||
if (is_sat == l_true) {
|
||||
m_solver->get_model(m_model);
|
||||
mk_not_dominated_by();
|
||||
}
|
||||
return is_sat;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue