Z3软约束

发布于 2025-02-02 17:12:48 字数 669 浏览 2 评论 0原文

我对在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尘世孤行 2025-02-09 17:12:48

它出现parse_smt2_string do 不是保留软主张。

如果添加print(o.sexpr())在调用检查之前,它会打印:

(declare-fun v () Real)
(declare-fun v1 () Bool)
(assert (= v1 (<= (to_real 0) v)))
(assert (> (to_real 10) v))

如您所见,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 call check, it prints:

(declare-fun v () Real)
(declare-fun v1 () Bool)
(assert (= v1 (<= (to_real 0) v)))
(assert (> (to_real 10) v))

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文