3

我在一个名为“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)”。

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

谢谢。

4

1 回答 1

5

Z3 为可满足的实例生成模型。你的公式不能满足。使用约束

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

我们有那个o1 = 0and s1 = 3, s2 = 3, s3 = 5, and filled = 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 
于 2012-01-29T02:27:32.727 回答