mirror of
https://github.com/Z3Prover/z3
synced 2025-08-26 13:06:05 +00:00
modulating data-type solver
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
cb2d8d2107
commit
bbfe02b25a
10 changed files with 44 additions and 26 deletions
|
@ -102,7 +102,7 @@ namespace smt {
|
|||
}
|
||||
}
|
||||
|
||||
void context::delete_unfixed(obj_map<expr, expr*>& var2val) {
|
||||
void 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();
|
||||
|
@ -137,14 +137,16 @@ namespace smt {
|
|||
to_delete.push_back(k);
|
||||
}
|
||||
}
|
||||
IF_VERBOSE(1, verbose_stream() << "(get-consequences deleting: " << to_delete.size() << " num-values: " << var2val.size() << ")\n";);
|
||||
for (unsigned i = 0; i < to_delete.size(); ++i) {
|
||||
var2val.remove(to_delete[i]);
|
||||
unfixed.push_back(to_delete[i]);
|
||||
}
|
||||
}
|
||||
|
||||
lbool context::get_consequences(expr_ref_vector const& assumptions,
|
||||
expr_ref_vector const& vars, expr_ref_vector& conseq) {
|
||||
expr_ref_vector const& vars,
|
||||
expr_ref_vector& conseq,
|
||||
expr_ref_vector& unfixed) {
|
||||
|
||||
m_antecedents.reset();
|
||||
lbool is_sat = check(assumptions.size(), assumptions.c_ptr());
|
||||
|
@ -168,6 +170,9 @@ namespace smt {
|
|||
trail.push_back(val);
|
||||
var2val.insert(vars[i], val);
|
||||
}
|
||||
else {
|
||||
unfixed.push_back(vars[i]);
|
||||
}
|
||||
}
|
||||
extract_fixed_consequences(0, var2val, _assumptions, conseq);
|
||||
unsigned num_units = assigned_literals().size();
|
||||
|
@ -179,7 +184,6 @@ namespace smt {
|
|||
unsigned num_iterations = 0;
|
||||
unsigned model_threshold = 2;
|
||||
while (!var2val.empty()) {
|
||||
++num_iterations;
|
||||
obj_map<expr,expr*>::iterator it = var2val.begin();
|
||||
expr* e = it->m_key;
|
||||
expr* val = it->m_value;
|
||||
|
@ -212,22 +216,29 @@ namespace smt {
|
|||
}
|
||||
if (get_assignment(lit) == l_true) {
|
||||
var2val.erase(e);
|
||||
unfixed.push_back(e);
|
||||
}
|
||||
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";);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
TRACE("context", tout << "Fixed: " << mk_pp(e, m) << "\n";);
|
||||
}
|
||||
++num_iterations;
|
||||
|
||||
TRACE("context", tout << "Unfixed variables: " << var2val.size() << "\n";);
|
||||
if (model_threshold <= num_iterations) {
|
||||
delete_unfixed(var2val);
|
||||
if (model_threshold <= num_iterations || num_iterations <= 2) {
|
||||
unsigned num_deleted = unfixed.size();
|
||||
delete_unfixed(var2val, unfixed);
|
||||
num_deleted = unfixed.size() - num_deleted;
|
||||
// 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";);
|
||||
|
||||
}
|
||||
// repeat until we either have a model with negated literal or
|
||||
// the literal is implied at base.
|
||||
|
@ -242,8 +253,7 @@ namespace smt {
|
|||
conseq.push_back(fml);
|
||||
var2val.erase(e);
|
||||
SASSERT(get_assignment(lit) == l_false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
end_search();
|
||||
return l_true;
|
||||
|
|
|
@ -3422,7 +3422,6 @@ namespace smt {
|
|||
}
|
||||
|
||||
lbool context::bounded_search() {
|
||||
SASSERT(!inconsistent());
|
||||
unsigned counter = 0;
|
||||
|
||||
TRACE("bounded_search", tout << "starting bounded search...\n";);
|
||||
|
|
|
@ -1347,7 +1347,7 @@ 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);
|
||||
void delete_unfixed(obj_map<expr, expr*>& var2val, expr_ref_vector& unfixed);
|
||||
|
||||
expr_ref antecedent2fml(uint_set const& ante);
|
||||
|
||||
|
@ -1391,7 +1391,7 @@ namespace smt {
|
|||
|
||||
lbool check(unsigned num_assumptions = 0, expr * const * assumptions = 0, bool reset_cancel = true);
|
||||
|
||||
lbool get_consequences(expr_ref_vector const& assumptions, expr_ref_vector const& vars, expr_ref_vector& conseq);
|
||||
lbool get_consequences(expr_ref_vector const& assumptions, expr_ref_vector const& vars, expr_ref_vector& conseq, expr_ref_vector& unfixed);
|
||||
|
||||
lbool setup_and_check(bool reset_cancel = true);
|
||||
|
||||
|
|
|
@ -99,8 +99,8 @@ namespace smt {
|
|||
return m_kernel.check(num_assumptions, assumptions);
|
||||
}
|
||||
|
||||
lbool get_consequences(expr_ref_vector const& assumptions, expr_ref_vector const& vars, expr_ref_vector& conseq) {
|
||||
return m_kernel.get_consequences(assumptions, vars, conseq);
|
||||
lbool get_consequences(expr_ref_vector const& assumptions, expr_ref_vector const& vars, expr_ref_vector& conseq, expr_ref_vector& unfixed) {
|
||||
return m_kernel.get_consequences(assumptions, vars, conseq, unfixed);
|
||||
}
|
||||
|
||||
void get_model(model_ref & m) const {
|
||||
|
@ -268,8 +268,8 @@ namespace smt {
|
|||
return r;
|
||||
}
|
||||
|
||||
lbool kernel::get_consequences(expr_ref_vector const& assumptions, expr_ref_vector const& vars, expr_ref_vector& conseq) {
|
||||
return m_imp->get_consequences(assumptions, vars, conseq);
|
||||
lbool kernel::get_consequences(expr_ref_vector const& assumptions, expr_ref_vector const& vars, expr_ref_vector& conseq, expr_ref_vector& unfixed) {
|
||||
return m_imp->get_consequences(assumptions, vars, conseq, unfixed);
|
||||
}
|
||||
|
||||
void kernel::get_model(model_ref & m) const {
|
||||
|
|
|
@ -129,7 +129,8 @@ namespace smt {
|
|||
/**
|
||||
\brief extract consequences among variables.
|
||||
*/
|
||||
lbool get_consequences(expr_ref_vector const& assumptions, expr_ref_vector const& vars, expr_ref_vector& conseq);
|
||||
lbool get_consequences(expr_ref_vector const& assumptions, expr_ref_vector const& vars,
|
||||
expr_ref_vector& conseq, expr_ref_vector& unfixed);
|
||||
|
||||
/**
|
||||
\brief Return the model associated with the last check command.
|
||||
|
|
|
@ -68,7 +68,8 @@ namespace smt {
|
|||
}
|
||||
|
||||
virtual lbool get_consequences_core(expr_ref_vector const& assumptions, expr_ref_vector const& vars, expr_ref_vector& conseq) {
|
||||
return m_context.get_consequences(assumptions, vars, conseq);
|
||||
expr_ref_vector unfixed(m_context.m());
|
||||
return m_context.get_consequences(assumptions, vars, conseq, unfixed);
|
||||
}
|
||||
|
||||
virtual void assert_expr(expr * t) {
|
||||
|
|
|
@ -97,6 +97,7 @@ namespace smt {
|
|||
virtual void pop_scope_eh(unsigned num_scopes);
|
||||
virtual final_check_status final_check_eh();
|
||||
virtual void reset_eh();
|
||||
virtual void restart_eh() { m_util.reset(); }
|
||||
virtual bool is_shared(theory_var v) const;
|
||||
public:
|
||||
theory_datatype(ast_manager & m, theory_datatype_params & p);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue