无法使用Z3生成模型

时间:2012-01-29 02:22:49

标签: z3

我在一个名为“knapsack.smt2”的文件中有背包问题的示例代码,我相信它是smt2格式,我有最新版本的Z3:

(declare-const s1 Int)
(declare-const o1 Int)
(declare-const b1 Bool)

(declare-const s2 Int)
(declare-const o2 Int)
(declare-const b2 Bool)

(declare-const s3 Int)
(declare-const o3 Int)
(declare-const b3 Bool)


(declare-const sack-size Int)
(declare-const filled Int)

(assert (< o1 sack-size))
(assert (< o2 sack-size))
(assert (< o3 sack-size))

(assert (>= o1 0))
(assert (>= o2 0))
(assert (>= o3 0))

(assert (=> (not b1)(= o1 o2)))
(assert (=> (not b2)(= o2 o3)))

(assert (=> b1 (= (+ o1 s1) o2)))
(assert (=> b2 (= (+ o2 s2) o3)))
(assert (=> b3 (= (+ o3 s3) filled)))

(assert (=> (not b3) (= o3 filled)))
(assert (<= filled sack-size))

(assert ( = o1 0))


(assert ( = s1 3))
(assert ( = s2 4))
(assert ( = s3 5))
(assert ( = sack-size 20))

(assert ( = filled 13))

(check-sat)
(get-model)

但是,当我运行“z3 -m knapsack.smt2”时,我收到以下错误消息:

>> z3 -m knapsack.smt2
unsat
(error "line 46 column 10: model is not available")

其中第46行是最后一行“(get-model)”。

有谁能告诉我为什么这不起作用?

感谢。

1 个答案:

答案 0 :(得分:5)

Z3为可满足的实例生成模型。 你的配方不可满足。使用约束

(assert ( = o1 0))
(assert ( = s1 3))
(assert ( = s2 4))
(assert ( = s3 5))
(assert ( = filled 13))

我们有o1 = 0s1 = 3s2 = 3s3 = 5filled = 13, 使用约束

(assert (=> (not b1)(= o1 o2)))
(assert (=> b1 (= (+ o1 s1) o2)))

我们有o2 = 0o2 = 3

使用

(assert (=> (not b2)(= o2 o3)))
(assert (=> b2 (= (+ o2 s2) o3)))

我们有o3 = o2o3 = o2 + 3 使用

(assert (=> b3 (= (+ o3 s3) filled)))
(assert (=> (not b3) (= o3 filled)))

我们有o3 = 8o3 = 13

现在,我们可以看到冲突

o2 = 0 or o2 = 3
o3 = 8 or o3 = 13
o3 = o2 or o3 = o2 + 3 

如果我们尝试o2 = 0,我们会得到不可满足的公式

o3 = 8 or o3 = 13
o3 = 0 or o3 = 3 

如果我们尝试o2 = 3,我们会得到不可满足的公式

o3 = 8 or o3 = 13
o3 = 3 or o3 = 6