1

I have a set of linear constraints defined on a set of real parameters. The aim is to find a solution of parameters that satisfies maximum number of these constraints. I use the Optimizer in z3 but it is really slow. The number of constraints is 100 and the number of parameters is 9, which is not a large number. I use the following code:

from z3 import *
s = Optimize()
W = RealVector('w', 9)
s.add(And([And(w >= -100, w <= 100) for w in W]))

**Add soft constraints from a text file

out = s.check()

Following is a sample of the soft constraints, each with weight 1, that are added to the problem:

w__0 + 7*w__1 + 181*w__2 + 84*w__3 + 21*w__4 + 192*w__5 + 36*w__6 + 59*w__7 + 51*w__8 > 0

w__0 + 2*w__1 + 127*w__2 + 58*w__3 + 24*w__4 + 275*w__5 + 28*w__6 + 160*w__7 + 25*w__8 < 0

w__0 + 11*w__1 + 138*w__2 + 76*w__3 + 0*w__4 + 0*w__5 + 33*w__6 + 42*w__7 + 35*w__8 < 0

w__0 + 2*w__1 + 81*w__2 + 60*w__3 + 22*w__4 + 0*w__5 + 28*w__6 + 29*w__7 + 25*w__8 < 0

w__0 + 0*w__1 + 84*w__2 + 82*w__3 + 31*w__4 + 125*w__5 + 38*w__6 + 23*w__7 + 23*w__8 < 0

w__0 + 9*w__1 + 140*w__2 + 94*w__3 + 0*w__4 + 0*w__5 + 33*w__6 + 73*w__7 + 45*w__8 > 0

w__0 + 8*w__1 + 197*w__2 + 74*w__3 + 0*w__4 + 0*w__5 + 26*w__6 + 119*w__7 + 39*w__8 > 0

w__0 + 8*w__1 + 120*w__2 + 0*w__3 + 0*w__4 + 0*w__5 + 30*w__6 + 18*w__7 + 38*w__8 > 0

w__0 + 7*w__1 + 161*w__2 + 86*w__3 + 0*w__4 + 0*w__5 + 30*w__6 + 17*w__7 + 47*w__8 > 0

w__0 + 4*w__1 + 120*w__2 + 68*w__3 + 0*w__4 + 0*w__5 + 30*w__6 + 71*w__7 + 34*w__8 < 0

w__0 + 7*w__1 + 187*w__2 + 50*w__3 + 33*w__4 + 392*w__5 + 34*w__6 + 83*w__7 + 34*w__8 > 0

w__0 + 2*w__1 + 87*w__2 + 0*w__3 + 23*w__4 + 0*w__5 + 29*w__6 + 77*w__7 + 25*w__8 < 0

w__0 + 1*w__1 + 97*w__2 + 68*w__3 + 21*w__4 + 0*w__5 + 27*w__6 + 110*w__7 + 22*w__8 < 0

w__0 + 4*w__1 + 123*w__2 + 80*w__3 + 15*w__4 + 176*w__5 + 32*w__6 + 44*w__7 + 34*w__8 < 0

w__0 + 6*w__1 + 195*w__2 + 70*w__3 + 0*w__4 + 0*w__5 + 31*w__6 + 33*w__7 + 31*w__8 > 0

w__0 + 0*w__1 + 101*w__2 + 64*w__3 + 17*w__4 + 0*w__5 + 21*w__6 + 25*w__7 + 21*w__8 < 0

w__0 + 12*w__1 + 92*w__2 + 62*w__3 + 7*w__4 + 258*w__5 + 28*w__6 + 93*w__7 + 44*w__8 > 0

w__0 + 1*w__1 + 88*w__2 + 62*w__3 + 24*w__4 + 44*w__5 + 30*w__6 + 42*w__7 + 23*w__8 < 0

I know that the performance of the solution will depend on the nature of the problem but with 100 such constraints the computations go on forever. Is there any additional option that I can use to make this faster?

I also implemented the fu-malik algorithm myself by extracting the core, even with that it's really slow.

Patrick Trentin
  • 7,126
  • 3
  • 23
  • 40
  • Yes, the linear constraints mentioned are enforced as soft constraints. – Kshitij Goyal Apr 09 '20 at 18:19
  • All of the soft constraint have equal weights. – Kshitij Goyal Apr 10 '20 at 00:09
  • the default weight (1), if that wasn't clear. – Kshitij Goyal Apr 10 '20 at 17:46
  • Do you need any more information? I can also provide you with the full set of `00 constraints. – Kshitij Goyal Apr 13 '20 at 18:24
  • I shared my limited knowledge [here](https://stackoverflow.com/questions/57773821/combination-of-maxsmt-and-user-defined-cost-function-in-z3-solver) and [here](https://stackoverflow.com/questions/59288428/incremental-learning-using-maxsmt). I am not qualified enough on z3 to provide an answer to this question. You should try get the attention of [Nikolaj Bjorner](https://stackoverflow.com/users/1096362/nikolaj-bjorner) or [Christoph Wintersteiger](https://stackoverflow.com/users/869966/christoph-wintersteiger), both are esteemed domain experts and know its options much better than me. – Patrick Trentin Apr 13 '20 at 20:14
  • Having said this, one or more complete and fully reproducible SMTLIB formulas would surely help them try it out. As an OMT developer, I would also be interested in a benchmark-set of SMT-LIB problems like this. – Patrick Trentin Apr 13 '20 at 20:19

0 Answers0