我是 Z3 的新手,正在尝试制作一个求解器,将每个可满足的解决方案返回到布尔公式。从其他 SO 帖子中记下笔记,我已经编写了我希望能起作用的代码,但事实并非如此。问题似乎是,通过添加以前的解决方案,我删除了一些变量,但它们又在后面的解决方案中返回了?
目前我只是想解决a或b或c。
如果我解释得不好,请告诉我,我会尽力进一步解释。
预先感谢您的回复:)
我的代码:
from z3 import *
a, b, c = Bools('a b c')
s = Solver()
s.add(Or([a, b, c]))
while (s.check() == sat):
print(s.check())
print(s)
print(s.model())
print(s.model().decls())
print("\n")
s.add(Or([ f() != s.model()[f] for f in s.model().decls() if f.arity() == 0]))
Run Code Online (Sandbox Code Playgroud)
我的输出:
sat
[Or(a, b, c)]
[c = False, b = False, a = True]
[c, b, a]
sat
[Or(a, b, c), Or(c != False, b != False, a != True)]
[b = True, …Run Code Online (Sandbox Code Playgroud)