【问题标题】:Z3Py: constraint of not equal tuplesZ3Py:不相等元组的约束
【发布时间】:2016-09-25 23:26:55
【问题描述】:

我有一堆布尔值:

a=Bool('a')
...
z=Bool('z')

如何将其中一些布尔值打包成元组,然后添加关于它们不相等的约束?

我试过了:

tuple1=(a,b,c,d)
tuple2=(e,f,g,h)
# so far so good
s=Solver()
s.add(tuple1 != tuple2)

但这不起作用。

【问题讨论】:

    标签: z3 z3py


    【解决方案1】:

    python 元组不会反映到 Z3 元组。 您可以通过以下方式为 Z3 创建元组类型L

    from z3 import *
    a,b,c,d,e,f,g,h = Ints('a b c d e f g h')
    
    tuple = Datatype('tuple')
    tuple.declare('tuple',('1', IntSort()), ('2', IntSort()), ('3', IntSort()), ('4', IntSort()))
    tuple = tuple.create()
    tuple1=tuple.tuple(a,b,c,d)
    tuple2=tuple.tuple(e,f,g,h)
    # so far so good
    s=Solver()
    s.add(tuple1 != tuple2)
    print s.check()
    print s.model()
    

    在这种情况下,您会得到 Z3 可以理解的元组不等式。 Z3 不理解 python 元组之间的 != 或 == 运算符。 也许可以将 python 支持扩展到此类数据类型 但发行版不支持此类扩展。

    【讨论】:

    • 只有一个问题:我可以用数组替换元组吗,数组的大小将在运行时设置?然后填充它们并进行比较?
    猜你喜欢
    • 1970-01-01
    • 2019-02-10
    • 2017-08-22
    • 1970-01-01
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多