mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
reworking pd-maxres
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
980e74b4ff
commit
e3cb0e2d8b
13 changed files with 192 additions and 170 deletions
|
@ -206,16 +206,10 @@ public:
|
|||
init_local();
|
||||
set_soft_assumptions();
|
||||
lbool is_sat = l_true;
|
||||
trace_bounds("max_res");
|
||||
trace_bounds("maxres");
|
||||
exprs cs;
|
||||
while (m_lower < m_upper) {
|
||||
#if 0
|
||||
expr_ref_vector asms(m_asms);
|
||||
sort_assumptions(asms);
|
||||
is_sat = s().check_sat(asms.size(), asms.c_ptr());
|
||||
#else
|
||||
is_sat = check_sat_hill_climb(m_asms);
|
||||
#endif
|
||||
if (m_cancel) {
|
||||
return l_undef;
|
||||
}
|
||||
|
@ -268,33 +262,45 @@ public:
|
|||
first = false;
|
||||
IF_VERBOSE(3, verbose_stream() << "weight: " << get_weight(asms[0].get()) << " " << get_weight(asms[index-1].get()) << " num soft: " << index << "\n";);
|
||||
m_last_index = index;
|
||||
is_sat = s().check_sat(index, asms.c_ptr());
|
||||
is_sat = check_sat(index, asms.c_ptr());
|
||||
}
|
||||
}
|
||||
else {
|
||||
is_sat = s().check_sat(asms.size(), asms.c_ptr());
|
||||
is_sat = check_sat(asms.size(), asms.c_ptr());
|
||||
}
|
||||
return is_sat;
|
||||
}
|
||||
|
||||
lbool check_sat(unsigned sz, expr* const* asms) {
|
||||
if (m_st == s_primal_dual && m_c.sat_enabled()) {
|
||||
rational max_weight = m_upper;
|
||||
vector<rational> weights;
|
||||
for (unsigned i = 0; i < sz; ++i) {
|
||||
weights.push_back(get_weight(asms[i]));
|
||||
}
|
||||
return inc_sat_check_sat(s(), sz, asms, weights.c_ptr(), max_weight);
|
||||
}
|
||||
else {
|
||||
return s().check_sat(sz, asms);
|
||||
}
|
||||
}
|
||||
|
||||
void found_optimum() {
|
||||
IF_VERBOSE(1, verbose_stream() << "found optimum\n";);
|
||||
s().get_model(m_model);
|
||||
DEBUG_CODE(
|
||||
for (unsigned i = 0; i < m_asms.size(); ++i) {
|
||||
SASSERT(is_true(m_asms[i].get()));
|
||||
});
|
||||
SASSERT(is_true(m_asms));
|
||||
rational upper(0);
|
||||
for (unsigned i = 0; i < m_soft.size(); ++i) {
|
||||
m_assignment[i] = is_true(m_soft[i]);
|
||||
if (!m_assignment[i]) upper += m_weights[i];
|
||||
if (!m_assignment[i]) {
|
||||
upper += m_weights[i];
|
||||
}
|
||||
}
|
||||
SASSERT(upper == m_lower);
|
||||
m_upper = m_lower;
|
||||
m_found_feasible_optimum = true;
|
||||
}
|
||||
|
||||
|
||||
virtual lbool operator()() {
|
||||
m_defs.reset();
|
||||
switch(m_st) {
|
||||
|
@ -496,14 +502,6 @@ public:
|
|||
return m_asm2weight.find(e);
|
||||
}
|
||||
|
||||
void sls() {
|
||||
vector<rational> ws;
|
||||
for (unsigned i = 0; i < m_asms.size(); ++i) {
|
||||
ws.push_back(get_weight(m_asms[i].get()));
|
||||
}
|
||||
enable_sls(m_asms, ws);
|
||||
}
|
||||
|
||||
rational split_core(exprs const& core) {
|
||||
if (core.empty()) return rational(0);
|
||||
// find the minimal weight:
|
||||
|
@ -687,6 +685,13 @@ public:
|
|||
return is_true(m_model.get(), e);
|
||||
}
|
||||
|
||||
bool is_true(expr_ref_vector const& es) {
|
||||
for (unsigned i = 0; i < es.size(); ++i) {
|
||||
if (!is_true(es[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void remove_soft(exprs const& core, expr_ref_vector& asms) {
|
||||
for (unsigned i = 0; i < asms.size(); ++i) {
|
||||
if (core.contains(asms[i].get())) {
|
||||
|
|
|
@ -33,8 +33,7 @@ namespace opt {
|
|||
lbool operator()() {
|
||||
IF_VERBOSE(1, verbose_stream() << "(opt.sls)\n";);
|
||||
init();
|
||||
set_enable_sls(true);
|
||||
enable_sls(m_soft, m_weights);
|
||||
enable_sls(true);
|
||||
lbool is_sat = s().check_sat(0, 0);
|
||||
if (is_sat == l_true) {
|
||||
s().get_model(m_model);
|
||||
|
|
|
@ -97,12 +97,8 @@ namespace opt {
|
|||
s().updt_params(p);
|
||||
}
|
||||
|
||||
void maxsmt_solver_base::enable_sls(expr_ref_vector const& soft, vector<rational> const& ws) {
|
||||
m_c.enable_sls(soft, ws);
|
||||
}
|
||||
|
||||
void maxsmt_solver_base::set_enable_sls(bool f) {
|
||||
m_c.set_enable_sls(f);
|
||||
void maxsmt_solver_base::enable_sls(bool force) {
|
||||
m_c.enable_sls(force);
|
||||
}
|
||||
|
||||
void maxsmt_solver_base::set_soft_assumptions() {
|
||||
|
|
|
@ -100,8 +100,7 @@ namespace opt {
|
|||
|
||||
|
||||
protected:
|
||||
void enable_sls(expr_ref_vector const& soft, weights_t& ws);
|
||||
void set_enable_sls(bool f);
|
||||
void enable_sls(bool force);
|
||||
void set_soft_assumptions();
|
||||
void trace_bounds(char const* solver);
|
||||
|
||||
|
|
|
@ -130,7 +130,6 @@ namespace opt {
|
|||
m_fm(m),
|
||||
m_objective_refs(m),
|
||||
m_enable_sat(false),
|
||||
m_enable_sls(false),
|
||||
m_is_clausal(false),
|
||||
m_pp_neat(false)
|
||||
{
|
||||
|
@ -532,18 +531,11 @@ namespace opt {
|
|||
}
|
||||
|
||||
void context::set_soft_assumptions() {
|
||||
if (m_sat_solver.get()) {
|
||||
m_params.set_bool("soft_assumptions", true);
|
||||
m_sat_solver->updt_params(m_params);
|
||||
}
|
||||
// TBD no-op
|
||||
}
|
||||
|
||||
void context::enable_sls(expr_ref_vector const& soft, vector<rational> const& weights) {
|
||||
SASSERT(soft.size() == weights.size());
|
||||
if (m_sat_solver.get()) {
|
||||
set_soft_inc_sat(m_sat_solver.get(), soft.size(), soft.c_ptr(), weights.c_ptr());
|
||||
}
|
||||
if (m_enable_sls && m_sat_solver.get()) {
|
||||
void context::enable_sls(bool force) {
|
||||
if ((force || m_enable_sls) && m_sat_solver.get()) {
|
||||
m_params.set_bool("optimize_model", true);
|
||||
m_sat_solver->updt_params(m_params);
|
||||
}
|
||||
|
|
|
@ -50,8 +50,7 @@ namespace opt {
|
|||
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 enable_sls(bool force) = 0; // stochastic local search
|
||||
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.
|
||||
|
@ -216,8 +215,7 @@ namespace opt {
|
|||
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 enable_sls(bool force);
|
||||
virtual void set_soft_assumptions();
|
||||
virtual symbol const& maxsat_engine() const { return m_maxsat_engine; }
|
||||
virtual void get_base_model(model_ref& _m);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue