mirror of
https://github.com/Z3Prover/z3
synced 2025-08-26 13:06:05 +00:00
merge
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
commit
6582330cc4
13 changed files with 126 additions and 61 deletions
|
@ -187,6 +187,10 @@ namespace smt {
|
|||
SASSERT(m_todo_js_qhead <= m_todo_js.size());
|
||||
m_antecedents = &result;
|
||||
mark_justification(js);
|
||||
process_justifications();
|
||||
}
|
||||
|
||||
void conflict_resolution::process_justifications() {
|
||||
while (true) {
|
||||
unsigned sz = m_todo_js.size();
|
||||
while (m_todo_js_qhead < sz) {
|
||||
|
@ -234,6 +238,17 @@ namespace smt {
|
|||
SASSERT(m_todo_eqs.empty());
|
||||
}
|
||||
|
||||
void conflict_resolution::eq2literals(enode* n1, enode* n2, literal_vector & result) {
|
||||
SASSERT(m_todo_js.empty());
|
||||
SASSERT(m_todo_js_qhead == 0);
|
||||
SASSERT(m_todo_eqs.empty());
|
||||
m_antecedents = &result;
|
||||
m_todo_eqs.push_back(enode_pair(n1, n2));
|
||||
process_justifications();
|
||||
unmark_justifications(0);
|
||||
SASSERT(m_todo_eqs.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return maximum scope level of an antecedent literal of js.
|
||||
*/
|
||||
|
|
|
@ -168,6 +168,7 @@ namespace smt {
|
|||
void eq_branch2literals(enode * n1, enode * n2);
|
||||
void eq2literals(enode * n1, enode * n2);
|
||||
void justification2literals_core(justification * js, literal_vector & result) ;
|
||||
void process_justifications();
|
||||
void unmark_justifications(unsigned old_js_qhead);
|
||||
|
||||
literal_vector m_tmp_literal_vector;
|
||||
|
@ -257,6 +258,8 @@ namespace smt {
|
|||
|
||||
void justification2literals(justification * js, literal_vector & result);
|
||||
|
||||
void eq2literals(enode * n1, enode * n2, literal_vector & result);
|
||||
|
||||
};
|
||||
|
||||
inline void mark_literals(conflict_resolution & cr, unsigned sz, literal const * ls) {
|
||||
|
|
|
@ -102,7 +102,7 @@ namespace smt {
|
|||
}
|
||||
}
|
||||
|
||||
void context::delete_unfixed(obj_map<expr, expr*>& var2val, expr_ref_vector& unfixed) {
|
||||
unsigned context::delete_unfixed(obj_map<expr, expr*>& var2val, expr_ref_vector& unfixed) {
|
||||
ast_manager& m = m_manager;
|
||||
ptr_vector<expr> to_delete;
|
||||
obj_map<expr,expr*>::iterator it = var2val.begin(), end = var2val.end();
|
||||
|
@ -141,6 +141,49 @@ namespace smt {
|
|||
var2val.remove(to_delete[i]);
|
||||
unfixed.push_back(to_delete[i]);
|
||||
}
|
||||
return to_delete.size();
|
||||
}
|
||||
|
||||
//
|
||||
// Extract equalities that are congruent at the search level.
|
||||
//
|
||||
unsigned context::extract_fixed_eqs(obj_map<expr, expr*>& var2val, expr_ref_vector& conseq) {
|
||||
ast_manager& m = m_manager;
|
||||
ptr_vector<expr> to_delete;
|
||||
expr_ref fml(m), eq(m);
|
||||
obj_map<expr,expr*>::iterator it = var2val.begin(), end = var2val.end();
|
||||
for (; it != end; ++it) {
|
||||
expr* k = it->m_key;
|
||||
expr* v = it->m_value;
|
||||
if (!m.is_bool(k) && e_internalized(k) && e_internalized(v) &&
|
||||
get_enode(k)->get_root() == get_enode(v)->get_root()) {
|
||||
literal_vector literals;
|
||||
m_conflict_resolution->eq2literals(get_enode(v), get_enode(k), literals);
|
||||
uint_set s;
|
||||
for (unsigned i = 0; i < literals.size(); ++i) {
|
||||
SASSERT(get_assign_level(literals[i]) <= get_search_level());
|
||||
s |= m_antecedents.find(literals[i].var());
|
||||
}
|
||||
|
||||
fml = m.mk_eq(k, v);
|
||||
fml = m.mk_implies(antecedent2fml(s), fml);
|
||||
conseq.push_back(fml);
|
||||
to_delete.push_back(k);
|
||||
|
||||
for (unsigned i = 0; i < literals.size(); ++i) {
|
||||
literals[i].neg();
|
||||
}
|
||||
eq = mk_eq_atom(k, v);
|
||||
internalize_formula(eq, false);
|
||||
literal lit(get_bool_var(eq), true);
|
||||
literals.push_back(lit);
|
||||
mk_clause(literals.size(), literals.c_ptr(), 0);
|
||||
}
|
||||
}
|
||||
for (unsigned i = 0; i < to_delete.size(); ++i) {
|
||||
var2val.remove(to_delete[i]);
|
||||
}
|
||||
return to_delete.size();
|
||||
}
|
||||
|
||||
lbool context::get_consequences(expr_ref_vector const& assumptions,
|
||||
|
@ -183,6 +226,9 @@ namespace smt {
|
|||
m_case_split_queue->init_search_eh();
|
||||
unsigned num_iterations = 0;
|
||||
unsigned model_threshold = 2;
|
||||
unsigned num_unfixed = 0;
|
||||
unsigned num_fixed_eqs = 0;
|
||||
unsigned num_reiterations = 0;
|
||||
while (!var2val.empty()) {
|
||||
obj_map<expr,expr*>::iterator it = var2val.begin();
|
||||
expr* e = it->m_key;
|
||||
|
@ -221,7 +267,7 @@ namespace smt {
|
|||
else if (get_assign_level(lit) > get_search_level()) {
|
||||
TRACE("context", tout << "Retry fixing: " << mk_pp(e, m) << "\n";);
|
||||
pop_to_search_lvl();
|
||||
IF_VERBOSE(1, verbose_stream() << "(get-consequences re-iterating)\n";);
|
||||
++num_reiterations;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
|
@ -229,22 +275,37 @@ namespace smt {
|
|||
}
|
||||
++num_iterations;
|
||||
|
||||
TRACE("context", tout << "Unfixed variables: " << var2val.size() << "\n";);
|
||||
if (model_threshold <= num_iterations || num_iterations <= 2) {
|
||||
unsigned num_deleted = unfixed.size();
|
||||
delete_unfixed(var2val, unfixed);
|
||||
num_deleted = unfixed.size() - num_deleted;
|
||||
bool apply_slow_pass = model_threshold <= num_iterations || num_iterations <= 2;
|
||||
if (apply_slow_pass) {
|
||||
num_unfixed += delete_unfixed(var2val, unfixed);
|
||||
// The next time we check the model is after 1.5 additional iterations.
|
||||
model_threshold *= 3;
|
||||
model_threshold /= 2;
|
||||
IF_VERBOSE(1, verbose_stream() << "(get-consequences deleting: " << num_deleted << " num-values: " << var2val.size() << " num-iterations: " << num_iterations << ")\n";);
|
||||
|
||||
model_threshold /= 2;
|
||||
}
|
||||
// repeat until we either have a model with negated literal or
|
||||
// the literal is implied at base.
|
||||
|
||||
extract_fixed_consequences(num_units, var2val, _assumptions, conseq);
|
||||
num_units = assigned_literals().size();
|
||||
if (apply_slow_pass) {
|
||||
num_fixed_eqs += extract_fixed_eqs(var2val, conseq);
|
||||
IF_VERBOSE(1, verbose_stream() << "(get-consequences"
|
||||
<< " iterations: " << num_iterations
|
||||
<< " variables: " << var2val.size()
|
||||
<< " fixed: " << conseq.size()
|
||||
<< " unfixed: " << unfixed.size()
|
||||
<< " fixed-eqs: " << num_fixed_eqs
|
||||
<< " unfixed-deleted: " << num_unfixed
|
||||
<< ")\n";);
|
||||
TRACE("context", tout << "(get-consequences"
|
||||
<< " iterations: " << num_iterations
|
||||
<< " variables: " << var2val.size()
|
||||
<< " fixed: " << conseq.size()
|
||||
<< " unfixed: " << unfixed.size()
|
||||
<< " fixed-eqs: " << num_fixed_eqs
|
||||
<< " unfixed-deleted: " << num_unfixed
|
||||
<< ")\n";);
|
||||
}
|
||||
if (var2val.contains(e)) {
|
||||
TRACE("context", tout << "Fixed value to " << mk_pp(e, m) << " was not processed\n";);
|
||||
expr_ref fml(m);
|
||||
|
|
|
@ -1347,7 +1347,9 @@ namespace smt {
|
|||
u_map<uint_set> m_antecedents;
|
||||
void extract_fixed_consequences(unsigned idx, obj_map<expr, expr*>& var2val, uint_set const& assumptions, expr_ref_vector& conseq);
|
||||
|
||||
void delete_unfixed(obj_map<expr, expr*>& var2val, expr_ref_vector& unfixed);
|
||||
unsigned delete_unfixed(obj_map<expr, expr*>& var2val, expr_ref_vector& unfixed);
|
||||
|
||||
unsigned extract_fixed_eqs(obj_map<expr, expr*>& var2val, expr_ref_vector& conseq);
|
||||
|
||||
expr_ref antecedent2fml(uint_set const& ante);
|
||||
|
||||
|
|
|
@ -55,6 +55,18 @@ namespace smt {
|
|||
void set_progress_callback(progress_callback * callback) {
|
||||
return m_kernel.set_progress_callback(callback);
|
||||
}
|
||||
|
||||
void display(std::ostream & out) const {
|
||||
// m_kernel.display(out); <<< for external users it is just junk
|
||||
// TODO: it will be replaced with assertion_stack.display
|
||||
unsigned num = m_kernel.get_num_asserted_formulas();
|
||||
expr * const * fms = m_kernel.get_asserted_formulas();
|
||||
out << "(kernel";
|
||||
for (unsigned i = 0; i < num; i++) {
|
||||
out << "\n " << mk_ismt2_pp(fms[i], m(), 2);
|
||||
}
|
||||
out << ")";
|
||||
}
|
||||
|
||||
void assert_expr(expr * e) {
|
||||
TRACE("smt_kernel", tout << "assert:\n" << mk_ismt2_pp(e, m()) << "\n";);
|
||||
|
@ -150,18 +162,6 @@ namespace smt {
|
|||
void get_guessed_literals(expr_ref_vector & result) {
|
||||
m_kernel.get_guessed_literals(result);
|
||||
}
|
||||
|
||||
void display(std::ostream & out) const {
|
||||
// m_kernel.display(out); <<< for external users it is just junk
|
||||
// TODO: it will be replaced with assertion_stack.display
|
||||
unsigned num = m_kernel.get_num_asserted_formulas();
|
||||
expr * const * fms = m_kernel.get_asserted_formulas();
|
||||
out << "(kernel";
|
||||
for (unsigned i = 0; i < num; i++) {
|
||||
out << "\n " << mk_ismt2_pp(fms[i], m(), 2);
|
||||
}
|
||||
out << ")";
|
||||
}
|
||||
|
||||
void collect_statistics(::statistics & st) const {
|
||||
m_kernel.collect_statistics(st);
|
||||
|
|
|
@ -23,6 +23,7 @@ Notes:
|
|||
#include"smt_params_helper.hpp"
|
||||
#include"mus.h"
|
||||
|
||||
|
||||
namespace smt {
|
||||
|
||||
class solver : public solver_na2as {
|
||||
|
@ -144,8 +145,7 @@ namespace smt {
|
|||
r.append(tmp.size(), tmp.c_ptr());
|
||||
}
|
||||
|
||||
virtual ast_manager& get_manager() { return m_context.m(); }
|
||||
|
||||
virtual ast_manager& get_manager() const { return m_context.m(); }
|
||||
|
||||
virtual void set_progress_callback(progress_callback * callback) {
|
||||
m_callback = callback;
|
||||
|
@ -159,15 +159,8 @@ namespace smt {
|
|||
virtual expr * get_assertion(unsigned idx) const {
|
||||
SASSERT(idx < get_num_assertions());
|
||||
return m_context.get_formulas()[idx];
|
||||
}
|
||||
|
||||
virtual std::ostream& display(std::ostream & out) const {
|
||||
m_context.display(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
solver * mk_smt_solver(ast_manager & m, params_ref const & p, symbol const & logic) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue