如何获得所有模型或所有凸评估
How to get all models or all convex evaluation?
我是Z3-Solver的新手,在C 中使用API,并希望解决一组不等式并找到结果。
我已经阅读了用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&lt; = x&lt; = u1 and l2&lt; = x -y&lt; = u2 and ...}(,但不是遍历所有评估。
顺便说一句,关于Python的教程很多(例如(,我可以在C 中学习Z3作为示例和API DOC。启动并不容易。
您的"模型反驳"循环不是很正确。由于您没有发布整个代码,因此很难确定是否还有其他问题,但这就是我的操作方式:
#include<vector>
#include"z3++.h"
using namespace std;
using namespace z3;
int main(void) {
context c;
expr_vector variables(c);
variables.push_back(c.int_const("x"));
variables.push_back(c.int_const("y"));
variables.push_back(c.int_const("z"));
expr x = variables[0];
expr y = variables[1];
expr z = variables[2];
solver s(c);
s.add(5 <= x+y+z);
s.add(x+y+z <= 16);
s.add(-4 <= x-y);
s.add(x-y <= 6);
s.add(-1 <= x-z);
s.add(x-z <= 7);
s.add(x >= 0);
s.add(y >= 0);
s.add(z >= 0);
while (s.check() == sat) {
model m = s.get_model();
cout << m << endl;
cout << "#######" << endl;
expr tmp = c.bool_val(false);
for(int i = 0; i < variables.size(); ++i) {
tmp = tmp || (variables[i] != m.eval(variables[i]));
}
s.add(tmp);
}
return 0;
}
此代码运行并枚举所有"混凝土"模型。从您的问题来看,我也想知道您是否可以获得"符号"模型:SMT求解器是不可能的。SMT求解器仅产生混凝土(即所有地面术语(模型,因此,如果您需要从它们中概括,则必须在Z3边界之外执行此操作。
相关文章:
- std::condition_variable::wait()如何评估给定的谓词
- QTableView:endMoveRows在模型中重置水平页眉大小
- 将IBM Rhapsody模型集成到VS 2019中
- 旋转模型矩阵时的形状失真
- c++11评估顺序(未定义的行为)
- 成员函数调用和C++对象模型
- 连接 dockerized 模型和 dockerized 数据库时出现"无法 SQLConnect"错误
- 打印 ONNXRUNTIME::图形没有模型
- C++内存模型和位字段的最大序列
- 如何使用"equal to"以外的评估编写开关语句
- 使用SIR模型的疾病爆发模拟
- 嵌套 if 中没有返回评估
- 懒惰的参数评估try_emplace?
- Qt - QVector 和模型视图 - 从列表视图获取自定义类的最佳方法是什么?
- 如何在 ECS 模型中组织实体?
- 在官方张量流 resnet50 模型上运行 tflite 精度工具
- 在实践中,在运行时为零的乘法中是否有任何"lazy"评估
- Libtorch:如何加载ONNX模型?
- 使用 assimp 加载模型 - 不需要提升?
- 如何获得所有模型或所有凸评估