简体   繁体   中英

How to get the upper bounds and lower bounds in Z3 java API?

When using the z3 optimizing solver, the bounds of models are required especially the constraints are complex. I can find the function upper and lower in the Z3 python api but not be available for the Java api. Could you take some examples showing how to get the model bounds in the Z3 java api?

You should use the Handle object to access the bounds. The relevant functions are here:

https://github.com/Z3Prover/z3/blob/master/src/api/java/Optimize.java#L92-L103

Z3 comes with a java optimize example which does access the Handle inside the optimize class. See:

https://github.com/Z3Prover/z3/blob/master/examples/java/JavaExample.java#L2216-L2237

Simply follow that example and further call getLower and getUpper , something like:

Optimize.Handle mx = opt.MkMaximize(xExp);

mx.getLower()
mx.getUpper()

Note that min/max values in optimization is not always reliable, nor they mean anything larger than min and smaller than max will be satisfy your constraints. They are merely what the solver kept track of as it was constraining the variable, and might not be what you have in mind. It's best to show what you tried, and what you got when asking stack-overflow questions.

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