【发布时间】:2019-09-29 03:16:33
【问题描述】:
我是使用 C++ API 的 Z3-Solver 的新手,我想解决一组不等式并找到结果。
我已阅读 the answer which written in Python 并尝试用 C++ 编写它,但它重复打印一个模型。
5 <= x + y + z <= 16
AND -4 <= x - y <= 6
AND 1 <= y - z <= 3
AND -1 <= x - z <= 7
AND x >= 0 AND y >= 0 AND z >= 0
不等式被添加到求解器中,并且有很多评估。
c 是上下文,s 是求解器。
vector<const char*> variables {"x", "y", "z"};
// ...
// till here, s was added into several constraints
while(s.check() == sat){
model m = s.get_model();
cout << m << "\n######\n";
expr tmp = c.bool_val(false);
for(int i = 0; i < variables.size(); ++ i){
tmp = tmp || (m[c.int_const(variables[i])] != c.int_const(variables[i]));
}
s.add(tmp);
}
结果:
(define-fun z () Int
0)
(define-fun y () Int
2)
(define-fun x () Int
3)
######
(define-fun z () Int
0)
(define-fun y () Int
2)
(define-fun x () Int
3)
######
(define-fun z () Int
0)
...
它只打印一个模型。我不确定哪里错了。
如何获得所有模型或获得一个或多个凸集(例如 {l1
顺便说一句,有很多关于python的教程(例如this),我可以在那里学习c++中的z3,因为example和api doc.不容易上手。
【问题讨论】: