mirror of
https://github.com/Z3Prover/z3
synced 2025-06-05 21:53:23 +00:00
update core generation to be partial, update maxres to use current model too
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
3f8083dfa6
commit
b5bbf83847
9 changed files with 36 additions and 17 deletions
|
@ -367,8 +367,12 @@ private:
|
||||||
|
|
||||||
void extract_model() {
|
void extract_model() {
|
||||||
TRACE("sat", tout << "retrieve model\n";);
|
TRACE("sat", tout << "retrieve model\n";);
|
||||||
model_ref md = alloc(model, m);
|
|
||||||
sat::model const & ll_m = m_solver.get_model();
|
sat::model const & ll_m = m_solver.get_model();
|
||||||
|
if (ll_m.empty()) {
|
||||||
|
m_model = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
model_ref md = alloc(model, m);
|
||||||
atom2bool_var::iterator it = m_map.begin();
|
atom2bool_var::iterator it = m_map.begin();
|
||||||
atom2bool_var::iterator end = m_map.end();
|
atom2bool_var::iterator end = m_map.end();
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it) {
|
||||||
|
|
|
@ -156,7 +156,7 @@ public:
|
||||||
lbool mus_solver() {
|
lbool mus_solver() {
|
||||||
init();
|
init();
|
||||||
init_local();
|
init_local();
|
||||||
while (true) {
|
while (m_lower < m_upper) {
|
||||||
TRACE("opt",
|
TRACE("opt",
|
||||||
display_vec(tout, m_asms.size(), m_asms.c_ptr());
|
display_vec(tout, m_asms.size(), m_asms.c_ptr());
|
||||||
s().display(tout);
|
s().display(tout);
|
||||||
|
@ -167,6 +167,7 @@ public:
|
||||||
if (m_cancel) {
|
if (m_cancel) {
|
||||||
return l_undef;
|
return l_undef;
|
||||||
}
|
}
|
||||||
|
model_ref mdl;
|
||||||
switch (is_sat) {
|
switch (is_sat) {
|
||||||
case l_true:
|
case l_true:
|
||||||
found_optimum();
|
found_optimum();
|
||||||
|
@ -174,6 +175,7 @@ public:
|
||||||
case l_false:
|
case l_false:
|
||||||
is_sat = process_unsat();
|
is_sat = process_unsat();
|
||||||
if (is_sat != l_true) return is_sat;
|
if (is_sat != l_true) return is_sat;
|
||||||
|
get_mus_model(mdl);
|
||||||
break;
|
break;
|
||||||
case l_undef:
|
case l_undef:
|
||||||
return l_undef;
|
return l_undef;
|
||||||
|
@ -359,14 +361,16 @@ public:
|
||||||
// likewise, if the cores are too big, don't block the cores.
|
// likewise, if the cores are too big, don't block the cores.
|
||||||
//
|
//
|
||||||
|
|
||||||
process_unsat(cores);
|
|
||||||
|
|
||||||
exprs cs;
|
exprs cs;
|
||||||
get_current_correction_set(cs);
|
get_current_correction_set(cs);
|
||||||
unsigned max_core = max_core_size(cores);
|
unsigned max_core = max_core_size(cores);
|
||||||
if (cs.size() <= std::max(max_core, m_max_correction_set_size)) {
|
if (!cs.empty() && cs.size() < max_core) {
|
||||||
process_sat(cs);
|
process_sat(cs);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
process_unsat(cores);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_lower = m_upper;
|
m_lower = m_upper;
|
||||||
|
@ -465,6 +469,7 @@ public:
|
||||||
cs.push_back(m_asms[i].get());
|
cs.push_back(m_asms[i].get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
IF_VERBOSE(2, verbose_stream() << "(opt.maxres correction set size: " << cs.size() << ")\n";);
|
||||||
TRACE("opt", display_vec(tout << "new correction set: ", cs.size(), cs.c_ptr()););
|
TRACE("opt", display_vec(tout << "new correction set: ", cs.size(), cs.c_ptr()););
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,7 +559,7 @@ public:
|
||||||
if (m_c.sat_enabled()) {
|
if (m_c.sat_enabled()) {
|
||||||
// SAT solver core extracts some model
|
// SAT solver core extracts some model
|
||||||
// during unsat core computation.
|
// during unsat core computation.
|
||||||
s().get_model(mdl);
|
s().get_model(mdl);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
w = m_mus.get_best_model(mdl);
|
w = m_mus.get_best_model(mdl);
|
||||||
|
|
|
@ -451,7 +451,7 @@ namespace opt {
|
||||||
m_maxsat_engine != symbol("sls")) {
|
m_maxsat_engine != symbol("sls")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_params.set_bool("minimize_core", true);
|
m_params.set_bool("minimize_core_partial", true);
|
||||||
m_sat_solver = mk_inc_sat_solver(m, m_params);
|
m_sat_solver = mk_inc_sat_solver(m, m_params);
|
||||||
unsigned sz = get_solver().get_num_assertions();
|
unsigned sz = get_solver().get_num_assertions();
|
||||||
for (unsigned i = 0; i < sz; ++i) {
|
for (unsigned i = 0; i < sz; ++i) {
|
||||||
|
|
|
@ -105,6 +105,7 @@ namespace sat {
|
||||||
}
|
}
|
||||||
m_minimize_lemmas = p.minimize_lemmas();
|
m_minimize_lemmas = p.minimize_lemmas();
|
||||||
m_minimize_core = p.minimize_core();
|
m_minimize_core = p.minimize_core();
|
||||||
|
m_minimize_core_partial = p.minimize_core_partial();
|
||||||
m_optimize_model = p.optimize_model();
|
m_optimize_model = p.optimize_model();
|
||||||
m_dyn_sub_res = p.dyn_sub_res();
|
m_dyn_sub_res = p.dyn_sub_res();
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ namespace sat {
|
||||||
bool m_minimize_lemmas;
|
bool m_minimize_lemmas;
|
||||||
bool m_dyn_sub_res;
|
bool m_dyn_sub_res;
|
||||||
bool m_minimize_core;
|
bool m_minimize_core;
|
||||||
|
bool m_minimize_core_partial;
|
||||||
bool m_optimize_model;
|
bool m_optimize_model;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,9 @@ namespace sat {
|
||||||
}
|
}
|
||||||
|
|
||||||
lbool mus::operator()() {
|
lbool mus::operator()() {
|
||||||
|
bool minimize_partial = s.m_config.m_minimize_core_partial;
|
||||||
flet<bool> _disable_min(s.m_config.m_minimize_core, false);
|
flet<bool> _disable_min(s.m_config.m_minimize_core, false);
|
||||||
|
flet<bool> _disable_min_partial(s.m_config.m_minimize_core_partial, false);
|
||||||
flet<bool> _disable_opt(s.m_config.m_optimize_model, false);
|
flet<bool> _disable_opt(s.m_config.m_optimize_model, false);
|
||||||
flet<bool> _is_active(m_is_active, true);
|
flet<bool> _is_active(m_is_active, true);
|
||||||
TRACE("sat", tout << "old core: " << s.get_core() << "\n";);
|
TRACE("sat", tout << "old core: " << s.get_core() << "\n";);
|
||||||
|
@ -58,7 +60,7 @@ namespace sat {
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unsigned delta_time = 0;
|
||||||
while (!core.empty()) {
|
while (!core.empty()) {
|
||||||
IF_VERBOSE(2, verbose_stream() << "(opt.mus reducing core: " << core.size() << " new core: " << mus.size() << ")\n";);
|
IF_VERBOSE(2, verbose_stream() << "(opt.mus reducing core: " << core.size() << " new core: " << mus.size() << ")\n";);
|
||||||
TRACE("sat",
|
TRACE("sat",
|
||||||
|
@ -69,6 +71,11 @@ namespace sat {
|
||||||
set_core();
|
set_core();
|
||||||
return l_undef;
|
return l_undef;
|
||||||
}
|
}
|
||||||
|
if (minimize_partial && delta_time > 4) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
unsigned num_literals = core.size() + mus.size();
|
||||||
|
|
||||||
literal lit = core.back();
|
literal lit = core.back();
|
||||||
core.pop_back();
|
core.pop_back();
|
||||||
unsigned sz = mus.size();
|
unsigned sz = mus.size();
|
||||||
|
@ -99,14 +106,6 @@ namespace sat {
|
||||||
if (new_core.contains(~lit)) {
|
if (new_core.contains(~lit)) {
|
||||||
mus.resize(sz);
|
mus.resize(sz);
|
||||||
break;
|
break;
|
||||||
#if 0
|
|
||||||
mus.pop_back();
|
|
||||||
is_sat = s.check(mus.size(), mus.c_ptr());
|
|
||||||
SASSERT(is_sat != l_true);
|
|
||||||
if (is_sat != l_false) {
|
|
||||||
return l_undef;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
mus.resize(sz);
|
mus.resize(sz);
|
||||||
TRACE("sat", tout << "new core: " << new_core << "\n";);
|
TRACE("sat", tout << "new core: " << new_core << "\n";);
|
||||||
|
@ -119,6 +118,14 @@ namespace sat {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned new_num_literals = core.size() + mus.size();
|
||||||
|
if (new_num_literals == num_literals) {
|
||||||
|
delta_time++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
delta_time = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TRACE("sat", tout << "new core: " << mus << "\n";);
|
TRACE("sat", tout << "new core: " << mus << "\n";);
|
||||||
set_core();
|
set_core();
|
||||||
|
|
|
@ -19,5 +19,6 @@ def_module_params('sat',
|
||||||
('minimize_lemmas', BOOL, True, 'minimize learned clauses'),
|
('minimize_lemmas', BOOL, True, 'minimize learned clauses'),
|
||||||
('dyn_sub_res', BOOL, True, 'dynamic subsumption resolution for minimizing learned clauses'),
|
('dyn_sub_res', BOOL, True, 'dynamic subsumption resolution for minimizing learned clauses'),
|
||||||
('minimize_core', BOOL, False, 'minimize computed core'),
|
('minimize_core', BOOL, False, 'minimize computed core'),
|
||||||
|
('minimize_core_partial', BOOL, False, 'apply partial (cheap) core minimization'),
|
||||||
('optimize_model', BOOL, False, 'enable optimization of soft constraints'),
|
('optimize_model', BOOL, False, 'enable optimization of soft constraints'),
|
||||||
('dimacs.core', BOOL, False, 'extract core from DIMACS benchmarks')))
|
('dimacs.core', BOOL, False, 'extract core from DIMACS benchmarks')))
|
||||||
|
|
|
@ -1730,7 +1730,7 @@ namespace sat {
|
||||||
idx--;
|
idx--;
|
||||||
}
|
}
|
||||||
reset_unmark(old_size);
|
reset_unmark(old_size);
|
||||||
if (m_config.m_minimize_core) {
|
if (m_config.m_minimize_core || m_config.m_minimize_core_partial) {
|
||||||
// TBD:
|
// TBD:
|
||||||
// apply optional clause minimization by detecting subsumed literals.
|
// apply optional clause minimization by detecting subsumed literals.
|
||||||
// initial experiment suggests it has no effect.
|
// initial experiment suggests it has no effect.
|
||||||
|
|
|
@ -938,7 +938,7 @@ namespace smt {
|
||||||
m_new_atoms.pop_back();
|
m_new_atoms.pop_back();
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ptr_vector<atom> occs(m_var_occs[v]);
|
ptr_vector<atom> occs(m_var_occs[v]);
|
||||||
|
|
||||||
std::sort(atoms.begin(), atoms.end(), compare_atoms());
|
std::sort(atoms.begin(), atoms.end(), compare_atoms());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue