| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 |
<html lang="en-US"> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 5 |
<title>MiniSAT User Guide: How to use the MiniSAT SAT Solver</title> |
| 6 |
<meta name="description" content="A user guide (documentation) for the MiniSAT (MiniSAT2) program, a minimalistic, open-source Boolean satisfiability problem (SAT) solver. It describes how to use MiniSAT, including its input format, options, and output format."> |
| 7 |
<meta name="keywords" content="miniSAT, miniSAT2, SAT, satisfiability, boolean satisfiability solver, documentation, howto, user guide, input, format, open source, open source software, formal methods, free software, FLOSS, David, Wheeler, David A. Wheeler, David Wheeler"> |
| 8 |
<meta name="generator" content="vim"> |
| 9 |
</head> |
| 10 |
<body> |
| 11 |
<h1>MiniSAT User Guide: How to use the MiniSAT SAT Solver</h1> |
| 12 |
<p> |
| 13 |
<i>by <a href="http://www.dwheeler.com">David A. Wheeler</a>, version 1.00 (2008-06-28)</i> |
| 14 |
<p> |
| 15 |
MiniSat is a minimalistic, open-source Boolean satisfiability problem |
| 16 |
(SAT) solver, developed for both researchers and developers; it |
| 17 |
is released under the "MIT license". |
| 18 |
<p> |
| 19 |
A SAT solver can determine if it is possible to find assignments to boolean |
| 20 |
variables that would make a given expression true, if the expression is |
| 21 |
written with only AND, OR, NOT, parentheses, and boolean variables. |
| 22 |
If it's satisfiable, most SAT solvers (including MiniSAT) |
| 23 |
can also show a set of assignments that make the expression true. |
| 24 |
Many problems can be broken down into a large SAT problem |
| 25 |
(perhaps with thousands of variables), so SAT solvers have a variety |
| 26 |
of uses. |
| 27 |
<p> |
| 28 |
This article is a brief |
| 29 |
user guide (documentation) for the MiniSAT (MiniSAT2) program. |
| 30 |
It describes how to use MiniSAT, including its input format, options, |
| 31 |
and output format. |
| 32 |
<p> |
| 33 |
<p> |
| 34 |
<h1>Conjunctive Normal Form (CNF)</h1> |
| 35 |
<p> |
| 36 |
Like many SAT solvers, MiniSAT requires that its input be in |
| 37 |
conjunctive normal form (CNF or cnf). |
| 38 |
CNF is built from these building blocks: |
| 39 |
<ul> |
| 40 |
<li><i>term</i>: A term is either a boolean variable (e.g., x4) |
| 41 |
or a negated boolean variable (NOT x4, written here as -x4). |
| 42 |
<li><i>clause</i>: A clause is a set of one or more terms, connected with OR |
| 43 |
(written here as |); boolean variables may not repeat inside a clause. |
| 44 |
<li><i>expression</i>: An expression is a set of one or more clauses, |
| 45 |
each connected by AND (written here as &). |
| 46 |
</ul> |
| 47 |
<p> |
| 48 |
An example of CNF is: |
| 49 |
<pre> |
| 50 |
(x1 | -x5 | x4) & |
| 51 |
(-x1 | x5 | x3 | x4) & |
| 52 |
(-x3 | x4). |
| 53 |
</pre> |
| 54 |
<p> |
| 55 |
Any boolean expression can be converted into CNF; |
| 56 |
algorithms and code for doing so are available elsewhere |
| 57 |
(e.g., see "Artificial Intelligence: A modern Approach" |
| 58 |
by Russel and Norvig, 1995). |
| 59 |
|
| 60 |
<p> |
| 61 |
<h1>MiniSAT input format</h1> |
| 62 |
<p> |
| 63 |
MiniSAT, like most SAT solvers, accepts its input in a simplified |
| 64 |
"DIMACS CNF" format, which is a simple text format. |
| 65 |
Every line beginning "c" is a comment. |
| 66 |
The first non-comment line must be of the form: |
| 67 |
<pre> |
| 68 |
p cnf NUMBER_OF_VARIABLES NUMBER_OF_CLAUSES |
| 69 |
</pre> |
| 70 |
<p> |
| 71 |
Each of the non-comment lines afterwards defines a clause. |
| 72 |
Each of these lines is a space-separated list of variables; |
| 73 |
a positive value means that corresponding variable |
| 74 |
(so 4 means x4), and a negative value means the negation of that variable |
| 75 |
(so -5 means -x5). |
| 76 |
Each line must end in a space and the number 0. |
| 77 |
<p> |
| 78 |
So the CNF expression above would be written as: |
| 79 |
<pre> |
| 80 |
c Here is a comment. |
| 81 |
p cnf 5 3 |
| 82 |
1 -5 4 0 |
| 83 |
-1 5 3 4 0 |
| 84 |
-3 -4 0 |
| 85 |
</pre> |
| 86 |
<p> |
| 87 |
The "p cnf" line means that this is SAT problem in CNF format with |
| 88 |
5 variables and 3 clauses. The first line after it is the first clause, |
| 89 |
meaning x1 | -x5 | x4. |
| 90 |
<p> |
| 91 |
You can view this as a single expression. |
| 92 |
Alternatively, you can view this as a set of clauses, and the |
| 93 |
solver's job is to find the set of boolean variable assignments that |
| 94 |
make all the clauses true. |
| 95 |
<p> |
| 96 |
The |
| 97 |
<a href="http://www.satcompetition.org/2004/format-solvers2004.html"> |
| 98 |
SAT 2004 competition</a> has more information. |
| 99 |
|
| 100 |
<p> |
| 101 |
<h1>Invoking MiniSAT</h1> |
| 102 |
<p> |
| 103 |
MiniSAT's usage is: |
| 104 |
<pre> |
| 105 |
minisat [options] [INPUT-FILE [RESULT-OUTPUT-FILE]] |
| 106 |
</pre> |
| 107 |
<p> |
| 108 |
The INPUT-FILE is in DIMACS CNF format as described above, either |
| 109 |
plain text or gzipped. |
| 110 |
You can invoke it with the options "-h" or "--help" to see the other options. |
| 111 |
<p> |
| 112 |
The program's options include: |
| 113 |
<pre> |
| 114 |
-pre = {none,once} [Turn on preprocessor] |
| 115 |
-asymm |
| 116 |
-rcheck |
| 117 |
-grow = NUM [ must be greater than 0 ] |
| 118 |
-polarity-mode = {true,false,rnd} |
| 119 |
-decay = NUM [ 0 - 1 ] |
| 120 |
-rnd-freq = NUM [ 0 - 1 ] |
| 121 |
-dimacs = OUTPUT-FILE |
| 122 |
-verbosity = {0,1,2} |
| 123 |
</pre> |
| 124 |
<p> |
| 125 |
Options with a value must be immediately followed by "=" and its value, e.g.: |
| 126 |
<pre> |
| 127 |
minisat -pre=once |
| 128 |
</pre> |
| 129 |
<p> |
| 130 |
For many problems, using the preprocessor is a good idea (-pre=once). |
| 131 |
<p> |
| 132 |
|
| 133 |
<p> |
| 134 |
<h1>MiniSAT output format</h1> |
| 135 |
<p> |
| 136 |
When run, miniSAT sends to standard error a number of different |
| 137 |
statistics about its execution. |
| 138 |
It will output to standard output either |
| 139 |
"SATISFIABLE" or "UNSATISFIABLE" (without the quote marks), depending |
| 140 |
on whether or not the expression is satisfiable or not. |
| 141 |
<p> |
| 142 |
If you give it a RESULT-OUTPUT-FILE, miniSAT will write text to the file. |
| 143 |
The first line will be "SAT" (if it is satisfiable) or "UNSAT" |
| 144 |
(if it is not). |
| 145 |
If it is SAT, the second line will be set of assignments to the |
| 146 |
boolean variables that satisfies the expression. |
| 147 |
(There may be many others; it simply has to produce <i>one</i> assignment). |
| 148 |
<p> |
| 149 |
So for the example above, it will produce in the output file: |
| 150 |
<pre> |
| 151 |
SAT |
| 152 |
1 2 -3 4 5 0 |
| 153 |
</pre> |
| 154 |
<p> |
| 155 |
This means that it <i>is</i> satisfiable, with |
| 156 |
x1=t, x2=t, x3=f, x4=t, and x5=t (where t is true and f is false). |
| 157 |
Going back to our original example, we should see that this is a |
| 158 |
solution: |
| 159 |
<pre> |
| 160 |
(x1 | -x5 | x4) = t | -t | t = t |
| 161 |
(-x1 | x5 | x3 | x4) = -t | t | f | t = t |
| 162 |
(-x3 | x4) = -f | t = t |
| 163 |
</pre> |
| 164 |
|
| 165 |
<p> |
| 166 |
<h1>Getting more solutions</h1> |
| 167 |
<p> |
| 168 |
If you want to get another solution, the "obvious" way is to |
| 169 |
add, as a new clause, the negated form of the previous solution. |
| 170 |
E.G., for our example, we could take: |
| 171 |
<pre> |
| 172 |
1 2 -3 4 5 0 |
| 173 |
</pre> |
| 174 |
and create this new input (note that the count of clauses has increased): |
| 175 |
<pre> |
| 176 |
p cnf 5 4 |
| 177 |
1 -5 4 0 |
| 178 |
-1 5 3 4 0 |
| 179 |
-3 -4 0 |
| 180 |
-1 -2 3 -4 -5 0 |
| 181 |
</pre> |
| 182 |
<p> |
| 183 |
If we put this in file "second.in", and run: |
| 184 |
<pre> |
| 185 |
minisat second.in second.out |
| 186 |
</pre> |
| 187 |
We will get a new solution; here's second.out: |
| 188 |
<pre> |
| 189 |
SAT |
| 190 |
1 -2 -3 4 5 0 |
| 191 |
</pre> |
| 192 |
IE., x1=t, x2=f, x3=f, x4=t, and x5=t. |
| 193 |
This is a different solution from the previous one, because x2=f instead of |
| 194 |
x2=t. |
| 195 |
We can confirm this (it's the same as last time, |
| 196 |
because x2 isn't even in any of the clauses): |
| 197 |
<pre> |
| 198 |
(x1 | -x5 | x4) = t | -t | t = t |
| 199 |
(-x1 | x5 | x3 | x4) = -t | t | f | t = t |
| 200 |
(-x3 | x4) = -f | t = t |
| 201 |
</pre> |
| 202 |
|
| 203 |
|
| 204 |
<p> |
| 205 |
<h1>For more information</h1> |
| 206 |
<p> |
| 207 |
You can get more information from: |
| 208 |
<ul> |
| 209 |
<li> |
| 210 |
<a href="http://en.wikipedia.org/wiki/Boolean_satisfiability_problem"> |
| 211 |
Wikipedia's article "Boolean satisfiability problem"</a> |
| 212 |
<li> |
| 213 |
<a href="http://en.wikipedia.org/wiki/Conjunctive_normal_form"> |
| 214 |
Wikipedia's article "Conjunctive normal form"</a> |
| 215 |
<li> |
| 216 |
<a href="http://www.satlive.org/">SAT Live!</a> - links/news about the |
| 217 |
SAT problem |
| 218 |
<li><a href="http://www.satisfiability.org/"> |
| 219 |
The International Conferences on |
| 220 |
Theory and Applications of Satisfiability Testing (SAT)</a> |
| 221 |
<li> |
| 222 |
<a href="http://www.satlib.org">SATLIB - The Satisfiability Library</a> |
| 223 |
<li> |
| 224 |
<a href="http://www.dwheeler.com/essays/high-assurance-floss.html"> |
| 225 |
High Assurance (for Security or Safety) and Free-Libre / Open Source Software (FLOSS)... with Lots on Formal Methods (aka high confidence or high integrity)</a> has a long list of FLOSS tools that support high assurance efforts, |
| 226 |
including SAT solvers. |
| 227 |
</ul> |
| 228 |
|
| 229 |
<p> |
| 230 |
<hr> |
| 231 |
<p> |
| 232 |
This article was written by |
| 233 |
<a href="http://www.dwheeler.com">David A. Wheeler</a>, and is released |
| 234 |
to the public domain. |
| 235 |
If you use it or reference it, please credit David A. Wheeler |
| 236 |
(though this is not a requirement for its use). |
| 237 |
You can get this version at |
| 238 |
<a href="http://www.dwheeler.com/essays/minisat-user-guide-1.0.html"> |
| 239 |
http://www.dwheeler.com/essays/minisat-user-guide-1.0.html</a>, or |
| 240 |
the latest version at |
| 241 |
<a href="http://www.dwheeler.com/essays/minisat-user-guide.html"> |
| 242 |
http://www.dwheeler.com/essays/minisat-user-guide.html</a>. |
| 243 |
|
| 244 |
</body> |
| 245 |
|