3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-08 18:31:49 +00:00

separate MaxSMT functionality to enable using this independently (and incrementally) of overall context

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2015-02-16 09:11:28 +01:00
parent ded635cd06
commit 911ffc370a
16 changed files with 72 additions and 40 deletions

View file

@ -99,7 +99,7 @@ namespace opt {
}
public:
bcd2(context& c,
bcd2(maxsat_context& c,
weights_t& ws, expr_ref_vector const& soft):
maxsmt_solver_base(c, ws, soft),
pb(m),
@ -399,7 +399,7 @@ namespace opt {
};
maxsmt_solver_base* mk_bcd2(
context& c, weights_t& ws, expr_ref_vector const& soft) {
maxsat_context& c, weights_t& ws, expr_ref_vector const& soft) {
return alloc(bcd2, c, ws, soft);
}

View file

@ -23,6 +23,6 @@ Notes:
#include "maxsmt.h"
namespace opt {
maxsmt_solver_base* mk_bcd2(context& c, weights_t& ws, expr_ref_vector const& soft);
maxsmt_solver_base* mk_bcd2(maxsat_context& c, weights_t& ws, expr_ref_vector const& soft);
}
#endif

View file

@ -50,7 +50,7 @@ namespace opt {
model_ref m_model;
public:
fu_malik(context& c, weights_t& ws, expr_ref_vector const& soft):
fu_malik(maxsat_context& c, weights_t& ws, expr_ref_vector const& soft):
maxsmt_solver_base(c, ws, soft),
m_fm(c.fm()),
m_aux_soft(soft),
@ -229,7 +229,7 @@ namespace opt {
}
};
maxsmt_solver_base* mk_fu_malik(context& c, weights_t & ws, expr_ref_vector const& soft) {
maxsmt_solver_base* mk_fu_malik(maxsat_context& c, weights_t & ws, expr_ref_vector const& soft) {
return alloc(fu_malik, c, ws, soft);
}

View file

@ -29,7 +29,7 @@ Notes:
namespace opt {
maxsmt_solver_base* mk_fu_malik(context& c, weights_t & ws, expr_ref_vector const& soft);
maxsmt_solver_base* mk_fu_malik(maxsat_context& c, weights_t & ws, expr_ref_vector const& soft);
};

View file

@ -75,7 +75,7 @@ namespace opt {
public:
maxhs(context& c, weights_t& ws, expr_ref_vector const& soft):
maxhs(maxsat_context& c, weights_t& ws, expr_ref_vector const& soft):
maxsmt_solver_base(c, ws, soft),
m_aux(m),
m_at_lower_bound(false) {
@ -554,7 +554,7 @@ namespace opt {
};
maxsmt_solver_base* mk_maxhs(
context& c, weights_t& ws, expr_ref_vector const& soft) {
maxsat_context& c, weights_t& ws, expr_ref_vector const& soft) {
return alloc(maxhs, c, ws, soft);
}

View file

@ -23,7 +23,7 @@ Notes:
#include "maxsmt.h"
namespace opt {
maxsmt_solver_base* mk_maxhs(context& c,
maxsmt_solver_base* mk_maxhs(maxsat_context& c,
weights_t& ws, expr_ref_vector const& soft);
}
#endif

View file

@ -107,7 +107,7 @@ private:
typedef ptr_vector<expr> exprs;
public:
maxres(context& c,
maxres(maxsat_context& c,
weights_t& ws, expr_ref_vector const& soft,
strategy_t st):
maxsmt_solver_base(c, ws, soft),
@ -788,12 +788,12 @@ public:
};
opt::maxsmt_solver_base* opt::mk_maxres(
context& c, weights_t& ws, expr_ref_vector const& soft) {
maxsat_context& c, weights_t& ws, expr_ref_vector const& soft) {
return alloc(maxres, c, ws, soft, maxres::s_primal);
}
opt::maxsmt_solver_base* opt::mk_primal_dual_maxres(
context& c, weights_t& ws, expr_ref_vector const& soft) {
maxsat_context& c, weights_t& ws, expr_ref_vector const& soft) {
return alloc(maxres, c, ws, soft, maxres::s_primal_dual);
}

View file

@ -22,9 +22,9 @@ Notes:
namespace opt {
maxsmt_solver_base* mk_maxres(context& c, weights_t & ws, expr_ref_vector const& soft);
maxsmt_solver_base* mk_maxres(maxsat_context& c, weights_t & ws, expr_ref_vector const& soft);
maxsmt_solver_base* mk_primal_dual_maxres(context& c, weights_t & ws, expr_ref_vector const& soft);
maxsmt_solver_base* mk_primal_dual_maxres(maxsat_context& c, weights_t & ws, expr_ref_vector const& soft);
};

View file

@ -26,7 +26,7 @@ namespace opt {
class sls : public maxsmt_solver_base {
public:
sls(context& c, weights_t& ws, expr_ref_vector const& soft):
sls(maxsat_context& c, weights_t& ws, expr_ref_vector const& soft):
maxsmt_solver_base(c, ws, soft) {
}
virtual ~sls() {}
@ -54,7 +54,7 @@ namespace opt {
};
maxsmt_solver_base* mk_sls(
context& c, weights_t& ws, expr_ref_vector const& soft) {
maxsat_context& c, weights_t& ws, expr_ref_vector const& soft) {
return alloc(sls, c, ws, soft);
}

View file

@ -27,7 +27,7 @@ Notes:
namespace opt {
maxsmt_solver_base* mk_sls(context& c, weights_t& ws, expr_ref_vector const& soft);
maxsmt_solver_base* mk_sls(maxsat_context& c, weights_t& ws, expr_ref_vector const& soft);
};

View file

@ -36,7 +36,7 @@ Notes:
namespace opt {
maxsmt_solver_base::maxsmt_solver_base(
context& c, vector<rational> const& ws, expr_ref_vector const& soft):
maxsat_context& c, vector<rational> const& ws, expr_ref_vector const& soft):
m(c.get_manager()),
m_c(c),
m_cancel(false),
@ -156,7 +156,7 @@ namespace opt {
maxsmt::maxsmt(context& c):
maxsmt::maxsmt(maxsat_context& c):
m(c.get_manager()), m_c(c), m_cancel(false),
m_soft_constraints(m), m_answer(m) {}

View file

@ -33,7 +33,7 @@ namespace opt {
typedef vector<rational> const weights_t;
class context;
class maxsat_context;
class maxsmt_solver {
protected:
@ -59,7 +59,7 @@ namespace opt {
class maxsmt_solver_base : public maxsmt_solver {
protected:
ast_manager& m;
context& m_c;
maxsat_context& m_c;
volatile bool m_cancel;
const expr_ref_vector m_soft;
vector<rational> m_weights;
@ -71,7 +71,7 @@ namespace opt {
params_ref m_params; // config
public:
maxsmt_solver_base(context& c, weights_t& ws, expr_ref_vector const& soft);
maxsmt_solver_base(maxsat_context& c, weights_t& ws, expr_ref_vector const& soft);
virtual ~maxsmt_solver_base() {}
virtual rational get_lower() const { return m_lower; }
@ -114,7 +114,7 @@ namespace opt {
class maxsmt {
ast_manager& m;
context& m_c;
maxsat_context& m_c;
scoped_ptr<maxsmt_solver_base> m_msolver;
volatile bool m_cancel;
expr_ref_vector m_soft_constraints;
@ -126,7 +126,7 @@ namespace opt {
model_ref m_model;
params_ref m_params;
public:
maxsmt(context& c);
maxsmt(maxsat_context& c);
lbool operator()();
void set_cancel(bool f);
void updt_params(params_ref& p);

View file

@ -34,8 +34,40 @@ namespace opt {
class opt_solver;
/**
\brief base class required by MaxSMT solvers.
By implementing a base class, you can invoke the MaxSMT solvers
independent of the overall optimization infrastructure.
The caller has to supply a solver object that encapsulates
an incremental SAT or SMT solver. The MaxSMT solvers may assume that
the solver object should be in a satisfiable state and contain an initial model.
*/
class context : public opt_wrapper, public pareto_callback {
class maxsat_context {
public:
virtual filter_model_converter& fm() = 0; // converter that removes fresh names introduced by simplification.
virtual bool sat_enabled() const = 0; // is using th SAT solver core enabled?
virtual solver& get_solver() = 0; // retrieve solver object (SAT or SMT solver)
virtual ast_manager& get_manager() = 0;
virtual params_ref& params() = 0;
virtual void enable_sls(expr_ref_vector const& soft, weights_t& weights) = 0; // stochastic local search
virtual void set_enable_sls(bool f) = 0; // overwrite whether SLS is enabled.
virtual void set_soft_assumptions() = 0; // configure SAT solver to skip assumptions assigned by unit-propagation
virtual symbol const& maxsat_engine() const = 0; // retrieve maxsat engine configuration parameter.
virtual void get_base_model(model_ref& _m) = 0; // retrieve model from initial satisfiability call.
virtual smt::context& smt_context() = 0; // access SMT context for SMT based MaxSMT solver (wmax requires SMT core)
};
/**
\brief main context object for optimization.
Hard and soft assertions, and objectives are registered with this context.
It handles combinations of objectives.
*/
class context :
public opt_wrapper,
public pareto_callback,
public maxsat_context {
struct free_func_visitor;
typedef map<symbol, maxsmt*, symbol_hash_proc, symbol_eq_proc> map_t;
typedef map<symbol, unsigned, symbol_hash_proc, symbol_eq_proc> map_id;
@ -176,17 +208,17 @@ namespace opt {
virtual expr_ref mk_ge(unsigned i, model_ref& model);
virtual expr_ref mk_le(unsigned i, model_ref& model);
smt::context& smt_context() { return m_opt_solver->get_context(); }
filter_model_converter& fm() { return m_fm; }
bool sat_enabled() const { return 0 != m_sat_solver.get(); }
solver& get_solver();
ast_manager& get_manager() { return this->m; }
params_ref& params() { return m_params; }
void enable_sls(expr_ref_vector const& soft, weights_t& weights);
void set_enable_sls(bool f) { m_enable_sls = f; }
void set_soft_assumptions();
symbol const& maxsat_engine() const { return m_maxsat_engine; }
void get_base_model(model_ref& _m);
virtual smt::context& smt_context() { return m_opt_solver->get_context(); }
virtual filter_model_converter& fm() { return m_fm; }
virtual bool sat_enabled() const { return 0 != m_sat_solver.get(); }
virtual solver& get_solver();
virtual ast_manager& get_manager() { return this->m; }
virtual params_ref& params() { return m_params; }
virtual void enable_sls(expr_ref_vector const& soft, weights_t& weights);
virtual void set_enable_sls(bool f) { m_enable_sls = f; }
virtual void set_soft_assumptions();
virtual symbol const& maxsat_engine() const { return m_maxsat_engine; }
virtual void get_base_model(model_ref& _m);
private:

View file

@ -33,7 +33,7 @@ namespace opt {
class wmax : public maxsmt_solver_base {
public:
wmax(context& c, weights_t& ws, expr_ref_vector const& soft):
wmax(maxsat_context& c, weights_t& ws, expr_ref_vector const& soft):
maxsmt_solver_base(c, ws, soft) {}
virtual ~wmax() {}
@ -76,7 +76,7 @@ namespace opt {
}
};
maxsmt_solver_base* mk_wmax(context& c, weights_t& ws, expr_ref_vector const& soft) {
maxsmt_solver_base* mk_wmax(maxsat_context& c, weights_t& ws, expr_ref_vector const& soft) {
return alloc(wmax, c, ws, soft);
}

View file

@ -23,7 +23,7 @@ Notes:
#include "maxsmt.h"
namespace opt {
maxsmt_solver_base* mk_wmax(context& c, weights_t & ws, expr_ref_vector const& soft);
maxsmt_solver_base* mk_wmax(maxsat_context& c, weights_t & ws, expr_ref_vector const& soft);
}
#endif

View file

@ -372,7 +372,7 @@ namespace smt {
tout << "js.kind: " << js.get_kind() << "\n";
tout << "consequent: " << consequent << "\n";
for (unsigned i = 0; i < m_assigned_literals.size(); ++i) {
tout << m_assigned_literals[i] << " ";
tout << m_assigned_literals[i] << " ";
}
tout << "\n";
);