How to optimize a piece of code in Z3? (PI_NON_NESTED_ARITH_WEIGHT related)

前端 未结 2 1039
夕颜
夕颜 2020-12-20 05:31

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         


        
2条回答
  •  时光取名叫无心
    2020-12-20 06:25

    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.

    1. Find one solution (in your case, a solution to (sat c d e f)

    2. Compute the value of that solution (if your solution is c0, d0, e0, f0, evaluate (goal c0 d0 e0 f0). Call that value v0.

    3. Find a solution to the new problem (and (sat c1 d1 e1 f1) (> (goal c1 d1 e1 f1) v0)).

    4. 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.

提交回复
热议问题