3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-07 18:05:21 +00:00

cleanup cancelation logic

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2015-12-11 12:35:35 -08:00
parent 4e155887b2
commit 61dbb6168e
37 changed files with 93 additions and 198 deletions

View file

@ -130,12 +130,6 @@ namespace api {
m_context.display_smt2(num_queries, queries, str);
return str.str();
}
void cancel() {
m_context.cancel();
}
void reset_cancel() {
m_context.reset_cancel();
}
unsigned get_num_levels(func_decl* pred) {
return m_context.get_num_levels(pred);
}
@ -285,13 +279,13 @@ extern "C" {
LOG_Z3_fixedpoint_query(c, d, q);
RESET_ERROR_CODE();
lbool r = l_undef;
cancel_eh<api::fixedpoint_context> eh(*to_fixedpoint_ref(d));
unsigned timeout = to_fixedpoint(d)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
unsigned rlimit = to_fixedpoint(d)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
api::context::set_interruptable si(*(mk_c(c)), eh);
{
scoped_timer timer(timeout, &eh);
scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
cancel_eh<reslimit> eh(mk_c(c)->m().limit());
api::context::set_interruptable si(*(mk_c(c)), eh);
scoped_timer timer(timeout, &eh);
try {
r = to_fixedpoint_ref(d)->ctx().query(to_expr(q));
}
@ -313,7 +307,7 @@ extern "C" {
RESET_ERROR_CODE();
lbool r = l_undef;
unsigned timeout = to_fixedpoint(d)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
cancel_eh<api::fixedpoint_context> eh(*to_fixedpoint_ref(d));
cancel_eh<reslimit> eh(mk_c(c)->m().limit());
api::context::set_interruptable si(*(mk_c(c)), eh);
{
scoped_timer timer(timeout, &eh);

View file

@ -98,7 +98,6 @@ struct euclidean_solver::imp {
numeral_manager * m_manager;
bool m_owns_m;
volatile bool m_cancel;
equations m_equations;
equations m_solution;
@ -517,7 +516,6 @@ struct euclidean_solver::imp {
m_var_queue(16, elim_order_lt(m_solved)) {
m_inconsistent = null_eq_idx;
m_next_justification = 0;
m_cancel = false;
m_next_x = null_var;
m_next_eq = null_eq_idx;
}
@ -779,9 +777,6 @@ struct euclidean_solver::imp {
del_nums(m_norm_bs_vector);
}
void set_cancel(bool f) {
m_cancel = f;
}
};
@ -842,12 +837,6 @@ void euclidean_solver::normalize(unsigned num, mpz const * as, var const * xs, m
return m_imp->normalize(num, as, xs, c, a_prime, c_prime, js);
}
void euclidean_solver::set_cancel(bool f) {
#pragma omp critical (euclidean_solver)
{
m_imp->set_cancel(f);
}
}
void euclidean_solver::display(std::ostream & out) const {
m_imp->display(out);

View file

@ -95,10 +95,6 @@ public:
*/
void normalize(unsigned num, mpz const * as, var const * xs, mpz const & c, mpz & a_prime, mpz & c_prime, justification_vector & js);
/**
\brief Set/Reset the cancel flag.
*/
void set_cancel(bool f);
void display(std::ostream & out) const;
};

View file

@ -647,8 +647,8 @@ private:
};
hilbert_basis::hilbert_basis():
m_cancel(false),
hilbert_basis::hilbert_basis(reslimit& lim):
m_limit(lim),
m_use_support(true),
m_use_ordered_support(true),
m_use_ordered_subsumption(true)
@ -804,7 +804,7 @@ void hilbert_basis::add_unit_vector(unsigned i, numeral const& e) {
lbool hilbert_basis::saturate() {
init_basis();
m_current_ineq = 0;
while (!m_cancel && m_current_ineq < m_ineqs.size()) {
while (checkpoint() && m_current_ineq < m_ineqs.size()) {
select_inequality();
stopwatch sw;
sw.start();
@ -823,7 +823,7 @@ lbool hilbert_basis::saturate() {
}
++m_current_ineq;
}
if (m_cancel) {
if (!checkpoint()) {
return l_undef;
}
return l_true;
@ -853,7 +853,7 @@ lbool hilbert_basis::saturate_orig(num_vector const& ineq, bool is_eq) {
// resolve passive into active
offset_t j = alloc_vector();
while (!m_passive->empty()) {
if (m_cancel) {
if (!checkpoint()) {
return l_undef;
}
offset_t idx = m_passive->pop();
@ -862,7 +862,7 @@ lbool hilbert_basis::saturate_orig(num_vector const& ineq, bool is_eq) {
recycle(idx);
continue;
}
for (unsigned i = 0; !m_cancel && i < m_active.size(); ++i) {
for (unsigned i = 0; checkpoint() && i < m_active.size(); ++i) {
if ((!m_use_support || support.contains(m_active[i].m_offset)) && can_resolve(idx, m_active[i], true)) {
resolve(idx, m_active[i], j);
if (add_goal(j)) {
@ -942,7 +942,7 @@ lbool hilbert_basis::saturate(num_vector const& ineq, bool is_eq) {
TRACE("hilbert_basis", display(tout););
// resolve passive into active
offset_t idx = alloc_vector();
while (!m_cancel && !m_passive2->empty()) {
while (checkpoint() && !m_passive2->empty()) {
offset_t sos, pas;
TRACE("hilbert_basis", display(tout); );
unsigned offset = m_passive2->pop(sos, pas);
@ -967,7 +967,7 @@ lbool hilbert_basis::saturate(num_vector const& ineq, bool is_eq) {
}
idx = alloc_vector();
}
if (m_cancel) {
if (!checkpoint()) {
return l_undef;
}
@ -1112,6 +1112,10 @@ hilbert_basis::offset_t hilbert_basis::alloc_vector() {
}
}
bool hilbert_basis::checkpoint() {
return m_limit.inc();
}
bool hilbert_basis::add_goal(offset_t idx) {
TRACE("hilbert_basis", display(tout, idx););
values v = vec(idx);

View file

@ -32,6 +32,7 @@ Revision History:
#include "lbool.h"
#include "statistics.h"
#include "checked_int64.h"
#include "rlimit.h"
typedef vector<rational> rational_vector;
@ -85,6 +86,7 @@ class hilbert_basis {
numeral const* operator()() const { return m_values; }
};
reslimit& m_limit;
vector<num_vector> m_ineqs; // set of asserted inequalities
svector<bool> m_iseq; // inequalities that are equalities
num_vector m_store; // store of vectors
@ -95,7 +97,6 @@ class hilbert_basis {
svector<offset_t> m_zero; // zeros
passive* m_passive; // passive set
passive2* m_passive2; // passive set
volatile bool m_cancel;
stats m_stats;
index* m_index; // index of generated vectors
unsigned_vector m_ints; // indices that can be both positive and negative
@ -105,6 +106,7 @@ class hilbert_basis {
bool m_use_ordered_support; // parameter: (commutativity) resolve in order
bool m_use_ordered_subsumption; // parameter
class iterator {
hilbert_basis const& hb;
unsigned m_idx;
@ -138,6 +140,8 @@ class hilbert_basis {
bool can_resolve(offset_t i, offset_t j, bool check_sign) const;
sign_t get_sign(offset_t idx) const;
bool add_goal(offset_t idx);
bool checkpoint();
offset_t alloc_vector();
void resolve(offset_t i, offset_t j, offset_t r);
iterator begin() const { return iterator(*this,0); }
@ -154,7 +158,7 @@ class hilbert_basis {
public:
hilbert_basis();
hilbert_basis(reslimit& rl);
~hilbert_basis();
void reset();
@ -188,8 +192,6 @@ public:
unsigned get_num_ineqs() const { return m_ineqs.size(); }
void get_ge(unsigned i, rational_vector& v, rational& b, bool& is_eq);
void set_cancel(bool f) { m_cancel = f; }
void display(std::ostream& out) const;
void collect_statistics(statistics& st) const;

View file

@ -92,6 +92,7 @@ namespace simplex {
};
static const var_t null_var;
reslimit& m_limit;
mutable manager m;
mutable eps_manager em;
mutable matrix M;
@ -109,10 +110,10 @@ namespace simplex {
stats m_stats;
public:
simplex():
simplex(reslimit& lim):
m_limit(lim),
M(m),
m_max_iterations(UINT_MAX),
m_cancel(false),
m_to_patch(1024),
m_bland(false),
m_blands_rule_threshold(1000) {}
@ -140,7 +141,6 @@ namespace simplex {
void unset_lower(var_t var);
void unset_upper(var_t var);
void set_value(var_t var, eps_numeral const& b);
void set_cancel(bool f) { m_cancel = f; }
void set_max_iterations(unsigned n) { m_max_iterations = n; }
void reset();
lbool make_feasible();

View file

@ -332,7 +332,7 @@ namespace simplex {
SASSERT(well_formed());
while ((v = select_var_to_fix()) != null_var) {
TRACE("simplex", display(tout << "v" << v << "\n"););
if (m_cancel || num_iterations > m_max_iterations) {
if (!m_limit.inc() || num_iterations > m_max_iterations) {
return l_undef;
}
check_blands_rule(v, num_repeated);
@ -670,7 +670,7 @@ namespace simplex {
bool inc_x_i, inc_x_j;
while (true) {
if (m_cancel) {
if (!m_limit.inc()) {
return l_undef;
}
select_pivot_primal(v, x_i, x_j, a_ij, inc_x_i, inc_x_j);

View file

@ -230,8 +230,7 @@ namespace datalog {
m_enable_bind_variables(true),
m_last_status(OK),
m_last_answer(m),
m_engine_type(LAST_ENGINE),
m_cancel(false) {
m_engine_type(LAST_ENGINE) {
re.set_context(this);
updt_params(pa);
}
@ -751,15 +750,16 @@ namespace datalog {
}
#if 0
void context::cancel() {
m_cancel = true;
m_last_status = CANCELED;
m_transf.cancel();
if (m_engine) m_engine->cancel();
}
#endif
void context::cleanup() {
m_cancel = false;
m_last_status = OK;
if (m_engine) m_engine->cleanup();
}

View file

@ -487,11 +487,13 @@ namespace datalog {
//
// -----------------------------------
void cancel();
bool canceled() const { return m_cancel; }
bool canceled() {
if (m.limit().inc()) return true;
m_last_status = CANCELED;
return false;
}
void cleanup();
void reset_cancel() { cleanup(); }
/**
\brief check if query 'q' is satisfied under asserted rules and background.

View file

@ -74,7 +74,6 @@ class hnf::imp {
ast_manager& m;
bool m_produce_proofs;
volatile bool m_cancel;
expr_ref_vector m_todo;
proof_ref_vector m_proofs;
expr_ref_vector m_refs;
@ -96,7 +95,6 @@ public:
imp(ast_manager & m):
m(m),
m_produce_proofs(false),
m_cancel(false),
m_todo(m),
m_proofs(m),
m_refs(m),
@ -156,7 +154,7 @@ public:
m_todo.push_back(n);
m_proofs.push_back(p);
m_produce_proofs = p != 0;
while (!m_todo.empty() && !m_cancel) {
while (!m_todo.empty() && checkpoint()) {
fml = m_todo.back();
pr = m_proofs.back();
m_todo.pop_back();
@ -174,8 +172,8 @@ public:
});
}
void set_cancel(bool f) {
m_cancel = f;
bool checkpoint() {
return m.limit().inc();
}
void set_name(symbol const& n) {
@ -192,7 +190,6 @@ public:
}
void reset() {
m_cancel = false;
m_todo.reset();
m_proofs.reset();
m_refs.reset();
@ -524,9 +521,6 @@ void hnf::operator()(expr * n, proof* p, expr_ref_vector & rs, proof_ref_vector&
);
}
void hnf::set_cancel(bool f) {
m_imp->set_cancel(f);
}
void hnf::set_name(symbol const& n) {
m_imp->set_name(n);

View file

@ -43,9 +43,6 @@ class hnf {
proof_ref_vector& ps // [OUT] proofs of rs
);
void cancel() { set_cancel(true); }
void reset_cancel() { set_cancel(false); }
void set_cancel(bool f);
void set_name(symbol const& name);
void reset();
func_decl_ref_vector const& get_fresh_predicates();

View file

@ -470,7 +470,6 @@ namespace datalog {
ast_manager& m;
rule_manager& rm;
bv_util bv;
volatile bool m_cancel;
ptr_vector<expr> m_todo;
ast_mark m_visited1, m_visited2;
ddnfs m_ddnfs;
@ -486,7 +485,6 @@ namespace datalog {
m(ctx.get_manager()),
rm(ctx.get_rule_manager()),
bv(m),
m_cancel(false),
m_trail(m),
m_inner_ctx(m, m_ctx.get_register_engine(), m_ctx.get_fparams())
{
@ -518,15 +516,7 @@ namespace datalog {
// return execute_rules(new_rules);
}
void cancel() {
m_cancel = true;
m_inner_ctx.cancel();
}
void cleanup() {
m_cancel = false;
}
void reset_statistics() {
m_stats.reset();
}
@ -884,12 +874,6 @@ namespace datalog {
lbool ddnf::query(expr* query) {
return m_imp->query(query);
}
void ddnf::cancel() {
m_imp->cancel();
}
void ddnf::cleanup() {
m_imp->cleanup();
}
void ddnf::reset_statistics() {
m_imp->reset_statistics();
}

View file

@ -37,8 +37,6 @@ namespace datalog {
ddnf(context& ctx);
~ddnf();
virtual lbool query(expr* query);
virtual void cancel();
virtual void cleanup();
virtual void reset_statistics();
virtual void collect_statistics(statistics& st) const;
virtual void display_certificate(std::ostream& out) const;

View file

@ -230,7 +230,7 @@ public:
set_background(ctx);
dlctx.updt_params(m_params);
unsigned timeout = m_dl_ctx->get_params().timeout();
cancel_eh<datalog::context> eh(dlctx);
cancel_eh<reslimit> eh(ctx.m().limit());
bool query_exn = false;
lbool status = l_undef;
{

View file

@ -64,9 +64,6 @@ class horn_tactic : public tactic {
}
void set_cancel(bool f) {
if (f) {
m_ctx.cancel();
}
}
void normalize(expr_ref& f) {

View file

@ -270,8 +270,6 @@ namespace datalog {
symbol const& get_name() const { return m_name; }
virtual void set_cancel(bool f) {}
relation_manager & get_manager() const { return m_manager; }
ast_manager& get_ast_manager() const { return datalog::get_ast_manager_from_rel_manager(m_manager); }
context& get_context() const { return datalog::get_context_from_rel_manager(m_manager); }

View file

@ -54,8 +54,6 @@ namespace datalog {
virtual table_base * mk_empty(const table_signature & s);
virtual void set_cancel(bool f) { m_plugin.set_cancel(f); }
static table_plugin* mk_sparse(relation_manager& rm);
protected:

View file

@ -463,12 +463,6 @@ namespace datalog {
}
}
void relation_manager::set_cancel(bool f) {
for (unsigned i = 0; i < m_relation_plugins.size(); ++i) {
m_relation_plugins[i]->set_cancel(f);
}
}
std::string relation_manager::to_nice_string(const relation_element & el) const {
uint64 val;
std::stringstream stm;

View file

@ -225,8 +225,6 @@ namespace datalog {
relation_fact & to);
void set_cancel(bool f);
// -----------------------------------
//

View file

@ -499,7 +499,6 @@ namespace datalog {
}
void karr_relation_plugin::set_cancel(bool f) {
m_hb.set_cancel(f);
}
relation_base * karr_relation_plugin::mk_empty(const relation_signature & s) {

View file

@ -41,6 +41,7 @@ namespace datalog {
public:
karr_relation_plugin(relation_manager& rm):
relation_plugin(karr_relation_plugin::get_name(), rm),
m_hb(get_ast_manager().limit()),
a(get_ast_manager())
{}

View file

@ -512,9 +512,6 @@ namespace datalog {
get_rmanager().set_predicate_kind(pred, target_kind);
}
void rel_context::set_cancel(bool f) {
get_rmanager().set_cancel(f);
}
void rel_context::setup_default_relation() {
if (m_context.default_relation() == symbol("doc")) {

View file

@ -51,8 +51,6 @@ namespace datalog {
lbool saturate(scoped_query& sq);
void set_cancel(bool f);
void setup_default_relation();
public:
@ -82,8 +80,6 @@ namespace datalog {
virtual void collect_statistics(statistics& st) const;
virtual void cancel() { set_cancel(true); }
virtual void cleanup() { set_cancel(false);}
virtual void updt_params();
/**

View file

@ -509,7 +509,6 @@ namespace tb {
bool_rewriter m_rw;
smt_params m_fparams;
smt::kernel m_solver;
volatile bool m_cancel;
public:
index(ast_manager& m):
@ -523,8 +522,7 @@ namespace tb {
m_subst(m),
m_qe(m),
m_rw(m),
m_solver(m, m_fparams),
m_cancel(false) {}
m_solver(m, m_fparams) {}
void insert(ref<clause>& g) {
m_index.push_back(g);
@ -540,17 +538,6 @@ namespace tb {
return found;
}
void cancel() {
m_cancel = true;
m_solver.cancel();
m_qe.set_cancel(true);
}
void cleanup() {
m_solver.reset_cancel();
m_qe.set_cancel(false);
m_cancel = false;
}
void reset() {
m_index.reset();
@ -594,7 +581,7 @@ namespace tb {
// extract pre_cond => post_cond validation obligation from match.
bool find_match(unsigned& subsumer) {
for (unsigned i = 0; !m_cancel && i < m_index.size(); ++i) {
for (unsigned i = 0; m.limit().inc() && i < m_index.size(); ++i) {
if (match_rule(i)) {
subsumer = m_index[i]->get_seqno();
return true;
@ -631,7 +618,7 @@ namespace tb {
app* q = g.get_predicate(predicate_index);
for (unsigned i = 0; !m_cancel && i < m_preds.size(); ++i) {
for (unsigned i = 0; m.limit().inc() && i < m_preds.size(); ++i) {
app* p = m_preds[i].get();
m_subst.push_scope();
unsigned limit = m_sideconds.size();
@ -660,7 +647,7 @@ namespace tb {
expr_ref_vector fmls(m_sideconds);
m_subst.reset_cache();
for (unsigned i = 0; !m_cancel && i < fmls.size(); ++i) {
for (unsigned i = 0; m.limit().inc() && i < fmls.size(); ++i) {
m_subst.apply(2, deltas, expr_offset(fmls[i].get(), 0), q);
fmls[i] = q;
}
@ -677,7 +664,7 @@ namespace tb {
}
}
m_rw.mk_and(fmls.size(), fmls.c_ptr(), postcond);
if (m_cancel) {
if (!m.limit().inc()) {
return false;
}
if (m.is_false(postcond)) {
@ -1350,7 +1337,6 @@ namespace datalog {
unsigned m_seqno;
tb::instruction m_instruction;
lbool m_status;
volatile bool m_cancel;
stats m_stats;
uint_set m_displayed_rules;
public:
@ -1365,8 +1351,7 @@ namespace datalog {
m_rules(),
m_seqno(0),
m_instruction(tb::SELECT_PREDICATE),
m_status(l_undef),
m_cancel(false)
m_status(l_undef)
{
// m_fparams.m_relevancy_lvl = 0;
m_fparams.m_mbqi = false;
@ -1393,18 +1378,9 @@ namespace datalog {
IF_VERBOSE(1, display_clause(*get_clause(), verbose_stream() << "g" << get_clause()->get_seqno() << " "););
return run();
}
void cancel() {
m_cancel = true;
m_index.cleanup();
m_solver.cancel();
}
void cleanup() {
m_cancel = false;
m_clauses.reset();
m_index.cleanup();
m_solver.reset_cancel();
}
void reset_statistics() {
@ -1519,7 +1495,7 @@ namespace datalog {
m_status = l_undef;
while (true) {
IF_VERBOSE(2, verbose_stream() << m_instruction << "\n";);
if (m_cancel) {
if (!m.limit().inc()) {
cleanup();
return l_undef;
}
@ -1671,9 +1647,6 @@ namespace datalog {
lbool tab::query(expr* query) {
return m_imp->query(query);
}
void tab::cancel() {
m_imp->cancel();
}
void tab::cleanup() {
m_imp->cleanup();
}

View file

@ -34,7 +34,6 @@ namespace datalog {
tab(context& ctx);
~tab();
virtual lbool query(expr* query);
virtual void cancel();
virtual void cleanup();
virtual void reset_statistics();
virtual void collect_statistics(statistics& st) const;

View file

@ -50,8 +50,7 @@ namespace datalog {
rm(ctx.get_rule_manager()),
m_inner_ctx(m, ctx.get_register_engine(), ctx.get_fparams()),
a(m),
m_pinned(m),
m_cancel(false) {
m_pinned(m) {
params_ref params;
params.set_sym("default_relation", symbol("karr_relation"));
params.set_sym("engine", symbol("datalog"));
@ -189,11 +188,6 @@ namespace datalog {
}
}
};
void mk_karr_invariants::cancel() {
m_cancel = true;
m_inner_ctx.cancel();
}
rule_set * mk_karr_invariants::operator()(rule_set const & source) {
if (!m_ctx.karr()) {
@ -214,7 +208,7 @@ namespace datalog {
get_invariants(*src_loop);
if (m_cancel) {
if (!m.limit().inc()) {
return 0;
}

View file

@ -57,7 +57,6 @@ namespace datalog {
arith_util a;
obj_map<func_decl, expr*> m_fun2inv;
ast_ref_vector m_pinned;
volatile bool m_cancel;
void get_invariants(rule_set const& src);
@ -67,8 +66,6 @@ namespace datalog {
mk_karr_invariants(context & ctx, unsigned priority);
virtual ~mk_karr_invariants();
virtual void cancel();
rule_set * operator()(rule_set const & source);

View file

@ -88,7 +88,7 @@ namespace opt {
bool empty() const { return 0 == size(); }
};
volatile bool m_cancel;
reslimit& m_limit;
rational m_lower;
rational m_upper;
vector<rational> m_weights;
@ -144,8 +144,8 @@ namespace opt {
static unsigned const null_idx = UINT_MAX;
imp():
m_cancel(false),
imp(reslimit& lim):
m_limit(lim),
m_max_weight(0),
m_denominator(1),
m_alloc("hitting-sets"),
@ -155,6 +155,7 @@ namespace opt {
m_scope_lvl(0),
m_compare_scores(),
m_heap(0, m_compare_scores),
m_simplex(lim),
m_weights_var(0) {
m_enable_simplex = true;
m_compare_scores.m_imp = this;
@ -298,11 +299,6 @@ namespace opt {
m_model[idx] == l_true;
}
void set_cancel(bool f) {
m_cancel = f;
m_simplex.set_cancel(f);
}
void collect_statistics(::statistics& st) const {
m_simplex.collect_statistics(st);
}
@ -641,7 +637,7 @@ namespace opt {
inline unsigned scope_lvl() const { return m_scope_lvl; }
inline bool inconsistent() const { return m_inconsistent; }
inline bool canceled() const { return m_cancel; }
inline bool canceled() const { return !m_limit.inc(); }
inline unsigned lvl(unsigned idx) const { return m_level[idx]; }
inline lbool value(unsigned idx) const { return m_value[idx]; }
@ -1073,7 +1069,7 @@ namespace opt {
};
hitting_sets::hitting_sets() { m_imp = alloc(imp); }
hitting_sets::hitting_sets(reslimit& lim) { m_imp = alloc(imp, lim); }
hitting_sets::~hitting_sets() { dealloc(m_imp); }
void hitting_sets::add_weight(rational const& w) { m_imp->add_weight(w); }
void hitting_sets::add_exists_true(unsigned sz, unsigned const* elems) { m_imp->add_exists_true(sz, elems); }
@ -1084,7 +1080,6 @@ namespace opt {
rational hitting_sets::get_upper() { return m_imp->get_upper(); }
void hitting_sets::set_upper(rational const& r) { return m_imp->set_upper(r); }
bool hitting_sets::get_value(unsigned idx) { return m_imp->get_value(idx); }
void hitting_sets::set_cancel(bool f) { m_imp->set_cancel(f); }
void hitting_sets::collect_statistics(::statistics& st) const { m_imp->collect_statistics(st); }
void hitting_sets::reset() { m_imp->reset(); }

View file

@ -22,6 +22,7 @@ Notes:
#include "rational.h"
#include "statistics.h"
#include "lbool.h"
#include "rlimit.h"
namespace opt {
@ -29,7 +30,7 @@ namespace opt {
struct imp;
imp* m_imp;
public:
hitting_sets();
hitting_sets(reslimit& lim);
~hitting_sets();
void add_weight(rational const& w);
void add_exists_true(unsigned sz, unsigned const* elems);

View file

@ -77,6 +77,7 @@ namespace opt {
public:
maxhs(maxsat_context& c, weights_t& ws, expr_ref_vector const& soft):
maxsmt_solver_base(c, ws, soft),
m_hs(m.limit()),
m_aux(m),
m_at_lower_bound(false) {
}
@ -84,7 +85,6 @@ namespace opt {
virtual void set_cancel(bool f) {
maxsmt_solver_base::set_cancel(f);
m_hs.set_cancel(f);
}
virtual void collect_statistics(statistics& st) const {

View file

@ -896,8 +896,8 @@ namespace smt {
template<typename Ext>
inf_eps_rational<inf_rational> theory_dense_diff_logic<Ext>::maximize(theory_var v, expr_ref& blocker, bool& has_shared) {
typedef simplex::simplex<simplex::mpq_ext> Simplex;
Simplex S;
ast_manager& m = get_manager();
Simplex S(m.limit());
objective_term const& objective = m_objectives[v];
has_shared = false;

View file

@ -236,6 +236,7 @@ namespace smt {
m_non_diff_logic_exprs(false),
m_factory(0),
m_nc_functor(*this),
m_S(m.limit()),
m_num_simplex_edges(0) {
}

View file

@ -231,6 +231,7 @@ namespace smt {
theory_pb::theory_pb(ast_manager& m, theory_pb_params& p):
theory(m.mk_family_id("pb")),
m_params(p),
m_simplex(m.limit()),
m_util(m),
m_max_compiled_coeff(rational(8))
{

View file

@ -98,14 +98,6 @@ public:
}
protected:
/**
\brief Reset cancel flag of t if this was not canceled.
*/
void parent_reset_cancel(tactic & t) {
if (!m_cancel) {
t.reset_cancel();
}
}
virtual void set_cancel(bool f) {
m_cancel = f;
@ -390,14 +382,6 @@ public:
}
protected:
/**
\brief Reset cancel flag of st if this was not canceled.
*/
void parent_reset_cancel(tactic & t) {
if (!m_cancel) {
t.reset_cancel();
}
}
virtual void set_cancel(bool f) {
m_cancel = f;
@ -583,8 +567,10 @@ public:
}
if (first) {
for (unsigned j = 0; j < sz; j++) {
if (static_cast<unsigned>(i) != j)
if (static_cast<unsigned>(i) != j) {
ts.get(j)->cancel();
managers[j]->limit().cancel();
}
}
ast_translation translator(*(managers[i]), m, false);
for (unsigned k = 0; k < _result.size(); k++) {
@ -784,8 +770,10 @@ public:
if (curr_failed) {
for (unsigned j = 0; j < r1_size; j++) {
if (static_cast<unsigned>(i) != j)
if (static_cast<unsigned>(i) != j) {
ts2.get(j)->cancel();
managers[j]->limit().cancel();
}
}
}
else {
@ -804,8 +792,10 @@ public:
}
if (first) {
for (unsigned j = 0; j < r1_size; j++) {
if (static_cast<unsigned>(i) != j)
if (static_cast<unsigned>(i) != j) {
ts2.get(j)->cancel();
managers[j]->limit().cancel();
}
}
ast_translation translator(new_m, m, false);
SASSERT(r2.size() == 1);

View file

@ -19,35 +19,36 @@ Revision History:
#include "rlimit.h"
reslimit::reslimit():
m_cancel(false),
m_count(0),
m_limit(UINT_MAX) {
m_limit(0) {
}
unsigned reslimit::count() const {
uint64 reslimit::count() const {
return m_count;
}
bool reslimit::inc() {
++m_count;
return m_count <= m_limit;
return !m_cancel && (m_limit == 0 || m_count <= m_limit);
}
bool reslimit::inc(unsigned offset) {
m_count += offset;
return m_count <= m_limit;
return !m_cancel && (m_limit == 0 || m_count <= m_limit);
}
void reslimit::push(unsigned delta_limit) {
unsigned new_limit = delta_limit + m_count;
uint64 new_limit = delta_limit + m_count;
if (new_limit <= m_count) {
new_limit = UINT_MAX;
new_limit = 0;
}
m_limits.push_back(m_limit);
m_limit = std::min(new_limit, m_limit);
m_limit = m_limit==0?new_limit:std::min(new_limit, m_limit);
}
void reslimit::pop() {
if (m_count > m_limit) {
if (m_count > m_limit && m_limit > 0) {
m_count = m_limit;
}
m_limit = m_limits.back();

View file

@ -22,16 +22,21 @@ Revision History:
#include "vector.h"
class reslimit {
unsigned m_count;
unsigned m_limit;
unsigned_vector m_limits;
volatile bool m_cancel;
uint64 m_count;
uint64 m_limit;
svector<uint64> m_limits;
public:
reslimit();
bool inc();
bool inc(unsigned offset);
void push(unsigned delta_limit);
void pop();
unsigned count() const;
bool inc();
bool inc(unsigned offset);
uint64 count() const;
void cancel() { m_cancel = true; }
void reset_cancel() { m_cancel = false; }
};
class scoped_rlimit {

View file

@ -238,5 +238,5 @@ void get_memory_statistics(statistics& st) {
}
void get_rlimit_statistics(reslimit& l, statistics& st) {
st.update("rlimit count", l.count());
st.update("rlimit count", static_cast<double>(l.count()));
}