3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +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

@ -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);