简体   繁体   English

如何获取Z3 java API中的上限和下限?

[英]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.使用 z3 优化求解器时,需要模型的边界,尤其是约束很复杂。 I can find the function upper and lower in the Z3 python api but not be available for the Java api. 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?您能否举一些例子来说明如何在 Z3 java api 中获得 model 边界?

You should use the Handle object to access the bounds.您应该使用Handle object 来访问边界。 The relevant functions are here:相关功能在这里:

https://github.com/Z3Prover/z3/blob/master/src/api/java/Optimize.java#L92-L103 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. Z3 带有一个 java 优化示例,它访问优化 class 内部的Handle See:看:

https://github.com/Z3Prover/z3/blob/master/examples/java/JavaExample.java#L2216-L2237 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:只需按照该示例并进一步调用getLowergetUpper ,例如:

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.最好展示你尝试了什么,以及在询问堆栈溢出问题时得到了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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