3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

user propagator over the API

This commit is contained in:
Nikolaj Bjorner 2020-08-18 21:52:52 -07:00
parent c50e869e5a
commit 4857d60c99
13 changed files with 141 additions and 63 deletions

View file

@ -892,14 +892,16 @@ extern "C" {
void* user_context,
Z3_push_eh push_eh,
Z3_pop_eh pop_eh,
Z3_fixed_eh fixed_eh) {
Z3_fixed_eh fixed_eh,
Z3_fresh_eh fresh_eh) {
Z3_TRY;
RESET_ERROR_CODE();
init_solver(c, s);
std::function<void(void*)> _push = push_eh;
std::function<void(void*,unsigned)> _pop = pop_eh;
std::function<void(void*,unsigned,expr*)> _fixed = [&](void* ctx, unsigned id, expr* e) { fixed_eh(ctx, id, of_ast(e)); };
to_solver_ref(s)->user_propagate_init(user_context, _fixed, _push, _pop);
std::function<void(void*,unsigned,expr*)> _fixed = (void(*)(void*,unsigned,expr*))fixed_eh;
std::function<void*(void*)> _fresh = fresh_eh;
to_solver_ref(s)->user_propagate_init(user_context, _fixed, _push, _pop, _fresh);
Z3_CATCH;
}

View file

@ -10505,17 +10505,44 @@ def TransitiveClosure(f):
return FuncDeclRef(Z3_mk_transitive_closure(f.ctx_ref(), f.ast), f.ctx)
"""
_user_propagate_bases = {}
def user_prop_push(ctx):
_user_propagate_bases[ctx].push();
def user_prop_pop(ctx, num_scopes):
_user_propagate_bases[ctx].pop(num_scopes)
def user_prop_fixed(ctx, id, value):
prop = _user_propagate_bases[ctx]
prop.fixed(id, _to_expr_ref(ctypes.c_void_p(value), prop.ctx))
def user_prop_fresh(ctx):
prop = _user_propagate_bases[ctx]
new_prop = prop.copy()
return ctypes.c_void_p(new_prop.id)
_user_prop_push = push_eh_type(user_prop_push)
_user_prop_pop = pop_eh_type(user_prop_pop)
_user_prop_fixed = fixed_eh_type(user_prop_fixed)
_user_prop_fresh = fresh_eh_type(user_prop_fresh)
class UserPropagateBase:
def __init__(self, s):
self.id = len(_user_propagate_bases) + 3
self.solver = s
self.ctx = s.ctx
Z3_user_propagate_init(self,
ctypes.CFUNCTYPE(None, ctypes.c_void_p)(_user_prop_push),
ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_uint())(_user_prop_pop),
ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_uint(), ctypes.c_void_p)(_user_prop_fixed))
_user_propagate_bases[self.id] = self
Z3_solver_propagate_init(s.ctx.ref(),
s.solver,
ctypes.c_void_p(self.id),
_user_prop_push,
_user_prop_pop,
_user_prop_fixed,
_user_prop_fresh)
def push(self):
raise Z3Exception("push has not been overwritten")
@ -10526,23 +10553,8 @@ class UserPropagateBase:
raise Z3Exception("fixed has not been overwritten")
def add(self, e):
return Z3_user_propagate_register(self.ctx.ref(), s.solver, e.ast)
return Z3_solver_propagate_register(self.ctx.ref(), self.solver.solver, e.ast)
def propagate(self, ids, e):
Z3_user_propagate_consequence(self.ctx.ref(), s.solver, ids, e.ast)
def _user_prop_push(ctx):
user_prop = ctx # need to access as python object.
user_prop.push()
def _user_prop_pop(ctx, num_scopes):
user_prop = ctx # need to access as python object
user_prop.pop(num_scopes)
def _user_prop_fixed(ctx, id, value):
user_prop = ctx # need to access as python object
user_prop.fixed(id, _to_expr_ref(value, user_prop.ctx))
"""
Z3_solver_propagate_consequence(self.ctx.ref(), self.solver.solver, ids, e.ast)

View file

@ -121,3 +121,6 @@ class FuncEntryObj(ctypes.c_void_p):
class RCFNumObj(ctypes.c_void_p):
def __init__(self, e): self._as_parameter_ = e
def from_param(obj): return obj

View file

@ -1412,6 +1412,15 @@ typedef enum
*/
typedef void Z3_error_handler(Z3_context c, Z3_error_code e);
/**
\brief callback functions for user propagator.
*/
typedef void Z3_push_eh(void* ctx);
typedef void Z3_pop_eh(void* ctx, unsigned num_scopes);
typedef void Z3_fixed_eh(void* ctx, unsigned id, Z3_ast value);
typedef void* Z3_fresh_eh(void* ctx);
/**
\brief A Goal is essentially a set of formulas.
Z3 provide APIs for building strategies/tactics for solving and transforming Goals.
@ -6515,13 +6524,10 @@ extern "C" {
Z3_ast Z3_API Z3_solver_get_implied_upper(Z3_context c, Z3_solver s, Z3_ast e);
/**
\brief register a user-properator with the solver.
*/
typedef void Z3_push_eh(void* ctx);
typedef void Z3_pop_eh(void* ctx, unsigned num_scopes);
typedef void Z3_fixed_eh(void* ctx, unsigned id, Z3_ast value);
*/
void Z3_API Z3_solver_propagate_init(
Z3_context c,
@ -6529,7 +6535,8 @@ extern "C" {
void* user_context,
Z3_push_eh push_eh,
Z3_pop_eh pop_eh,
Z3_fixed_eh fixed_eh);
Z3_fixed_eh fixed_eh,
Z3_fresh_eh fresh_eh);
/**
\brief register an expression to propagate on with the solver.