问题描述
感谢社区的帮助,我提出了以下代码:
from z3 import *
Color,(Red,Green,Blue) = EnumSort('Color',('Red','Green','Blue'))
Size,(Big,Medium,Small) = EnumSort('Size',('Big','Medium','Small'))
h1c,h2c,h3c = Consts('h1c h2c h3c',Color)
h1s,h2s,h3s = Consts('h1s h2s h3s',Size)
s = Solver()
myvars = [h1c,h3c,h1s,h3s]
s.add(Distinct([h1c,h3c]))
s.add(Distinct([h1s,h3s]))
s.add(h3s == Medium)
s.add(h3c == Red)
res = s.check()
n = 1
while (res == sat):
print("%d. " % n),m = s.model()
block = []
for var in myvars:
v = m.evaluate(var,model_completion=True)
print("%s = %-5s " % (var,v)),block.append(var != v)
s.add(Or(block))
n = n + 1
res = s.check()
这解决了一个问题,其中只有一所房子可以是中等大小和红色。其他组合则保持不变。
但是,我还想要一个条件,即众议院为什么要这样做,例如,绿色很小。最初没有指向特定的房子。这将排除所有未组合绿色或小型(绿色不能为中等,小型不能为红色等)的变体。但是也要保持区别,例如,只有一所房子可以是绿色和小型。因此,如果稍后我说房屋1是绿色或小型,那么对于房屋1来说,这是一个变体,其他房屋(变体)都不能是绿色或小型。
Example after 1st condition (Green is Small):
h1 = Green + Small
h2 = Green + Small
h3 = Green + Small
h1 = Red + Medium
h1 = Red + Big
h2 = Red + Medium
h2 = Red + Big
h3 = Red + Medium
h3 = Red + Big
h1 = Blue + Medium
h1 = Blue + Big
h2 = Blue + Medium
h2 = Blue + Big
h3 = Blue + Medium
h3 = Blue + Big ( I might missed something)
Example after 2nd condition (House 1 is Small/Green):
h1 = Green + Small
h2 = Red + Medium
h2 = Red + Big
h3 = Red + Medium
h3 = Red + Big
h2 = Blue + Medium
h2 = Blue + Big
h3 = Blue + Medium
h3 = Blue + Big ( I might missed something)
我一直在研究Functions
和children
变量,但是看不到如何比较堆栈中的任何变量。我认为代码需要完全重组?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)