3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-27 08:28:44 +00:00

add cube functionality

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2017-09-24 13:29:46 -07:00
parent ae9a6664d4
commit 82922d92f7
4 changed files with 83 additions and 58 deletions

View file

@ -820,6 +820,15 @@ namespace sat {
}
return out;
}
void lookahead::display_search_string() {
printf("\r");
std::stringstream strm;
strm << pp_prefix(m_prefix, m_trail_lim.size());
for (unsigned i = 0; i < 50; ++i) strm << " ";
printf(strm.str().c_str());
fflush(stdout);
}
void lookahead::construct_lookahead_table() {
literal u = get_child(null_literal), v = null_literal;
@ -1710,47 +1719,6 @@ namespace sat {
return true;
}
void lookahead::cube() {
m_model.reset();
scoped_level _sl(*this, c_fixed_truth);
literal_vector trail;
m_search_mode = lookahead_mode::searching;
double freevars_threshold = 0;
while (true) {
TRACE("sat", display(tout););
inc_istamp();
checkpoint();
literal l = choose();
if (inconsistent()) {
freevars_threshold = m_freevars.size();
if (!backtrack(trail)) return;
continue;
}
unsigned depth = m_trail_lim.size();
if (l == null_literal ||
(m_config.m_cube_cutoff != 0 && depth == m_config.m_cube_cutoff) ||
(m_config.m_cube_cutoff == 0 && m_freevars.size() < freevars_threshold)) {
display_cube(std::cout);
set_conflict();
if (!backtrack(trail)) return;
freevars_threshold *= (1.0 - pow(m_config.m_cube_fraction, depth));
continue;
}
TRACE("sat", tout << "choose: " << l << " " << trail << "\n";);
++m_stats.m_decisions;
IF_VERBOSE(1, printf("\r");
std::stringstream strm;
strm << pp_prefix(m_prefix, m_trail_lim.size());
for (unsigned i = 0; i < 50; ++i) strm << " ";
printf(strm.str().c_str());
fflush(stdout);
);
push(l, c_fixed_truth);
trail.push_back(l);
SASSERT(inconsistent() || !is_unsat());
}
}
lbool lookahead::search() {
m_model.reset();
scoped_level _sl(*this, c_fixed_truth);
@ -1770,19 +1738,73 @@ namespace sat {
}
TRACE("sat", tout << "choose: " << l << " " << trail << "\n";);
++m_stats.m_decisions;
IF_VERBOSE(1, printf("\r");
std::stringstream strm;
strm << pp_prefix(m_prefix, m_trail_lim.size());
for (unsigned i = 0; i < 50; ++i) strm << " ";
printf(strm.str().c_str());
fflush(stdout);
);
IF_VERBOSE(1, display_search_string(););
push(l, c_fixed_truth);
trail.push_back(l);
SASSERT(inconsistent() || !is_unsat());
}
}
bool lookahead::backtrack(literal_vector& trail, svector<bool> & is_decision) {
while (inconsistent()) {
if (trail.empty()) return false;
if (is_decision.back()) {
pop();
trail.back().neg();
assign(trail.back());
is_decision.back() = false;
propagate();
}
else {
trail.pop_back();
is_decision.pop_back();
}
}
return true;
}
lbool lookahead::cube() {
lbool result = l_false;
init_search();
m_model.reset();
scoped_level _sl(*this, c_fixed_truth);
literal_vector cube;
svector<bool> is_decision;
m_search_mode = lookahead_mode::searching;
double freevars_threshold = 0;
while (true) {
TRACE("sat", display(tout););
inc_istamp();
checkpoint();
literal l = choose();
if (inconsistent()) {
TRACE("sat", tout << "inconsistent: " << cube << "\n";);
freevars_threshold = m_freevars.size();
if (!backtrack(cube, is_decision)) return result;
continue;
}
if (l == null_literal) {
return l_true;
}
unsigned depth = cube.size();
if ((m_config.m_cube_cutoff != 0 && depth == m_config.m_cube_cutoff) ||
(m_config.m_cube_cutoff == 0 && m_freevars.size() < freevars_threshold)) {
display_cube(std::cout, cube);
freevars_threshold *= (1.0 - pow(m_config.m_cube_fraction, depth));
result = l_undef;
set_conflict();
if (!backtrack(cube, is_decision)) return result;
continue;
}
TRACE("sat", tout << "choose: " << l << " cube: " << cube << "\n";);
++m_stats.m_decisions;
push(l, c_fixed_truth);
cube.push_back(l);
is_decision.push_back(true);
SASSERT(inconsistent() || !is_unsat());
}
}
void lookahead::init_model() {
m_model.reset();
for (unsigned i = 0; i < m_num_vars; ++i) {
@ -1801,12 +1823,12 @@ namespace sat {
}
}
std::ostream& lookahead::display_cube(std::ostream& out) const {
std::ostream& lookahead::display_cube(std::ostream& out, literal_vector const& cube) const {
out << "c";
for (literal l : m_assumptions) {
for (literal l : cube) {
out << " " << ~l;
}
return out << "\n";
return out << " 0\n";
}
std::ostream& lookahead::display_binary(std::ostream& out) const {