3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-03-09 23:00:30 +00:00

Add Python Optimize.translate() and missing Go tactic/simplifier functions

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-01 02:14:16 +00:00
parent 2b8615f4fc
commit a15c659e81
3 changed files with 97 additions and 1 deletions

View file

@ -8463,8 +8463,11 @@ class Optimize(Z3PPObject):
self._on_models_id = None
Z3_optimize_inc_ref(self.ctx.ref(), self.optimize)
def __copy__(self):
return self.translate(self.ctx)
def __deepcopy__(self, memo={}):
return Optimize(self.optimize, self.ctx)
return self.translate(self.ctx)
def __del__(self):
if self.optimize is not None and self.ctx.ref() is not None and Z3_optimize_dec_ref is not None:
@ -8672,6 +8675,19 @@ class Optimize(Z3PPObject):
"""
return Statistics(Z3_optimize_get_statistics(self.ctx.ref(), self.optimize), self.ctx)
def translate(self, target):
"""Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
>>> c1 = Context()
>>> c2 = Context()
>>> o1 = Optimize(ctx=c1)
>>> o2 = o1.translate(c2)
"""
if z3_debug():
_z3_assert(isinstance(target, Context), "argument must be a Z3 context")
opt = Z3_optimize_translate(self.ctx.ref(), self.optimize, target.ref())
return Optimize(opt, target)
def set_on_model(self, on_model):
"""Register a callback that is invoked with every incremental improvement to
objective values. The callback takes a model as argument.