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.
Z3 is an efficient SMT solver with specialized algorithms for solving background theories.
Z3 is a solver for symbolic logic, a foundation for many software engineering tools. SMT solvers rely on a tight integration of specialized engines of proof. Each engine owns a piece of the global puzzle and implements specialized algorithms.
Z3 is used in many applications such as: software/hardware verification and testing, constraint solving, analysis of hybrid systems, security, biology (in silico analysis), and geometrical problems. This tutorial demonstrates the main capabilities of Z3Py: the Z3 API in Python.
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 <strategy>)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With