简体   繁体   中英

How to directly add constraints printed in python console within z3 automatically?

I have a set of constraints printed in my console which are as follows,

Region 1 
x3 > 0.75  
x2 <= 4.8500001430511475  
x3 <= 1.699999988079071  

Region 2  
x3 > 0.75  
x3 <= 1.75  
x2 <= 4.950000047683716  
x2 <= 4.450000047683716 

How do I automatically add these constraints within z3 and join these regions (defined by the two separate sets of inequalities) together?

Any help would be appreciated. Thanks!

Assuming x2 and x3 are reals, you can code this as:

from z3 import *

s = Solver()
x2, x3 = Reals('x2 x3')

s.add(x3 > 0.75)
s.add(x2 <= 4.8500001430511475)
s.add(x3 <= 1.699999988079071)

s.add(x3 > 0.75)
s.add(x3 <= 1.75)
s.add(x2 <= 4.950000047683716)
s.add(x2 <= 4.450000047683716)

print(s)

Which prints:

[x3 > 3/4,
 x2 <= 1940000057220459/400000000000000,
 x3 <= 1699999988079071/1000000000000000,
 x3 > 3/4,
 x3 <= 7/4,
 x2 <= 1237500011920929/250000000000000,
 x2 <= 1112500011920929/250000000000000]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM