mirror of
https://github.com/Z3Prover/z3
synced 2025-06-21 05:13:39 +00:00
nits
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
21058c38fd
commit
b573b94f84
8 changed files with 20 additions and 24 deletions
|
@ -138,7 +138,7 @@ namespace opt {
|
||||||
lbool operator()() {
|
lbool operator()() {
|
||||||
lbool is_sat = s.check_sat(0,0);
|
lbool is_sat = s.check_sat(0,0);
|
||||||
if (!m_soft.empty() && is_sat == l_true) {
|
if (!m_soft.empty() && is_sat == l_true) {
|
||||||
opt_solver::scoped_push _sp(s);
|
solver::scoped_push _sp(s);
|
||||||
|
|
||||||
lbool is_sat = l_true;
|
lbool is_sat = l_true;
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -51,13 +51,13 @@ namespace opt {
|
||||||
}
|
}
|
||||||
|
|
||||||
lbool context::optimize() {
|
lbool context::optimize() {
|
||||||
// TBD: add configurtion parameter
|
// TBD: add configuration parameter to select between box and pareto
|
||||||
return optimize_box();
|
return optimize_box();
|
||||||
}
|
}
|
||||||
|
|
||||||
lbool context::optimize_box() {
|
lbool context::optimize_box() {
|
||||||
opt_solver& s = *m_solver.get();
|
opt_solver& s = *m_solver.get();
|
||||||
opt_solver::scoped_push _sp(s);
|
solver::scoped_push _sp(s);
|
||||||
|
|
||||||
for (unsigned i = 0; i < m_hard_constraints.size(); ++i) {
|
for (unsigned i = 0; i < m_hard_constraints.size(); ++i) {
|
||||||
s.assert_expr(m_hard_constraints[i].get());
|
s.assert_expr(m_hard_constraints[i].get());
|
||||||
|
|
|
@ -49,8 +49,6 @@ namespace opt {
|
||||||
void add_objective(app* t, bool is_max) { m_optsmt.add(t, is_max); }
|
void add_objective(app* t, bool is_max) { m_optsmt.add(t, is_max); }
|
||||||
void add_hard_constraint(expr* f) { m_hard_constraints.push_back(f); }
|
void add_hard_constraint(expr* f) { m_hard_constraints.push_back(f); }
|
||||||
lbool optimize();
|
lbool optimize();
|
||||||
lbool optimize_pareto();
|
|
||||||
lbool optimize_box();
|
|
||||||
void set_cancel(bool f);
|
void set_cancel(bool f);
|
||||||
void reset_cancel() { set_cancel(false); }
|
void reset_cancel() { set_cancel(false); }
|
||||||
void cancel() { set_cancel(true); }
|
void cancel() { set_cancel(true); }
|
||||||
|
@ -59,6 +57,9 @@ namespace opt {
|
||||||
void display_range_assignment(std::ostream& out);
|
void display_range_assignment(std::ostream& out);
|
||||||
static void collect_param_descrs(param_descrs & r);
|
static void collect_param_descrs(param_descrs & r);
|
||||||
void updt_params(params_ref& p);
|
void updt_params(params_ref& p);
|
||||||
|
private:
|
||||||
|
lbool optimize_pareto();
|
||||||
|
lbool optimize_box();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,13 +85,6 @@ namespace opt {
|
||||||
~toggle_objective();
|
~toggle_objective();
|
||||||
};
|
};
|
||||||
|
|
||||||
class scoped_push {
|
|
||||||
solver& s;
|
|
||||||
public:
|
|
||||||
scoped_push(solver& s):s(s) { s.push(); }
|
|
||||||
~scoped_push() { s.pop(1); }
|
|
||||||
};
|
|
||||||
|
|
||||||
smt::context& get_context() { return m_context.get_context(); } // used by weighted maxsat.
|
smt::context& get_context() { return m_context.get_context(); } // used by weighted maxsat.
|
||||||
|
|
||||||
smt::theory_opt& get_optimizer();
|
smt::theory_opt& get_optimizer();
|
||||||
|
|
|
@ -37,8 +37,6 @@ Notes:
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
|
|
||||||
#ifndef _OPT_OBJECTIVE_H_
|
|
||||||
#define _OPT_OBJECTIVE_H_
|
|
||||||
|
|
||||||
#include "optsmt.h"
|
#include "optsmt.h"
|
||||||
#include "opt_solver.h"
|
#include "opt_solver.h"
|
||||||
|
@ -90,7 +88,6 @@ namespace opt {
|
||||||
lbool optsmt::farkas_opt() {
|
lbool optsmt::farkas_opt() {
|
||||||
smt::theory_opt& opt = s->get_optimizer();
|
smt::theory_opt& opt = s->get_optimizer();
|
||||||
|
|
||||||
IF_VERBOSE(1, verbose_stream() << typeid(opt).name() << "\n";);
|
|
||||||
if (typeid(smt::theory_inf_arith) != typeid(opt)) {
|
if (typeid(smt::theory_inf_arith) != typeid(opt)) {
|
||||||
return l_undef;
|
return l_undef;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +135,7 @@ namespace opt {
|
||||||
expr_ref bound(m);
|
expr_ref bound(m);
|
||||||
expr_ref_vector bounds(m);
|
expr_ref_vector bounds(m);
|
||||||
|
|
||||||
opt_solver::scoped_push _push(*s);
|
solver::scoped_push _push(*s);
|
||||||
|
|
||||||
//
|
//
|
||||||
// NB: we have to create all bound expressions before calling check_sat
|
// NB: we have to create all bound expressions before calling check_sat
|
||||||
|
@ -218,7 +215,7 @@ namespace opt {
|
||||||
// First check_sat call to initialize theories
|
// First check_sat call to initialize theories
|
||||||
lbool is_sat = s->check_sat(0, 0);
|
lbool is_sat = s->check_sat(0, 0);
|
||||||
if (is_sat == l_true && !m_objs.empty()) {
|
if (is_sat == l_true && !m_objs.empty()) {
|
||||||
opt_solver::scoped_push _push(*s);
|
solver::scoped_push _push(*s);
|
||||||
|
|
||||||
for (unsigned i = 0; i < m_objs.size(); ++i) {
|
for (unsigned i = 0; i < m_objs.size(); ++i) {
|
||||||
m_vars.push_back(s->add_objective(m_objs[i].get()));
|
m_vars.push_back(s->add_objective(m_objs[i].get()));
|
||||||
|
@ -289,8 +286,6 @@ namespace opt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void optsmt::add(app* t, bool is_max) {
|
void optsmt::add(app* t, bool is_max) {
|
||||||
expr_ref t1(t, m), t2(m);
|
expr_ref t1(t, m), t2(m);
|
||||||
th_rewriter rw(m);
|
th_rewriter rw(m);
|
||||||
|
@ -311,4 +306,3 @@ namespace opt {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ Author:
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
#ifndef _OPT_OBJECTIVES_H_
|
#ifndef _OPTSMT_H_
|
||||||
#define _OPT_OBJECTIVES_H_
|
#define _OPTSMT_H_
|
||||||
|
|
||||||
#include "opt_solver.h"
|
#include "opt_solver.h"
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ namespace opt {
|
||||||
void display_range_assignment(std::ostream& out) const;
|
void display_range_assignment(std::ostream& out) const;
|
||||||
|
|
||||||
unsigned get_num_objectives() const { return m_vars.size(); }
|
unsigned get_num_objectives() const { return m_vars.size(); }
|
||||||
void commit_assignment(unsigned i);
|
void commit_assignment(unsigned index);
|
||||||
inf_eps get_value(unsigned index) const;
|
inf_eps get_value(unsigned index) const;
|
||||||
inf_eps get_lower(unsigned index) const;
|
inf_eps get_lower(unsigned index) const;
|
||||||
inf_eps get_upper(unsigned index) const;
|
inf_eps get_upper(unsigned index) const;
|
||||||
|
|
|
@ -315,7 +315,7 @@ namespace opt {
|
||||||
smt::theory_weighted_maxsat& wth = ensure_theory();
|
smt::theory_weighted_maxsat& wth = ensure_theory();
|
||||||
lbool result;
|
lbool result;
|
||||||
{
|
{
|
||||||
opt_solver::scoped_push _s(s);
|
solver::scoped_push _s(s);
|
||||||
for (unsigned i = 0; i < m_soft.size(); ++i) {
|
for (unsigned i = 0; i < m_soft.size(); ++i) {
|
||||||
wth.assert_weighted(m_soft[i].get(), m_weights[i]);
|
wth.assert_weighted(m_soft[i].get(), m_weights[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,6 +130,14 @@ public:
|
||||||
\brief Display the content of this solver.
|
\brief Display the content of this solver.
|
||||||
*/
|
*/
|
||||||
virtual void display(std::ostream & out) const;
|
virtual void display(std::ostream & out) const;
|
||||||
|
|
||||||
|
class scoped_push {
|
||||||
|
solver& s;
|
||||||
|
public:
|
||||||
|
scoped_push(solver& s):s(s) { s.push(); }
|
||||||
|
~scoped_push() { s.pop(1); }
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue