I have a code in z3
which aims to solve an optimization problem for a boolean formula
(set-option :PI_NON_NESTED_ARITH_WEIGHT 1000000000)
(decl
I have solved optimization problems in Z3 in the following, iterative way, essentially a loop that searches for a solution by using several invocations of Z3.
Find one solution (in your case, a solution to (sat c d e f)
Compute the value of that solution (if your solution is c0
, d0
, e0
, f0
, evaluate (goal c0 d0 e0 f0)
. Call that value v0
.
Find a solution to the new problem (and (sat c1 d1 e1 f1) (> (goal c1 d1 e1 f1) v0))
.
If point 3. returns UNSAT, v0
is your maximum. If not, use the new solution as v0
and go back to point 3.
You can sometimes speed up the process by guessing an upper bound first (i.e. values cu
, du
, eu
, fu
such that (and (sat c d e f) (<= (goal cu du eu fu))
is UNSAT) and then proceeding by dichotomy.
In my experience, the iterative way is much faster than using quantifiers for optimization problems.