Minisat Tutorial
Minisat Tutorial
A file can start with some comment lines. These are just text lines that start
with a lower case c. As an example:
c This is a comment line
c and this is too
After the initial comments, the next line of the file must tell how many
variables (V a positive integer) and how many clauses (N a positive integer)
in this CNF format:
p cnf V N
The next N lines of the file each specify one single clause. DIMACS format
assumes your variables are x1, x2, x3, , xV. You specify a positive literal
(like x2 or x7) in this clause with a positive integer (in this case, 2 or 7). You
MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson. Copyright (c) 2007-2010 Niklas Sorensson
If we run MiniSat, it produces two sorts of outputs (1) some information sent to the
command line about how the internal DPLL search process went; (2) a yes/no
answer about satisfiability and any resulting satisfying assignment. So, if we run
the above file, the internal search information returned is this:
============================[ Problem Statistics ]=============================
|
|
| Number of variables:
3
|
| Number of clauses:
2
|
| Parse time:
0.00 s
|
|
|
============================[ Search Statistics ]==============================
| Conflicts |
ORIGINAL
|
LEARNT
| Progress |
|
|
Vars Clauses Literals |
Limit Clauses Lit/Cl |
|
===============================================================================
===============================================================================
restarts
: 1
conflicts
: 0
(0 /sec)
decisions
: 3
(0.00 % random) (3876 /sec)
propagations
: 3
(3876 /sec)
conflict literals
: 0
( nan % deleted)
Memory used
: 4.34 MB
CPU time
: 0.000774 s
SATISFIABLE
The [ Problem Statistics ] output tells you some useful things: how many
variables and clauses MiniSat found in your input file; how many variable decisions
(assignments) and Boolean constraint propagations (BCP steps) it did; what sort of
clause conflicts it found while doing DPLL search; and some other things related to
the clever heuristics all modern SAT solvers use.
The satisfiability result tells you yes/or no if it was satisfiable: Yes in this case, since
the result says SAT. And also an assignment of true/false values to the variables. If
a number appear as a positive integer k, it means that variable xk=1 in the satisfying
assignment. If a number appears as a negative integer k, it means that variable xk=0
in the satisfying assignment. So, in this example, x1=0, x2=1, x3=0 is the satisfying
assignment.
First, we connect the two circuits outputs with an EXOR gate; then we use MiniSat
to check if this new logic network can be satisfied (x7=1) or not. If it is satisfiable,
we will know the original two circuits are not equivalent, because there exists one
satisfying assignment such that x4 = 1, x6=0 or x4=0, x6=1.
Here are the SAT clauses converted from this little logic network:
(x2+x3)( x2+x3)( x1+x2+x5) (x1+x5) (x2+x5)
(x1+x3+x4) (x1+x4) (x3+x4) (x5+x6)( x5+x6)
(x4+x6+x7) (x4+x6+x7) (x4+x6+x7) (x4+x6+x7)(x7)
Here is the MiniSat output first [Problem Statistics], then the satisfiability result:
============================[ Problem Statistics ]=============================
|
|
| Number of variables:
7
|
| Number of clauses:
14
|
| Parse time:
0.00 s
|
|
|
============================[ Search Statistics ]==============================
| Conflicts |
ORIGINAL
|
LEARNT
| Progress |
|
|
Vars Clauses Literals |
Limit Clauses Lit/Cl |
|
===============================================================================
===============================================================================
restarts
: 1
conflicts
: 0
(0 /sec)
decisions
: 2
(0.00 % random) (2506 /sec)
propagations
: 7
(8772 /sec)
conflict literals
: 0
( nan % deleted)
Memory used
: 4.34 MB
CPU time
: 0.000798 s
SATISFIABLE
SAT
-1 2 -3 -4 -5 6 7 0
As we can see, the solver finds one satisfying assignment2 It gives the assignment
value for every variable in the input clauses. Since we only care about x1 and x2, the
real primary inputs to our logic, we can see that x1=0 and x2=1 will force the
EXOR output =1, and this is the input we want: it makes the two logic networks
2 Emphasis on the word one since there could be several solutions. When there is more than one solution,
MiniSAT returns just one of them. Thus, the output that you get from running MiniSat might be different.
create different output values, and demonstrates that they are not the same Boolean
function.
What is actually happening here is that the solver is doing some arithmetic and
dividing something by 0. In the above example, this is because there are 0 conflict
literals, and so an attempt to calculate some useful percentages results in a divideby-0. Another common reason for the nan is because the MiniSat solver is using
some system calls to measure the amount of CPU time each part of the computation
takes. On some platforms, for very small problems, these computations are so fast
that the system times returns a 0.0 result, for the number of time units (e.g.,
milliseconds). Then, when doing the calculations for computations / second, the
denominator is 0.0, and when you divide something by 0.0 what happens? The
answer on a modern computer with IEEE standard floating point
(http://en.wikipedia.org/wiki/IEEE_floating-point_standard), is something called a
Not-a-Number, which is abbreviated as NaN or nan. That is what is happening
here. Divide something by 0.0, and this nan is the result.