mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
reworking cancellation
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
981f8226fe
commit
baee4225a7
145 changed files with 172 additions and 958 deletions
|
@ -84,7 +84,7 @@ namespace sat {
|
|||
tout << "core: " << core << "\n";
|
||||
tout << "mus: " << mus << "\n";);
|
||||
|
||||
if (s.m_cancel) {
|
||||
if (s.canceled()) {
|
||||
set_core();
|
||||
return l_undef;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace sat {
|
|||
return m_elems[rnd(num_elems())];
|
||||
}
|
||||
|
||||
sls::sls(solver& s): s(s), m_cancel(false) {
|
||||
sls::sls(solver& s): s(s) {
|
||||
m_prob_choose_min_var = 43;
|
||||
m_clause_generation = 0;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ namespace sat {
|
|||
lbool sls::operator()(unsigned sz, literal const* tabu, bool reuse_model) {
|
||||
init(sz, tabu, reuse_model);
|
||||
unsigned i;
|
||||
for (i = 0; !m_false.empty() && !m_cancel && i < m_max_tries; ++i) {
|
||||
for (i = 0; !m_false.empty() && !s.canceled() && i < m_max_tries; ++i) {
|
||||
flip();
|
||||
}
|
||||
IF_VERBOSE(2, verbose_stream() << "tries " << i << "\n";);
|
||||
|
@ -378,7 +378,7 @@ namespace sat {
|
|||
}
|
||||
DEBUG_CODE(check_invariant(););
|
||||
unsigned i = 0;
|
||||
for (; !m_cancel && m_best_value > 0 && i < m_max_tries; ++i) {
|
||||
for (; !s.canceled() && m_best_value > 0 && i < m_max_tries; ++i) {
|
||||
wflip();
|
||||
if (m_false.empty()) {
|
||||
double val = evaluate_model(m_model);
|
||||
|
|
|
@ -54,12 +54,10 @@ namespace sat {
|
|||
clause_allocator m_alloc; // clause allocator
|
||||
clause_vector m_bin_clauses; // binary clauses
|
||||
svector<bool> m_tabu; // variables that cannot be swapped
|
||||
volatile bool m_cancel;
|
||||
public:
|
||||
sls(solver& s);
|
||||
virtual ~sls();
|
||||
lbool operator()(unsigned sz, literal const* tabu, bool reuse_model);
|
||||
void set_cancel(bool f) { m_cancel = f; }
|
||||
void set_max_tries(unsigned mx) { m_max_tries = mx; }
|
||||
virtual void display(std::ostream& out) const;
|
||||
protected:
|
||||
|
|
|
@ -32,7 +32,6 @@ Revision History:
|
|||
namespace sat {
|
||||
|
||||
solver::solver(params_ref const & p, reslimit& l, extension * ext):
|
||||
m_cancel(false),
|
||||
m_rlimit(l),
|
||||
m_config(p),
|
||||
m_ext(ext),
|
||||
|
@ -2714,11 +2713,6 @@ namespace sat {
|
|||
scc::collect_param_descrs(d);
|
||||
}
|
||||
|
||||
void solver::set_cancel(bool f) {
|
||||
m_cancel = f;
|
||||
m_wsls.set_cancel(f);
|
||||
}
|
||||
|
||||
void solver::collect_statistics(statistics & st) const {
|
||||
m_stats.collect_statistics(st);
|
||||
m_cleaner.collect_statistics(st);
|
||||
|
@ -2784,7 +2778,7 @@ namespace sat {
|
|||
//
|
||||
// -----------------------
|
||||
bool solver::check_invariant() const {
|
||||
if (m_cancel) return true;
|
||||
if (!m_rlimit.inc()) return true;
|
||||
integrity_checker checker(*this);
|
||||
SASSERT(checker());
|
||||
return true;
|
||||
|
|
|
@ -71,7 +71,6 @@ namespace sat {
|
|||
public:
|
||||
struct abort_solver {};
|
||||
protected:
|
||||
volatile bool m_cancel;
|
||||
reslimit& m_rlimit;
|
||||
config m_config;
|
||||
stats m_stats;
|
||||
|
@ -158,7 +157,6 @@ namespace sat {
|
|||
void updt_params(params_ref const & p);
|
||||
static void collect_param_descrs(param_descrs & d);
|
||||
|
||||
void set_cancel(bool f);
|
||||
void collect_statistics(statistics & st) const;
|
||||
void reset_statistics();
|
||||
void display_status(std::ostream & out) const;
|
||||
|
@ -239,13 +237,13 @@ namespace sat {
|
|||
lbool status(clause const & c) const;
|
||||
clause_offset get_offset(clause const & c) const { return m_cls_allocator.get_offset(&c); }
|
||||
void checkpoint() {
|
||||
if (m_cancel) throw solver_exception(Z3_CANCELED_MSG);
|
||||
if (!m_rlimit.inc()) { m_cancel = true; throw solver_exception(Z3_CANCELED_MSG); }
|
||||
if (!m_rlimit.inc()) { throw solver_exception(Z3_CANCELED_MSG); }
|
||||
++m_num_checkpoints;
|
||||
if (m_num_checkpoints < 10) return;
|
||||
m_num_checkpoints = 0;
|
||||
if (memory::get_allocation_size() > m_config.m_max_memory) throw solver_exception(Z3_MAX_MEMORY_MSG);
|
||||
}
|
||||
bool canceled() { return !m_rlimit.inc(); }
|
||||
typedef std::pair<literal, literal> bin_clause;
|
||||
protected:
|
||||
watch_list & get_wlist(literal l) { return m_watches[l.index()]; }
|
||||
|
|
|
@ -85,7 +85,6 @@ public:
|
|||
simp2_p.set_bool("flat", true); // required by som
|
||||
simp2_p.set_bool("hoist_mul", false); // required by som
|
||||
simp2_p.set_bool("elim_and", true);
|
||||
|
||||
m_preprocess =
|
||||
and_then(mk_card2bv_tactic(m, m_params),
|
||||
using_params(mk_simplify_tactic(m), simp2_p),
|
||||
|
@ -169,11 +168,6 @@ public:
|
|||
}
|
||||
return r;
|
||||
}
|
||||
virtual void set_cancel(bool f) {
|
||||
m_goal2sat.set_cancel(f);
|
||||
m_solver.set_cancel(f);
|
||||
if (f) m_preprocess->cancel(); else m_preprocess->reset_cancel();
|
||||
}
|
||||
virtual void push() {
|
||||
internalize_formulas();
|
||||
m_solver.user_push();
|
||||
|
@ -215,6 +209,7 @@ public:
|
|||
assert_expr(t);
|
||||
}
|
||||
}
|
||||
virtual ast_manager& get_manager() { return m; }
|
||||
virtual void assert_expr(expr * t) {
|
||||
TRACE("sat", tout << mk_pp(t, m) << "\n";);
|
||||
m_fmls.push_back(t);
|
||||
|
|
|
@ -58,7 +58,6 @@ struct goal2sat::imp {
|
|||
sat::bool_var m_true;
|
||||
bool m_ite_extra;
|
||||
unsigned long long m_max_memory;
|
||||
volatile bool m_cancel;
|
||||
expr_ref_vector m_trail;
|
||||
bool m_default_external;
|
||||
|
||||
|
@ -70,7 +69,6 @@ struct goal2sat::imp {
|
|||
m_trail(m),
|
||||
m_default_external(default_external) {
|
||||
updt_params(p);
|
||||
m_cancel = false;
|
||||
m_true = sat::null_bool_var;
|
||||
}
|
||||
|
||||
|
@ -334,7 +332,7 @@ struct goal2sat::imp {
|
|||
while (!m_frame_stack.empty()) {
|
||||
loop:
|
||||
cooperate("goal2sat");
|
||||
if (m_cancel)
|
||||
if (m.canceled())
|
||||
throw tactic_exception(TACTIC_CANCELED_MSG);
|
||||
if (memory::get_allocation_size() > m_max_memory)
|
||||
throw tactic_exception(TACTIC_MAX_MEMORY_MSG);
|
||||
|
@ -442,7 +440,6 @@ struct goal2sat::imp {
|
|||
process(fs[i]);
|
||||
}
|
||||
|
||||
void set_cancel(bool f) { m_cancel = f; }
|
||||
};
|
||||
|
||||
struct unsupported_bool_proc {
|
||||
|
@ -507,14 +504,6 @@ void goal2sat::operator()(goal const & g, params_ref const & p, sat::solver & t,
|
|||
proc(g);
|
||||
}
|
||||
|
||||
void goal2sat::set_cancel(bool f) {
|
||||
#pragma omp critical (goal2sat)
|
||||
{
|
||||
if (m_imp)
|
||||
m_imp->set_cancel(f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct sat2goal::imp {
|
||||
|
||||
|
@ -631,9 +620,8 @@ struct sat2goal::imp {
|
|||
expr_ref_vector m_lit2expr;
|
||||
unsigned long long m_max_memory;
|
||||
bool m_learned;
|
||||
volatile bool m_cancel;
|
||||
|
||||
imp(ast_manager & _m, params_ref const & p):m(_m), m_lit2expr(m), m_cancel(false) {
|
||||
imp(ast_manager & _m, params_ref const & p):m(_m), m_lit2expr(m) {
|
||||
updt_params(p);
|
||||
}
|
||||
|
||||
|
@ -643,7 +631,7 @@ struct sat2goal::imp {
|
|||
}
|
||||
|
||||
void checkpoint() {
|
||||
if (m_cancel)
|
||||
if (m.canceled())
|
||||
throw tactic_exception(TACTIC_CANCELED_MSG);
|
||||
if (memory::get_allocation_size() > m_max_memory)
|
||||
throw tactic_exception(TACTIC_MAX_MEMORY_MSG);
|
||||
|
@ -731,7 +719,6 @@ struct sat2goal::imp {
|
|||
assert_clauses(s.begin_learned(), s.end_learned(), r);
|
||||
}
|
||||
|
||||
void set_cancel(bool f) { m_cancel = f; }
|
||||
};
|
||||
|
||||
sat2goal::sat2goal():m_imp(0) {
|
||||
|
@ -765,10 +752,3 @@ void sat2goal::operator()(sat::solver const & t, atom2bool_var const & m, params
|
|||
proc(t, m, g, mc);
|
||||
}
|
||||
|
||||
void sat2goal::set_cancel(bool f) {
|
||||
#pragma omp critical (sat2goal)
|
||||
{
|
||||
if (m_imp)
|
||||
m_imp->set_cancel(f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ public:
|
|||
*/
|
||||
void operator()(goal const & g, params_ref const & p, sat::solver & t, atom2bool_var & m, dep2asm_map& dep2asm, bool default_external = false);
|
||||
|
||||
void set_cancel(bool f);
|
||||
|
||||
};
|
||||
|
||||
|
@ -83,7 +82,6 @@ public:
|
|||
*/
|
||||
void operator()(sat::solver const & t, atom2bool_var const & m, params_ref const & p, goal & s, model_converter_ref & mc);
|
||||
|
||||
void set_cancel(bool f);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -123,11 +123,6 @@ class sat_tactic : public tactic {
|
|||
result.push_back(g.get());
|
||||
}
|
||||
|
||||
void set_cancel(bool f) {
|
||||
m_goal2sat.set_cancel(f);
|
||||
m_sat2goal.set_cancel(f);
|
||||
m_solver.set_cancel(f);
|
||||
}
|
||||
|
||||
void dep2assumptions(obj_map<expr, sat::literal>& dep2asm,
|
||||
sat::literal_vector& assumptions) {
|
||||
|
@ -223,13 +218,6 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
virtual void set_cancel(bool f) {
|
||||
#pragma omp critical (sat_tactic)
|
||||
{
|
||||
if (m_imp)
|
||||
m_imp->set_cancel(f);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue