Z3软约束
我对在Z3中使用软约束的使用感到困惑。运行此程序时,我将获得以下输出。
from z3 import *
o = Solver()
expr = f"""
(declare-const v Real)
(declare-const v1 Bool)
(assert-soft v1)
(assert (= v1 (<= 0 v)))
(assert (> 10 v))
"""
p = parse_smt2_string(expr)
o.add(p)
print(o.check())
print(o.model())
输出: [v1 = false,v = -1]
有人会知道为什么在允许它的V值时,软约束不满足?
同样,此程序也不会返回预期的输出:
from z3 import *
o = Optimize()
expr = f"""
(declare-const v1 Real)
(declare-const e Bool)
(assert (= e (<= 6 v1)))
(assert-soft e)
"""
p = parse_smt2_string(expr)
o.add(p)
print(o.check())
print(o.model())
它返回[V1 = 0,e = false]。为什么不能实现软限制?
I am confused by the use of soft constraints in z3. When running this program, I obtain the following output.
from z3 import *
o = Solver()
expr = f"""
(declare-const v Real)
(declare-const v1 Bool)
(assert-soft v1)
(assert (= v1 (<= 0 v)))
(assert (> 10 v))
"""
p = parse_smt2_string(expr)
o.add(p)
print(o.check())
print(o.model())
output:
[v1 = False, v = -1]
Would someone please know why is the soft constraint not satisfied while there exist values for v which allow it?
Similarly, this program does not return the expected output:
from z3 import *
o = Optimize()
expr = f"""
(declare-const v1 Real)
(declare-const e Bool)
(assert (= e (<= 6 v1)))
(assert-soft e)
"""
p = parse_smt2_string(expr)
o.add(p)
print(o.check())
print(o.model())
It returns [v1 = 0, e = False]. Why can't the soft constraints be fulfilled?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它出现
parse_smt2_string
do 不是保留软主张。如果添加
print(o.sexpr())
在调用检查
之前,它会打印:如您所见,Soft-Constraint已消失。因此,Z3看到的不是您认为的。这解释了意外的输出。
我知道
parse_smt2_string
并不是完全忠实的,因为它不处理任意的smtlib输入。我不确定是否支持这种特殊情况。将其作为问题归档, https://github.com/z3prover/z3prover/z3/sissues 开发人员可能会看看。It appears
parse_smt2_string
does not preserve soft assertions.If you add
print(o.sexpr())
right before you callcheck
, it prints:As you see, the soft-constraint has disappeared. So, what z3 sees is not what you thought it did. This explains the unexpected output.
I know that
parse_smt2_string
isn't exactly faithful, in the sense that it doesn't handle arbitrary SMTLib inputs. Whether this particular case is supported, I'm not sure. File it as an issue at https://github.com/Z3Prover/z3/issues and the developers might take a look.