【问题标题】:retrieve the matched model in Z3py?在 Z3py 中检索匹配的模型?
【发布时间】:2013-03-17 21:51:46
【问题描述】:

在以下工作示例中,如何检索匹配的模型?

     S,   (cl_3,cl_39,cl_11, me_32,m_59,m_81) = 
     EnumSort('S', ['cl_3','cl_39','cl_11','me_32','me_59','me_81'])

       h1, h2 = Consts('h1 h2', S)
       def fun(h1 , h2):

        conds = [
        (cl_3, me_32),
        (cl_39, me_59),
        (cl_11, me_81),
         # ...
             ]

    and_conds = (And(h1==a, h2==b) for a,b in conds)
     return Or(*and_conds)

例如: 作为以下求解器

  s = Solver()
  x1 = Const('x1', S)
  x2 = Const('x2', S)
  s.add(fun(x1,x2)) 

  print s.check()
  print s.model()

【问题讨论】:

    标签: z3 smt constraint-programming


    【解决方案1】:

    我假设您想要 Z3 生成的模型中的 x1x2 的值。如果是这种情况,您可以使用以下方法检索它们:

       m = s.model()
       print m[x1]
       print m[x2]
    

    这里是完整的例子(也可以在线获得here)。顺便说一句,请注意我们不需要h1, h2 = Consts('h1 h2', S)

    S, (cl_3, cl_39, cl_11, me_32, me_59, me_81) = 
          EnumSort('S', ['cl_3','cl_39','cl_11','me_32','me_59','me_81'])
    def fun(h1 , h2):
       conds = [
         (cl_3, me_32),
         (cl_39, me_59),
         (cl_11, me_81),
       ]
       and_conds = (And(h1==a, h2==b) for a,b in conds)
       return Or(*and_conds)
    
    s = Solver()
    x1 = Const('x1', S)
    x2 = Const('x2', S)
    s.add(fun(x1,x2)) 
    print s.check()
    m = s.model()
    print m
    print m[x1]
    print m[x2]
    

    【讨论】:

      猜你喜欢
      • 2013-02-25
      • 1970-01-01
      • 1970-01-01
      • 2013-12-18
      • 2018-09-07
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      相关资源
      最近更新 更多