[英]Unable to extract value for Z3 EnumSort in z3py
I am currently trying to encode a problem into Z3, and I wish to model a "tristate" Boolean (ie, a Boolean with true
, false
and unknown
).我目前正在尝试将问题编码到 Z3 中,并且我希望对“三态”布尔值建模(即,具有
true
、 false
和unknown
的布尔值)。
Here is how I have modelled it:这是我建模的方式:
#!/usr/bin/env python
import z3
from collections import OrderedDict
TristateValues = ["True", "False", "Unknown"]
Tristate, consts = z3.EnumSort("Tristate", TristateValues)
TristateValues = OrderedDict(zip(TristateValues, consts))
s = z3.Solver()
x = z3.Const("x", Tristate)
s.add(x != TristateValues["Unknown"])
value = s.check()
if value == z3.sat:
m = s.model()
print str(m.eval(x))
else:
print str(value)
# EOF
And on this small example, things work well, and I get values such as True
or False
.在这个小例子中,一切运行良好,我得到了诸如
True
或False
值。
However, on larger examples, I get results such as:但是,在较大的示例中,我得到的结果如下:
Tristate!val!0
Tristate!val!1
Tristate!val!2
Clearly, it seems that there would be a mapping between these "Tristate" strings and the real values, so I wrote something like this:显然,这些“三态”字符串和真实值之间似乎存在映射,所以我写了这样的东西:
ModelToTristate = {}
as_list = list(TristateValues.keys())
for idx in range(0, len(as_list)):
ModelToTristate["Tristate!val!{:d}".format(idx)] = as_list[idx]
to try and map back between the values (this is why the use of OrderedDict
is important to preserve the ordering).尝试在值之间映射回(这就是为什么使用
OrderedDict
对保持排序很重要的原因)。
And, initially, it seemed that this worked.而且,最初,这似乎奏效了。 However, I then hit some more, stranger errors:
然而,我又遇到了一些更奇怪的错误:
ModelToTristate
where it seems I was indeed getting the correct value for calling str
on the result of model.eval()
(ie, Z3 would give True
, False
, etc. rather than than Tristate!val!*
)ModelToTristate
中找到查找错误,在那里我似乎确实获得了对model.eval()
结果调用str
的正确值(即,Z3 会给出True
、 False
等,而不是Tristate!val!*
)x == Tristate["False"]
, checking the look-up would result in model.eval(x) == Tristate!val!1
, where Tristate!val!1
maps to True
)x == Tristate["False"]
,检查查找也会导致model.eval(x) == Tristate!val!1
,其中Tristate!val!1
映射到True
) For this last issue, I think there is a lookup problem, rather than Z3 giving incorrect values.对于最后一个问题,我认为存在查找问题,而不是 Z3 给出的值不正确。
So, my question is: what is causing Z3 to use these Tristate!val!*
strings, and can I "force" Z3 to use the correct values (ie, True
, False
, Unknown
)?所以,我的问题是:是什么导致 Z3 使用这些
Tristate!val!*
字符串,我是否可以“强制”Z3 使用正确的值(即True
、 False
、 Unknown
)?
I am using Z3 4.5.0.我正在使用 Z3 4.5.0。
Update after checking it, it seems that this problem appears when I use SolverFor("QF_ABV")
.检查后更新,当我使用
SolverFor("QF_ABV")
时,似乎出现此问题。
The QF_ABV logic does not know about algebraic datatypes. QF_ABV 逻辑不知道代数数据类型。 It will treat them as uninterpreted.
它会将它们视为未解释的。 The model you get back then is as if the enumeration sort is free.
你得到的模型就像枚举排序是免费的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.