在Z3中,我可以调用(get-objectives)
来转储结果权重。
(例如here)
它打印的内容如下:
(objectives
(aaa 1)
(bbb 0)
)
在z3py中,Optimize.objectives()
打印目标计算的转储,而不是计算出的权重,如下所示:
[If(a == 3, 0, 1), If(b == 3, 0, 1)]
我有办法获得计算出的重量吗?或标准z3中特定目标的权重?
这是我的示例代码:
from z3 import *
a, b = Ints('a b')
s = Optimize()
s.add(3 <= a, a <= 10)
s.add(3 <= b, b <= 10)
s.add(a >= 2*b)
s.add_soft(a == 3, weight=1, id="aaa")
s.add_soft(b == 3, weight=1, id="bbb")
print(s.check())
print(s.model())
print(s.objectives())
答案 0 :(得分:2)
您可以使用该模型来评估目标:
m = s.model()
print [m.evaluate(o) for o in s.objectives()]
这会产生:
sat
[1, 0]