简体   繁体   English

Z3 最小化-无穷大答案

[英]Z3 minimization -infinity answer

I'm currently using the c++ API of z3 and have a problem minimizing the sum of integer variables.我目前正在使用 z3 的 c++ API 并且在最小化 integer 变量的总和时遇到问题。

There are some integer variables ( rv_i ) and each of them becomes some positive number or 0 depending on whether the boolean variable r_i is true or false.有一些 integer 变量( rv_i ),它们中的每一个都变为某个正数或 0,具体取决于 boolean 变量r_i是真还是假。 I want to minimize the sum of rv_i s and asserted the expressions like the below code.我想最小化rv_i的总和并断言如下代码所示的表达式。 I think the minimized value of the sum of rv_i s should be 0 if all r_i s are false or should be some positive value if some of r_i s are true, but z3 gives the minus infinity ( (* (- 1) oo) ) when printing the minimized result.我认为如果所有r_i都为假,则rv_i之和的最小值应该为 0,或者如果某些r_i为真,则应该是某个正值,但 z3 给出负无穷大( (* (- 1) oo) )打印最小化结果时。 why z3 gives the minus infinity to the minimized value of the below code?为什么 z3 将负无穷大赋予以下代码的最小值? (check result is sat) (检查结果是sat)

(declare-fun rv_10 () Int)
(declare-fun r_10 () Bool)
(declare-fun rv_9 () Int)
(declare-fun r_9 () Bool)
(declare-fun rv_8 () Int)
(declare-fun r_8 () Bool)
(declare-fun rv_7 () Int)
(declare-fun r_7 () Bool)
(declare-fun rv_6 () Int)
(declare-fun r_6 () Bool)
(declare-fun rv_5 () Int)
(declare-fun r_5 () Bool)
(declare-fun rv_4 () Int)
(declare-fun r_4 () Bool)
(declare-fun rv_3 () Int)
(declare-fun r_3 () Bool)
(declare-fun rv_2 () Int)
(declare-fun r_2 () Bool)
(declare-fun rv_1 () Int)
(declare-fun r_1 () Bool)
(declare-fun rv_0 () Int)
(declare-fun r_0 () Bool)
(declare-fun p_1 () Bool)
(declare-fun p_2 () Bool)
(declare-fun p_3 () Bool)
...
(assert (and (=> r_0 (= rv_0 1))
     (=> r_1 (= rv_1 3))
     (=> r_2 (= rv_2 5))
     (=> r_3 (= rv_3 2))
     (=> r_4 (= rv_4 2))
     (=> r_5 (= rv_5 3))
     (=> r_6 (= rv_6 5))
     (=> r_7 (= rv_7 5))
     (=> r_8 (= rv_8 5))
     (=> r_9 (= rv_9 5))
     (=> r_10 (= rv_10 5))
(assert (and (=> (not r_0) (= rv_0 0))
     (=> (not r_1) (= rv_1 0))
     (=> (not r_2) (= rv_2 0))
     (=> (not r_3) (= rv_3 0))
     (=> (not r_4) (= rv_4 0))
     (=> (not r_5) (= rv_5 0))
     (=> (not r_6) (= rv_6 0))
     (=> (not r_7) (= rv_7 0))
     (=> (not r_8) (= rv_8 0))
     (=> (not r_9) (= rv_9 0))
     (=> (not r_10) (= rv_10 0))
(assert (>= rv_0 0))
(assert (>= rv_1 0))
(assert (>= rv_2 0))
(assert (>= rv_3 0))
(assert (>= rv_4 0))
(assert (>= rv_5 0))
(assert (>= rv_6 0))
(assert (>= rv_7 0))
(assert (>= rv_8 0))
(assert (>= rv_9 0))
(assert (>= rv_10 0))
(assert (=> p_1 (and (or (not r_1) (not r_2)))))
(assert (=> p_2 (and (or r_0) (or r_1 r_2) (or r_3))))
(assert (=> p_3 (or r_6 r_7 r_8 r_9 r_10)))
...
(minimize (+ rv_0
   rv_1
   rv_2
   rv_3
   rv_4
   rv_5
   rv_6
   rv_7
   rv_8
   rv_9
   rv_10))
(check-sat)

I cannot replicate this.我无法复制这个。 Your input has a few ... 's in them, if you remove those and insert parenthesis to close the corresponding expressions, and add the following line at the very end (after check-sat ):您的输入中有一些... ,如果您删除这些并插入括号以关闭相应的表达式,并在最后添加以下行(在check-sat之后):

(get-objectives)

then z3 says:然后 z3 说:

sat
(objectives
 ((+ rv_0 rv_1 rv_2 rv_3 rv_4 rv_5 rv_6 rv_7 rv_8 rv_9 rv_10) 0)
)

So, either the parts you've ... 'd have code that change this behavior (unlikely), or since you're programming this using the C++ API, you're not quite using the C++ API correctly (more likely). So, either the parts you've ... 'd have code that change this behavior (unlikely), or since you're programming this using the C++ API, you're not quite using the C++ API correctly (more likely).

But without seeing the actual full input that causes the issue, it's impossible to tell what's going on wrong.但是如果没有看到导致问题的实际完整输入,就不可能知道发生了什么问题。 I doubt z3 is at fault here;我怀疑 z3 在这里有错; you should really post an MWE (minimal-workable-example);你真的应该发布一个 MWE(最小可行示例); see here: https://stackoverflow.com/help/minimal-reproducible-example见这里: https://stackoverflow.com/help/minimal-reproducible-example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM