How to get the model value in SAT problems using c++ api?

拥有回忆 提交于 2019-12-25 07:35:59

问题


I am using c++ api of z3 to solve a sat problem. When the problem is sat, I want to get the satisfiable assignments of all the variables. I find it easy to print the value of a variable as the following code shows:

context c;
solver s(c);
expr x=c.bool_const("x");
s.add(x);
if(s.check()==sat){
     model m=s.get_model();
      std::cout<<"x:"<<m.eval(x);
}

But the question is that I need to use it in a 'if' condition statement. for example:

if(m.eval(x)==true)
     std::cout<<"x is true";

Does anybody know how to do that? Thanks in advance.


回答1:


There is a function "eq" that can be used to check structural equality between two terms. THe overloaded == creates a new term, but eq(m.eval(e),c.bool_val(true)) checks for structural equality.



来源:https://stackoverflow.com/questions/17183246/how-to-get-the-model-value-in-sat-problems-using-c-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!