3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-24 01:25:31 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2019-08-23 23:29:10 +03:00
parent de69b01e92
commit a337a51374
28 changed files with 486 additions and 144 deletions

View file

@ -181,6 +181,7 @@ namespace sat {
m_drat_file = p.drat_file();
m_drat = (m_drat_check_unsat || m_drat_file != symbol("") || m_drat_check_sat) && p.threads() == 1;
m_drat_binary = p.drat_binary();
m_drat_activity = p.drat_activity();
m_dyn_sub_res = p.dyn_sub_res();
// Parameters used in Liang, Ganesh, Poupart, Czarnecki AAAI 2016.

View file

@ -168,6 +168,7 @@ namespace sat {
symbol m_drat_file;
bool m_drat_check_unsat;
bool m_drat_check_sat;
bool m_drat_activity;
bool m_card_solver;
bool m_xor_solver;

View file

@ -31,12 +31,15 @@ namespace sat {
m_inconsistent(false),
m_check_unsat(false),
m_check_sat(false),
m_check(false)
m_check(false),
m_activity(false),
m_num_add(0),
m_num_del(0)
{
if (s.m_config.m_drat && s.m_config.m_drat_file != symbol()) {
auto mode = s.m_config.m_drat_binary ? (std::ios_base::binary | std::ios_base::out | std::ios_base::trunc) : std::ios_base::out;
m_out = alloc(std::ofstream, s.m_config.m_drat_file.str().c_str(), mode);
if (s.m_config.m_drat_binary) {
if (s.get_config().m_drat && s.get_config().m_drat_file != symbol()) {
auto mode = s.get_config().m_drat_binary ? (std::ios_base::binary | std::ios_base::out | std::ios_base::trunc) : std::ios_base::out;
m_out = alloc(std::ofstream, s.get_config().m_drat_file.str().c_str(), mode);
if (s.get_config().m_drat_binary) {
std::swap(m_out, m_bout);
}
}
@ -59,9 +62,10 @@ namespace sat {
}
void drat::updt_config() {
m_check_unsat = s.m_config.m_drat_check_unsat;
m_check_sat = s.m_config.m_drat_check_sat;
m_check_unsat = s.get_config().m_drat_check_unsat;
m_check_sat = s.get_config().m_drat_check_sat;
m_check = m_check_unsat || m_check_sat;
m_activity = s.get_config().m_drat_activity;
}
std::ostream& operator<<(std::ostream& out, drat::status st) {
@ -78,6 +82,9 @@ namespace sat {
if (st == status::asserted || st == status::external) {
return;
}
if (m_activity && ((m_num_add % 1000) == 0)) {
dump_activity();
}
char buffer[10000];
char digits[20]; // enough for storing unsigned
@ -114,6 +121,14 @@ namespace sat {
m_out->write(buffer, len);
}
void drat::dump_activity() {
(*m_out) << "c a ";
for (unsigned v = 0; v < s.num_vars(); ++v) {
(*m_out) << s.m_activity[v] << " ";
}
(*m_out) << "\n";
}
void drat::bdump(unsigned n, literal const* c, status st) {
unsigned char ch = 0;
switch (st) {
@ -648,6 +663,7 @@ namespace sat {
}
void drat::add() {
++m_num_add;
if (m_out) (*m_out) << "0\n";
if (m_bout) bdump(0, nullptr, status::learned);
if (m_check_unsat) {
@ -655,12 +671,14 @@ namespace sat {
}
}
void drat::add(literal l, bool learned) {
++m_num_add;
status st = get_status(learned);
if (m_out) dump(1, &l, st);
if (m_bout) bdump(1, &l, st);
if (m_check) append(l, st);
}
void drat::add(literal l1, literal l2, bool learned) {
++m_num_add;
literal ls[2] = {l1, l2};
status st = get_status(learned);
if (m_out) dump(2, ls, st);
@ -668,6 +686,7 @@ namespace sat {
if (m_check) append(l1, l2, st);
}
void drat::add(clause& c, bool learned) {
++m_num_add;
status st = get_status(learned);
if (m_out) dump(c.size(), c.begin(), st);
if (m_bout) bdump(c.size(), c.begin(), st);
@ -677,6 +696,7 @@ namespace sat {
}
}
void drat::add(literal_vector const& lits, svector<premise> const& premises) {
++m_num_add;
if (m_check) {
switch (lits.size()) {
case 0: add(); break;
@ -690,6 +710,7 @@ namespace sat {
}
}
void drat::add(literal_vector const& c) {
++m_num_add;
if (m_out) dump(c.size(), c.begin(), status::learned);
if (m_bout) bdump(c.size(), c.begin(), status::learned);
if (m_check) {
@ -708,12 +729,14 @@ namespace sat {
}
void drat::del(literal l) {
++m_num_del;
if (m_out) dump(1, &l, status::deleted);
if (m_bout) bdump(1, &l, status::deleted);
if (m_check_unsat) append(l, status::deleted);
}
void drat::del(literal l1, literal l2) {
++m_num_del;
literal ls[2] = {l1, l2};
SASSERT(!(l1 == literal(13923, false) && l2 == literal(14020, true)));
if (m_out) dump(2, ls, status::deleted);
@ -733,7 +756,7 @@ namespace sat {
m_seen[lit.index()] = false;
}
#endif
++m_num_del;
//SASSERT(!(c.size() == 2 && c[0] == literal(13923, false) && c[1] == literal(14020, true)));
if (m_out) dump(c.size(), c.begin(), status::deleted);
if (m_bout) bdump(c.size(), c.begin(), status::deleted);

View file

@ -49,13 +49,15 @@ namespace sat {
std::ostream* m_out;
std::ostream* m_bout;
ptr_vector<clause> m_proof;
svector<status> m_status;
svector<status> m_status;
literal_vector m_units;
vector<watch> m_watches;
svector<lbool> m_assignment;
bool m_inconsistent;
bool m_check_unsat, m_check_sat, m_check;
unsigned m_num_add, m_num_del;
bool m_check_unsat, m_check_sat, m_check, m_activity;
void dump_activity();
void dump(unsigned n, literal const* c, status st);
void bdump(unsigned n, literal const* c, status st);
void append(literal l, status st);

View file

@ -48,6 +48,7 @@ def_module_params('sat',
('drat.binary', BOOL, False, 'use Binary DRAT output format'),
('drat.check_unsat', BOOL, False, 'build up internal proof and check'),
('drat.check_sat', BOOL, False, 'build up internal trace, check satisfying model'),
('drat.activity', BOOL, False, 'dump variable activities'),
('cardinality.solver', BOOL, True, 'use cardinality solver'),
('pb.solver', SYMBOL, 'solver', 'method for handling Pseudo-Boolean constraints: circuit (arithmetical circuit), sorting (sorting circuit), totalizer (use totalizer encoding), binary_merge, segmented, solver (use native solver)'),
('pb.min_arity', UINT, 9, 'minimal arity to compile pb/cardinality constraints to CNF'),

View file

@ -885,10 +885,9 @@ namespace sat {
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);
set_activity(v, static_cast<unsigned>(m_activity[v] * decay));
// NB. MapleSAT does not update canceled.
m_canceled[v] = m_stats.m_conflict;
m_case_split_queue.activity_changed_eh(v, false);
}
}
@ -1532,8 +1531,7 @@ namespace sat {
next = m_case_split_queue.min_var();
auto age = m_stats.m_conflict - m_canceled[next];
while (age > 0) {
m_activity[next] = static_cast<unsigned>(m_activity[next] * pow(0.95, age));
m_case_split_queue.activity_changed_eh(next, false);
set_activity(next, static_cast<unsigned>(m_activity[next] * pow(0.95, age)));
m_canceled[next] = m_stats.m_conflict;
next = m_case_split_queue.min_var();
age = m_stats.m_conflict - m_canceled[next];
@ -1792,10 +1790,12 @@ namespace sat {
return tracking_assumptions() && m_assumption_set.contains(l);
}
void solver::set_activity(bool_var v, unsigned act) {
void solver::set_activity(bool_var v, unsigned new_act) {
unsigned old_act = m_activity[v];
m_activity[v] = act;
m_case_split_queue.activity_changed_eh(v, act > old_act);
m_activity[v] = new_act;
if (!was_eliminated(v) && value(v) == l_undef && new_act != old_act) {
m_case_split_queue.activity_changed_eh(v, new_act > old_act);
}
}
bool solver::is_assumption(bool_var v) const {
@ -2195,14 +2195,9 @@ namespace sat {
}
}
void solver::update_activity(bool_var v, double p) {
unsigned old_act = m_activity[v];
unsigned new_act = (unsigned) (num_vars() * m_config.m_activity_scale * p);
m_activity[v] = new_act;
if (!was_eliminated(v) && value(v) == l_undef && new_act != old_act) {
m_case_split_queue.activity_changed_eh(v, new_act > old_act);
}
set_activity(v, new_act);
}
void solver::set_next_restart() {
@ -3705,8 +3700,7 @@ namespace sat {
if (interval > 0) {
auto activity = m_activity[v];
auto reward = (m_config.m_reward_offset * (m_participated[v] + m_reasoned[v])) / interval;
m_activity[v] = static_cast<unsigned>(m_step_size * reward + ((1 - m_step_size) * activity));
m_case_split_queue.activity_changed_eh(v, m_activity[v] > activity);
set_activity(v, static_cast<unsigned>(m_step_size * reward + ((1 - m_step_size) * activity)));
}
}
if (m_config.m_anti_exploration) {
@ -3966,10 +3960,9 @@ namespace sat {
double multiplier = m_config.m_reward_offset * (is_sat ? m_config.m_reward_multiplier : 1.0);
for (unsigned i = qhead; i < m_trail.size(); ++i) {
auto v = m_trail[i].var();
auto reward = multiplier / (m_stats.m_conflict - m_last_conflict[v] + 1);
auto reward = multiplier / (m_stats.m_conflict - m_last_conflict[v] + 1);
auto activity = m_activity[v];
m_activity[v] = static_cast<unsigned>(m_step_size * reward + ((1.0 - m_step_size) * activity));
m_case_split_queue.activity_changed_eh(v, m_activity[v] > activity);
set_activity(v, static_cast<unsigned>(m_step_size * reward + ((1.0 - m_step_size) * activity)));
}
}