You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimization Modulo Theories (OMT) extends Satisfiability Modulo Theories (SMT) by enabling solvers to find optimal solutions based on a defined objective function after verifying formula satisfiability. Adding OMT capabilities to the library would significantly enhance its ability to solve optimization problems directly.
I have implemented a prototype using Z3’s APIs. The solution is functional but hacky. I’m unsure if it’s the correct approach and it is inefficient because it copies all constraints to the optimizer. I’m also uncertain whether other SMT solvers support OMT, as my experience with SMT is limited.
data classMinimizingSolverZ3(valimpl:KZ3Solver) : MinimizingSolver<KZ3SolverConfiguration>,
KSolver<KZ3SolverConfiguration> by impl {
val z3Ctx:KZ3Context=
impl::class.java.getDeclaredField("z3Ctx").apply { isAccessible =true }.get(impl) asKZ3Contextval exprInternalizer = impl::class.java.getDeclaredMethod("getExprInternalizer")
.apply { isAccessible =true }.invoke(impl) asKZ3ExprInternalizerval exprCreate =Expr::class.java.getDeclaredMethod("create", Context::class.java, Long::class.java)
.apply { isAccessible =true } asMethodoverridefun <K:KArithSort> modelMinimizing(
expr:KExpr<K>,
maxIterations:Int,
timeout:Duration,
): KModel {
// Sadly, we need to create an Optimize object and copy all Solver constraints to itval opt:Optimize= z3Ctx.nativeContext.mkOptimize()
applyTimeout(opt, timeout)
for (c in impl.nativeSolver().assertions) opt.Assert(c)
// Add the expression to minimizeval exprId =with(exprInternalizer) { expr.internalizeExpr() }
val convertedExpr = exprCreate.invoke(null, z3Ctx.nativeContext, exprId) asExpr<*>
opt.MkMinimize(convertedExpr)
// Normal check, but using the optimizer
opt.Check()
// Extract the model and return itreturnKZ3Model(opt.model, expr.ctx, z3Ctx, exprInternalizer)
}
privatefunapplyTimeout(opt:Optimize, timeout:Duration) {
val z3Timeout =if (timeout ==Duration.INFINITE) UInt.MAX_VALUE.toInt()
else timeout.toInt(DurationUnit.MILLISECONDS)
opt.setParameters(z3Ctx.nativeContext.mkParams().apply { add("timeout", z3Timeout) })
}
}
The text was updated successfully, but these errors were encountered:
Optimization Modulo Theories (OMT) extends Satisfiability Modulo Theories (SMT) by enabling solvers to find optimal solutions based on a defined objective function after verifying formula satisfiability. Adding OMT capabilities to the library would significantly enhance its ability to solve optimization problems directly.
I have implemented a prototype using Z3’s APIs. The solution is functional but hacky. I’m unsure if it’s the correct approach and it is inefficient because it copies all constraints to the optimizer. I’m also uncertain whether other SMT solvers support OMT, as my experience with SMT is limited.
The text was updated successfully, but these errors were encountered: