3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 09:05:31 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2018-04-30 09:30:43 -07:00
commit f525f43e43
155 changed files with 3188 additions and 1043 deletions

View file

@ -1020,14 +1020,14 @@ namespace sat {
SASSERT(v != null_bool_var);
m_coeffs.reserve(v + 1, 0);
int64 coeff0 = m_coeffs[v];
int64_t coeff0 = m_coeffs[v];
if (coeff0 == 0) {
m_active_vars.push_back(v);
}
int64 loffset = static_cast<int64>(offset);
int64 inc = l.sign() ? -loffset : loffset;
int64 coeff1 = inc + coeff0;
int64_t loffset = static_cast<int64_t>(offset);
int64_t inc = l.sign() ? -loffset : loffset;
int64_t coeff1 = inc + coeff0;
m_coeffs[v] = coeff1;
if (coeff1 > INT_MAX || coeff1 < INT_MIN) {
m_overflow = true;
@ -1040,7 +1040,7 @@ namespace sat {
else if (coeff0 < 0 && inc > 0) {
inc_bound(coeff0 - std::min(0LL, coeff1));
}
int64 lbound = static_cast<int64>(m_bound);
int64_t lbound = static_cast<int64_t>(m_bound);
// reduce coefficient to be no larger than bound.
if (coeff1 > lbound) {
@ -1051,12 +1051,12 @@ namespace sat {
}
}
int64 ba_solver::get_coeff(bool_var v) const {
int64_t ba_solver::get_coeff(bool_var v) const {
return m_coeffs.get(v, 0);
}
unsigned ba_solver::get_abs_coeff(bool_var v) const {
int64 c = get_coeff(v);
int64_t c = get_coeff(v);
if (c < INT_MIN+1 || c > UINT_MAX) {
m_overflow = true;
return UINT_MAX;
@ -1065,7 +1065,7 @@ namespace sat {
}
int ba_solver::get_int_coeff(bool_var v) const {
int64 c = m_coeffs.get(v, 0);
int64_t c = m_coeffs.get(v, 0);
if (c < INT_MIN || c > INT_MAX) {
m_overflow = true;
return 0;
@ -1073,12 +1073,12 @@ namespace sat {
return static_cast<int>(c);
}
void ba_solver::inc_bound(int64 i) {
void ba_solver::inc_bound(int64_t i) {
if (i < INT_MIN || i > INT_MAX) {
m_overflow = true;
return;
}
int64 new_bound = m_bound;
int64_t new_bound = m_bound;
new_bound += i;
if (new_bound < 0) {
m_overflow = true;
@ -1196,7 +1196,7 @@ namespace sat {
switch (cnstr.tag()) {
case card_t: {
card& c = cnstr.to_card();
inc_bound(static_cast<int64>(offset) * c.k());
inc_bound(static_cast<int64_t>(offset) * c.k());
process_card(c, offset);
break;
}
@ -1269,7 +1269,7 @@ namespace sat {
js = s().m_justification[v];
offset = get_abs_coeff(v);
if (offset > m_bound) {
int64 bound64 = static_cast<int64>(m_bound);
int64_t bound64 = static_cast<int64_t>(m_bound);
m_coeffs[v] = (get_coeff(v) < 0) ? -bound64 : bound64;
offset = m_bound;
DEBUG_CODE(active2pb(m_A););
@ -1323,8 +1323,8 @@ namespace sat {
}
IF_VERBOSE(0,
active2pb(m_A);
uint64 c = 0;
for (uint64 c1 : m_A.m_coeffs) c += c1;
uint64_t c = 0;
for (uint64_t c1 : m_A.m_coeffs) c += c1;
verbose_stream() << "sum of coefficients: " << c << "\n";
display(verbose_stream(), m_A, true);
verbose_stream() << "conflicting literal: " << s().m_not_l << "\n";);
@ -1347,18 +1347,18 @@ namespace sat {
bool adjusted = false;
adjust_conflict_level:
int64 bound64 = m_bound;
int64 slack = -bound64;
int64_t bound64 = m_bound;
int64_t slack = -bound64;
for (bool_var v : m_active_vars) {
slack += get_abs_coeff(v);
}
m_lemma.reset();
m_lemma.push_back(null_literal);
unsigned num_skipped = 0;
int64 asserting_coeff = 0;
int64_t asserting_coeff = 0;
for (unsigned i = 0; 0 <= slack && i < m_active_vars.size(); ++i) {
bool_var v = m_active_vars[i];
int64 coeff = get_coeff(v);
int64_t coeff = get_coeff(v);
lbool val = value(v);
bool is_true = val == l_true;
bool append = coeff != 0 && val != l_undef && (coeff < 0 == is_true);
@ -1434,7 +1434,7 @@ namespace sat {
continue;
}
if (m_bound < coeff) {
int64 bound64 = m_bound;
int64_t bound64 = m_bound;
if (get_coeff(v) > 0) {
m_coeffs[v] = bound64;
}
@ -1474,7 +1474,7 @@ namespace sat {
inc_coeff(c[i], offset);
}
if (lit != null_literal) {
uint64 offset1 = static_cast<uint64>(offset) * c.k();
uint64_t offset1 = static_cast<uint64_t>(offset) * c.k();
if (offset1 > UINT_MAX) {
m_overflow = true;
}
@ -3753,12 +3753,12 @@ namespace sat {
}
bool ba_solver::validate_lemma() {
int64 bound64 = m_bound;
int64 val = -bound64;
int64_t bound64 = m_bound;
int64_t val = -bound64;
reset_active_var_set();
for (bool_var v : m_active_vars) {
if (m_active_var_set.contains(v)) continue;
int64 coeff = get_coeff(v);
int64_t coeff = get_coeff(v);
if (coeff == 0) continue;
m_active_var_set.insert(v);
literal lit(v, false);
@ -3782,7 +3782,7 @@ namespace sat {
p.reset(m_bound);
for (bool_var v : m_active_vars) {
if (m_active_var_set.contains(v)) continue;
int64 coeff = get_coeff(v);
int64_t coeff = get_coeff(v);
if (coeff == 0) continue;
m_active_var_set.insert(v);
literal lit(v, coeff < 0);
@ -3794,7 +3794,7 @@ namespace sat {
ba_solver::constraint* ba_solver::active2constraint() {
reset_active_var_set();
m_wlits.reset();
uint64 sum = 0;
uint64_t sum = 0;
if (m_bound == 1) return 0;
if (m_overflow) return 0;
@ -3855,7 +3855,7 @@ namespace sat {
}
std::sort(m_wlits.begin(), m_wlits.end(), compare_wlit());
unsigned k = 0;
uint64 sum = 0, sum0 = 0;
uint64_t sum = 0, sum0 = 0;
for (wliteral wl : m_wlits) {
if (sum >= m_bound) break;
sum0 = sum;
@ -3986,15 +3986,15 @@ namespace sat {
bool ba_solver::validate_resolvent() {
return true;
u_map<uint64> coeffs;
uint64 k = m_A.m_k + m_B.m_k;
u_map<uint64_t> coeffs;
uint64_t k = m_A.m_k + m_B.m_k;
for (unsigned i = 0; i < m_A.m_lits.size(); ++i) {
uint64 coeff = m_A.m_coeffs[i];
uint64_t coeff = m_A.m_coeffs[i];
SASSERT(!coeffs.contains(m_A.m_lits[i].index()));
coeffs.insert(m_A.m_lits[i].index(), coeff);
}
for (unsigned i = 0; i < m_B.m_lits.size(); ++i) {
uint64 coeff1 = m_B.m_coeffs[i], coeff2;
uint64_t coeff1 = m_B.m_coeffs[i], coeff2;
literal lit = m_B.m_lits[i];
if (coeffs.find((~lit).index(), coeff2)) {
if (coeff1 == coeff2) {
@ -4022,7 +4022,7 @@ namespace sat {
// C is above the sum of A and B
for (unsigned i = 0; i < m_C.m_lits.size(); ++i) {
literal lit = m_C.m_lits[i];
uint64 coeff;
uint64_t coeff;
if (coeffs.find(lit.index(), coeff)) {
if (coeff > m_C.m_coeffs[i] && m_C.m_coeffs[i] < m_C.m_k) {
goto violated;
@ -4103,7 +4103,7 @@ namespace sat {
\brief encode the case where Sum(a) >= k-1 & Sum(b) >= 1 \/ ... \/ Sum(a) >= 1 & Sum(b) >= k-1
*/
literal ba_solver::translate_to_sat(solver& s, u_map<bool_var>& translation, ineq& a, ineq& b) {
uint64 k0 = a.m_k;
uint64_t k0 = a.m_k;
literal_vector lits;
for (unsigned k = 1; k < a.m_k - 1; ++k) {
a.m_k = k; b.m_k = k0 - k;
@ -4143,7 +4143,7 @@ namespace sat {
ba_solver::ineq ba_solver::negate(ineq const& a) const {
ineq result;
uint64 sum = 0;
uint64_t sum = 0;
for (unsigned i = 0; i < a.m_lits.size(); ++i) {
result.push(~a.m_lits[i], a.m_coeffs[i]);
sum += a.m_coeffs[i];
@ -4170,9 +4170,9 @@ namespace sat {
return false;
}
}
uint64 value = 0;
uint64_t value = 0;
for (unsigned i = 0; i < p.m_lits.size(); ++i) {
uint64 coeff = p.m_coeffs[i];
uint64_t coeff = p.m_coeffs[i];
if (!lits.contains(p.m_lits[i])) {
value += coeff;
}

View file

@ -204,12 +204,12 @@ namespace sat {
protected:
struct ineq {
literal_vector m_lits;
svector<uint64> m_coeffs;
uint64 m_k;
literal_vector m_lits;
svector<uint64_t> m_coeffs;
uint64_t m_k;
ineq(): m_k(0) {}
void reset(uint64 k) { m_lits.reset(); m_coeffs.reset(); m_k = k; }
void push(literal l, uint64 c) { m_lits.push_back(l); m_coeffs.push_back(c); }
void reset(uint64_t k) { m_lits.reset(); m_coeffs.reset(); m_k = k; }
void push(literal l, uint64_t c) { m_lits.push_back(l); m_coeffs.push_back(c); }
};
solver* m_solver;
@ -229,7 +229,7 @@ namespace sat {
// conflict resolution
unsigned m_num_marks;
unsigned m_conflict_lvl;
svector<int64> m_coeffs;
svector<int64_t> m_coeffs;
svector<bool_var> m_active_vars;
unsigned m_bound;
tracked_uint_set m_active_var_set;
@ -426,11 +426,11 @@ namespace sat {
void reset_active_var_set();
void normalize_active_coeffs();
void inc_coeff(literal l, unsigned offset);
int64 get_coeff(bool_var v) const;
int64_t get_coeff(bool_var v) const;
unsigned get_abs_coeff(bool_var v) const;
int get_int_coeff(bool_var v) const;
unsigned get_bound() const;
void inc_bound(int64 i);
void inc_bound(int64_t i);
literal get_asserting_literal(literal conseq);
void process_antecedent(literal l, unsigned offset);

View file

@ -105,7 +105,7 @@ namespace sat {
void asymm_branch::process(big* big, clause_vector& clauses) {
int64 limit = -m_asymm_branch_limit;
int64_t limit = -m_asymm_branch_limit;
std::stable_sort(clauses.begin(), clauses.end(), clause_size_lt());
m_counter -= clauses.size();
clause_vector::iterator it = clauses.begin();

View file

@ -33,7 +33,7 @@ namespace sat {
solver & s;
params_ref m_params;
int64 m_counter;
int64_t m_counter;
random_gen m_rand;
unsigned m_calls;
@ -43,7 +43,7 @@ namespace sat {
unsigned m_asymm_branch_delay;
bool m_asymm_branch_sampled;
bool m_asymm_branch_all;
int64 m_asymm_branch_limit;
int64_t m_asymm_branch_limit;
// stats
unsigned m_elim_literals;

View file

@ -47,7 +47,7 @@ namespace sat {
void lookahead::flip_prefix() {
if (m_trail_lim.size() < 64) {
uint64 mask = (1ull << m_trail_lim.size());
uint64_t mask = (1ull << m_trail_lim.size());
m_prefix = mask | (m_prefix & (mask - 1));
}
}
@ -909,7 +909,7 @@ namespace sat {
void lookahead::display_search_string() {
printf("\r");
uint64 q = m_prefix;
uint64_t q = m_prefix;
unsigned depth = m_trail_lim.size();
unsigned d = std::min(63u, depth);
unsigned new_prefix_length = d;

View file

@ -27,13 +27,13 @@ Notes:
namespace sat {
struct pp_prefix {
uint64 m_prefix;
uint64_t m_prefix;
unsigned m_depth;
pp_prefix(uint64 p, unsigned d) : m_prefix(p), m_depth(d) {}
pp_prefix(uint64_t p, unsigned d) : m_prefix(p), m_depth(d) {}
};
inline std::ostream& operator<<(std::ostream& out, pp_prefix const& p) {
uint64 q = p.m_prefix;
uint64_t q = p.m_prefix;
unsigned d = std::min(63u, p.m_depth);
for (unsigned i = 0; i <= d; ++i) {
if (0 != (p.m_prefix & (1ull << i))) out << "1"; else out << "0";
@ -238,7 +238,7 @@ namespace sat {
double m_lookahead_reward; // metric associated with current lookahead1 literal.
literal_vector m_wstack; // windofall stack that is populated in lookahead1 mode
unsigned m_last_prefix_length;
uint64 m_prefix; // where we are in search tree
uint64_t m_prefix; // where we are in search tree
svector<prefix> m_vprefix; // var: prefix where variable participates in propagation
unsigned m_rating_throttle; // throttle to recompute rating
indexed_uint_set m_freevars;
@ -523,7 +523,7 @@ namespace sat {
void update_lookahead_reward(literal l, unsigned level);
bool dl_enabled(literal l) const { return m_lits[l.index()].m_double_lookahead != m_istamp_id; }
void dl_disable(literal l) { m_lits[l.index()].m_double_lookahead = m_istamp_id; }
bool dl_no_overflow(unsigned base) const { return base + 2 * m_lookahead.size() * static_cast<uint64>(m_config.m_dl_max_iterations + 1) < c_fixed_truth; }
bool dl_no_overflow(unsigned base) const { return base + 2 * m_lookahead.size() * static_cast<uint64_t>(m_config.m_dl_max_iterations + 1) < c_fixed_truth; }
unsigned do_double(literal l, unsigned& base);
unsigned double_look(literal l, unsigned& base);

View file

@ -782,7 +782,7 @@ namespace sat {
}
if (m_config.m_anti_exploration) {
uint64 age = m_stats.m_conflict - m_canceled[v];
uint64_t age = m_stats.m_conflict - m_canceled[v];
if (age > 0) {
double decay = pow(0.95, age);
m_activity[v] = static_cast<unsigned>(m_activity[v] * decay);
@ -1032,7 +1032,7 @@ namespace sat {
return check_par(num_lits, lits);
}
flet<bool> _searching(m_searching, true);
if (m_mc.empty() && gparams::get().get_bool("model_validate", false)) {
if (m_mc.empty() && gparams::get_ref().get_bool("model_validate", false)) {
m_clone = alloc(solver, m_params, m_rlimit);
m_clone->copy(*this);
}
@ -3101,7 +3101,7 @@ namespace sat {
SASSERT(value(v) == l_undef);
m_case_split_queue.unassign_var_eh(v);
if (m_config.m_branching_heuristic == BH_LRB) {
uint64 interval = m_stats.m_conflict - m_last_propagation[v];
uint64_t interval = m_stats.m_conflict - m_last_propagation[v];
if (interval > 0) {
auto activity = m_activity[v];
auto reward = (m_config.m_reward_offset * (m_participated[v] + m_reasoned[v])) / interval;

View file

@ -120,11 +120,11 @@ namespace sat {
// branch variable selection:
svector<unsigned> m_activity;
unsigned m_activity_inc;
svector<uint64> m_last_conflict;
svector<uint64> m_last_propagation;
svector<uint64> m_participated;
svector<uint64> m_canceled;
svector<uint64> m_reasoned;
svector<uint64_t> m_last_conflict;
svector<uint64_t> m_last_propagation;
svector<uint64_t> m_participated;
svector<uint64_t> m_canceled;
svector<uint64_t> m_reasoned;
int m_action;
double m_step_size;
// phase

View file

@ -816,7 +816,7 @@ private:
TRACE("sat", model_smt2_pp(tout, m, *mdl, 0););
if (!gparams::get().get_bool("model_validate", false)) return;
if (!gparams::get_ref().get_bool("model_validate", false)) return;
IF_VERBOSE(0, verbose_stream() << "Verifying solution\n";);
model_evaluator eval(*mdl);
eval.set_model_completion(false);