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)