Z3 Polarity using Z3 as SAT Solver

匿名 (未验证) 提交于 2019-12-03 01:05:01

问题:

I am trying to solve a SAT problem with 12000+ boolean variables using Z3. I expect that most of the variables will evaluate to false in the solution. Is there a way to guide or hint Z3 as SAT solver to try "polarity false" first? I've tried it with cryptominisat 2 and got good results.

回答1:

Z3 is a collection of solvers and preprocessors. We can provide hints for some of the solvers. When the command (check-sat) is used, Z3 will select the solver automatically for us. We should (check-sat-using ) if we want to select the solver ourselves. For example, the following command will instruct Z3 to use a Boolean SAT solver.

(check-sat-using sat) 

We can force it to always try "polarity false" first by using:

(check-sat-using (with sat :phase always-false)) 

We can also control the preprocessing steps. If we want to put the formula in CNF before invoking sat, we should use:

(check-sat-using (then tseitin-cnf (with sat :phase always-false))) 

EDIT: if you are using the DIMACS input format and Z3 v4.3.1, then you can't set parameters for all available solvers using the command line. The next release will address this limitation. In the meantime, you can download the work-in-progress branch using:

git clone https://git01.codeplex.com/z3 -b unstable  

and compile Z3. Then, to force polarity false, we use the command line option

sat.phase=always_false 

The command z3 -pm:sat will display all available options for this module.

END EDIT

Here is a complete example in SMT 2.0 (also available online):

(declare-const p Bool) (declare-const q Bool) (declare-const r Bool) (declare-const s Bool)  (assert (or (not p) (not q) (not r))) (assert (or r s)) (assert (or r (not s))) (assert (or r (and p q)))  (echo "With always false") (check-sat-using (then tseitin-cnf (with sat :phase always-false))) (get-model) (echo "With always true") (check-sat-using (then tseitin-cnf (with sat :phase always-true))) (get-model) 


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