mirror of
https://github.com/Z3Prover/z3
synced 2025-06-23 06:13:40 +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:
parent
ded635cd06
commit
911ffc370a
16 changed files with 72 additions and 40 deletions
|
@ -99,7 +99,7 @@ namespace opt {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bcd2(context& c,
|
bcd2(maxsat_context& c,
|
||||||
weights_t& ws, expr_ref_vector const& soft):
|
weights_t& ws, expr_ref_vector const& soft):
|
||||||
maxsmt_solver_base(c, ws, soft),
|
maxsmt_solver_base(c, ws, soft),
|
||||||
pb(m),
|
pb(m),
|
||||||
|
@ -399,7 +399,7 @@ namespace opt {
|
||||||
};
|
};
|
||||||
|
|
||||||
maxsmt_solver_base* mk_bcd2(
|
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);
|
return alloc(bcd2, c, ws, soft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,6 @@ Notes:
|
||||||
#include "maxsmt.h"
|
#include "maxsmt.h"
|
||||||
|
|
||||||
namespace opt {
|
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
|
#endif
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace opt {
|
||||||
model_ref m_model;
|
model_ref m_model;
|
||||||
|
|
||||||
public:
|
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),
|
maxsmt_solver_base(c, ws, soft),
|
||||||
m_fm(c.fm()),
|
m_fm(c.fm()),
|
||||||
m_aux_soft(soft),
|
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);
|
return alloc(fu_malik, c, ws, soft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ Notes:
|
||||||
|
|
||||||
namespace opt {
|
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);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -75,7 +75,7 @@ namespace opt {
|
||||||
|
|
||||||
|
|
||||||
public:
|
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),
|
maxsmt_solver_base(c, ws, soft),
|
||||||
m_aux(m),
|
m_aux(m),
|
||||||
m_at_lower_bound(false) {
|
m_at_lower_bound(false) {
|
||||||
|
@ -554,7 +554,7 @@ namespace opt {
|
||||||
};
|
};
|
||||||
|
|
||||||
maxsmt_solver_base* mk_maxhs(
|
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);
|
return alloc(maxhs, c, ws, soft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ Notes:
|
||||||
#include "maxsmt.h"
|
#include "maxsmt.h"
|
||||||
|
|
||||||
namespace opt {
|
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);
|
weights_t& ws, expr_ref_vector const& soft);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -107,7 +107,7 @@ private:
|
||||||
typedef ptr_vector<expr> exprs;
|
typedef ptr_vector<expr> exprs;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
maxres(context& c,
|
maxres(maxsat_context& c,
|
||||||
weights_t& ws, expr_ref_vector const& soft,
|
weights_t& ws, expr_ref_vector const& soft,
|
||||||
strategy_t st):
|
strategy_t st):
|
||||||
maxsmt_solver_base(c, ws, soft),
|
maxsmt_solver_base(c, ws, soft),
|
||||||
|
@ -788,12 +788,12 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
opt::maxsmt_solver_base* opt::mk_maxres(
|
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);
|
return alloc(maxres, c, ws, soft, maxres::s_primal);
|
||||||
}
|
}
|
||||||
|
|
||||||
opt::maxsmt_solver_base* opt::mk_primal_dual_maxres(
|
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);
|
return alloc(maxres, c, ws, soft, maxres::s_primal_dual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,9 @@ Notes:
|
||||||
|
|
||||||
namespace opt {
|
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);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace opt {
|
||||||
|
|
||||||
class sls : public maxsmt_solver_base {
|
class sls : public maxsmt_solver_base {
|
||||||
public:
|
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) {
|
maxsmt_solver_base(c, ws, soft) {
|
||||||
}
|
}
|
||||||
virtual ~sls() {}
|
virtual ~sls() {}
|
||||||
|
@ -54,7 +54,7 @@ namespace opt {
|
||||||
};
|
};
|
||||||
|
|
||||||
maxsmt_solver_base* mk_sls(
|
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);
|
return alloc(sls, c, ws, soft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ Notes:
|
||||||
namespace opt {
|
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);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,7 +36,7 @@ Notes:
|
||||||
namespace opt {
|
namespace opt {
|
||||||
|
|
||||||
maxsmt_solver_base::maxsmt_solver_base(
|
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.get_manager()),
|
||||||
m_c(c),
|
m_c(c),
|
||||||
m_cancel(false),
|
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(c.get_manager()), m_c(c), m_cancel(false),
|
||||||
m_soft_constraints(m), m_answer(m) {}
|
m_soft_constraints(m), m_answer(m) {}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace opt {
|
||||||
|
|
||||||
typedef vector<rational> const weights_t;
|
typedef vector<rational> const weights_t;
|
||||||
|
|
||||||
class context;
|
class maxsat_context;
|
||||||
|
|
||||||
class maxsmt_solver {
|
class maxsmt_solver {
|
||||||
protected:
|
protected:
|
||||||
|
@ -59,7 +59,7 @@ namespace opt {
|
||||||
class maxsmt_solver_base : public maxsmt_solver {
|
class maxsmt_solver_base : public maxsmt_solver {
|
||||||
protected:
|
protected:
|
||||||
ast_manager& m;
|
ast_manager& m;
|
||||||
context& m_c;
|
maxsat_context& m_c;
|
||||||
volatile bool m_cancel;
|
volatile bool m_cancel;
|
||||||
const expr_ref_vector m_soft;
|
const expr_ref_vector m_soft;
|
||||||
vector<rational> m_weights;
|
vector<rational> m_weights;
|
||||||
|
@ -71,7 +71,7 @@ namespace opt {
|
||||||
params_ref m_params; // config
|
params_ref m_params; // config
|
||||||
|
|
||||||
public:
|
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 ~maxsmt_solver_base() {}
|
||||||
virtual rational get_lower() const { return m_lower; }
|
virtual rational get_lower() const { return m_lower; }
|
||||||
|
@ -114,7 +114,7 @@ namespace opt {
|
||||||
|
|
||||||
class maxsmt {
|
class maxsmt {
|
||||||
ast_manager& m;
|
ast_manager& m;
|
||||||
context& m_c;
|
maxsat_context& m_c;
|
||||||
scoped_ptr<maxsmt_solver_base> m_msolver;
|
scoped_ptr<maxsmt_solver_base> m_msolver;
|
||||||
volatile bool m_cancel;
|
volatile bool m_cancel;
|
||||||
expr_ref_vector m_soft_constraints;
|
expr_ref_vector m_soft_constraints;
|
||||||
|
@ -126,7 +126,7 @@ namespace opt {
|
||||||
model_ref m_model;
|
model_ref m_model;
|
||||||
params_ref m_params;
|
params_ref m_params;
|
||||||
public:
|
public:
|
||||||
maxsmt(context& c);
|
maxsmt(maxsat_context& c);
|
||||||
lbool operator()();
|
lbool operator()();
|
||||||
void set_cancel(bool f);
|
void set_cancel(bool f);
|
||||||
void updt_params(params_ref& p);
|
void updt_params(params_ref& p);
|
||||||
|
|
|
@ -34,8 +34,40 @@ namespace opt {
|
||||||
|
|
||||||
class opt_solver;
|
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;
|
struct free_func_visitor;
|
||||||
typedef map<symbol, maxsmt*, symbol_hash_proc, symbol_eq_proc> map_t;
|
typedef map<symbol, maxsmt*, symbol_hash_proc, symbol_eq_proc> map_t;
|
||||||
typedef map<symbol, unsigned, symbol_hash_proc, symbol_eq_proc> map_id;
|
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_ge(unsigned i, model_ref& model);
|
||||||
virtual expr_ref mk_le(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(); }
|
virtual smt::context& smt_context() { return m_opt_solver->get_context(); }
|
||||||
filter_model_converter& fm() { return m_fm; }
|
virtual filter_model_converter& fm() { return m_fm; }
|
||||||
bool sat_enabled() const { return 0 != m_sat_solver.get(); }
|
virtual bool sat_enabled() const { return 0 != m_sat_solver.get(); }
|
||||||
solver& get_solver();
|
virtual solver& get_solver();
|
||||||
ast_manager& get_manager() { return this->m; }
|
virtual ast_manager& get_manager() { return this->m; }
|
||||||
params_ref& params() { return m_params; }
|
virtual params_ref& params() { return m_params; }
|
||||||
void enable_sls(expr_ref_vector const& soft, weights_t& weights);
|
virtual void enable_sls(expr_ref_vector const& soft, weights_t& weights);
|
||||||
void set_enable_sls(bool f) { m_enable_sls = f; }
|
virtual void set_enable_sls(bool f) { m_enable_sls = f; }
|
||||||
void set_soft_assumptions();
|
virtual void set_soft_assumptions();
|
||||||
symbol const& maxsat_engine() const { return m_maxsat_engine; }
|
virtual symbol const& maxsat_engine() const { return m_maxsat_engine; }
|
||||||
void get_base_model(model_ref& _m);
|
virtual void get_base_model(model_ref& _m);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace opt {
|
||||||
|
|
||||||
class wmax : public maxsmt_solver_base {
|
class wmax : public maxsmt_solver_base {
|
||||||
public:
|
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) {}
|
maxsmt_solver_base(c, ws, soft) {}
|
||||||
virtual ~wmax() {}
|
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);
|
return alloc(wmax, c, ws, soft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ Notes:
|
||||||
#include "maxsmt.h"
|
#include "maxsmt.h"
|
||||||
|
|
||||||
namespace opt {
|
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
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue