1

I am trying to minimize values using Z3. I set verbose to 0, and observed that Z3 finds an upper bound, and starts working from there to minimize the value. Example:

(optimize:check-sat)
(optimize:sat)
(optsmt upper bound: 3460)
(optsmt upper bound: 3455)
(optsmt upper bound: 3445)
(optsmt upper bound: 2430)
(optsmt upper bound: 2425)
(optsmt upper bound: 2325)
(optsmt upper bound: 2155)
(optsmt upper bound: 2150)
(optsmt upper bound: 2145)
(optsmt upper bound: 2135)
(optsmt upper bound: 2125)
(optsmt upper bound: 2055)
(optsmt upper bound: 2045)
(optsmt upper bound: 155)
(optsmt upper bound: 135)
(optsmt upper bound: 115)
(optsmt upper bound: 15)
(optsmt upper bound: 10)

I want to know if there is any way of setting the upper bound to a much lower level so as to get a faster output.

alias
  • 28,120
  • 2
  • 23
  • 40

1 Answers1

2

If you know there's a bound, why not just put that as an extra assertion:

(assert (< goal 200))

This is not guaranteed to speed things up, of course; and in general can miss the optimal point if you get it wrong. But it is a simple thing to try.

In general, the more information you provide to the solver, the better the chances that it'll converge faster.

Note that z3 doesn't really "search” during optimization. Instead it algorithmically determines and constraints the bounds. So there isn't really a "starting" value. For further references on how optimization works in z3, see this excellent recent answer by Patrick: What is the theory behind Z3 Optimize maximum and minimum functionality?

alias
  • 28,120
  • 2
  • 23
  • 40
  • I do not know the bound, but I do certainly know that the upper limit Z3 takes initially is way off the final value. It would be helpful to know if Z3 does this so as to find a satisfiable solution quickly, and then finds it easier to work on that solution to minimize the goal. – mayur sathe Feb 06 '19 at 07:09
  • See my extended answer and Patrick’s prior write-up for details. – alias Feb 06 '19 at 07:28
  • @mayursathe if you know a safe lower-bound for the objective function, then your problem might benefit from binary-/adaptive-search optimization techniques. – Patrick Trentin Feb 06 '19 at 07:58