gpt4 book ai didi

z3 - 无法使用 Z3 生成模型

转载 作者:行者123 更新时间:2023-12-04 13:00:54 25 4
gpt4 key购买 nike

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

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

谢谢。

最佳答案

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

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

我们有 o1 = 0s1 = 3, s2 = 3, s3 = 5,和 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

关于z3 - 无法使用 Z3 生成模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9050400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com