【问题标题】:Is it possible to query z3's Python API on whether a timeout occured?是否可以查询z3的Python API是否发生超时?
【发布时间】:2018-10-31 13:06:36
【问题描述】:

我想限制 z3 可以在某些问题上花费的时间,这可以通过设置超时来实现:

from z3 import *
solver = Solver()
solver.set(timeout=60000)
# add constraints to solver
result = solver.check()

但是,我想检查是否确实发生了超时。 result 在这种情况下是 unknown,但这也可能会发生,因为这个问题是不可判定的(我使用的理论通常是不可判定的)。

那么,有没有办法查明是否发生了超时?

【问题讨论】:

    标签: python python-3.x z3 z3py


    【解决方案1】:

    当然,只需使用reason_unknown 调用:

    from z3 import *
    solver = Solver()
    solver.set(timeout=1)
    x, y = Ints('x y')
    solver.add(x**y == x)
    result = solver.check()
    print result
    print solver.reason_unknown()
    

    打印出来:

    unknown
    timeout
    

    【讨论】:

      猜你喜欢
      • 2015-12-05
      • 1970-01-01
      • 2016-02-26
      • 2019-03-02
      • 2014-01-07
      • 1970-01-01
      • 2011-05-04
      • 2019-08-11
      • 1970-01-01
      相关资源
      最近更新 更多