This is just a short list of things that are often asked about MiniSat. The answers refer to its current version. If you have more questions, maybe you can browse the MiniSat google groups, or read the other FAQ by David A. Wheeler, and maybe the definition of the DIMACS file format. I also suggest to attentively read the output of ./minisat --help, of which the most important part is:

USAGE: ./minisat [options] <input-file> <result-output-file>

  where input may be either in plain or gzipped DIMACS.

CORE OPTIONS:

  -luby, -no-luby                         (default: on)
  -rnd-init, -no-rnd-init                 (default: off)

  -gc-frac      = <double> (   0 ..  inf) (default: 0.2)
  -rinc         = <double> (   1 ..  inf) (default: 2)
  -rnd-seed     = <double> (   0 ..  inf) (default: 9.16483e+07)
  -rnd-freq     = <double> [   0 ..    1] (default: 0)
  -cla-decay    = <double> (   0 ..    1) (default: 0.999)
  -var-decay    = <double> (   0 ..    1) (default: 0.95)

  -rfirst       = <int32>  [   1 .. imax] (default: 100)
  -ccmin-mode   = <int32>  [   0 ..    2] (default: 2)
  -phase-saving = <int32>  [   0 ..    2] (default: 2)
  -min-learnts  = <int32>  [   0 .. imax] (default: 0)

MAIN OPTIONS:

  -strict, -no-strict                     (default: off)
  -pre, -no-pre                           (default: on)
  -verb         = <int32>  [   0 ..    2] (default: 1)

How are variables picked?

The function responsible is pickBranchLit() in MiniSat. There are two methods of picking. One picks from an ordered heap, and the other picks totally randomly. By default, MiniSat never picks randomly (see random_var_freq), though this is adjustable from the command line (see the -rnd-freq=X option, where X is the fraction of random picks). The ordered heap is simply an ordered set of variables. A variable is higher in the list if it appeared lots of times in the clauses that were involved in recent conflicts (see in function analyze() the part with varBumpActivity()).

Why doesn’t MiniSat find the solution to my problem that has at most 2-3 really important variables?

This is related to the previous question. You probably have a LOT of internal variables (that are not important), and MiniSat doesn’t know which variables are important: its heuristic only looks at which variables take part in conflicts, so it can get lost in a part of the search space that is uninteresting. If you have turned on random picks with -rnd-freq, turn them off. If you use MiniSat as a library, you can call setDecisionVar(v, false) for the internal variables so that MiniSat only branches on the important ones. Only do this for variables whose values are fully determined by the important ones: when all decision variables are set, MiniSat reports the problem as satisfiable even if some non-decision variables are still unassigned.

MiniSat is taking too long to solve my cryptographic function!

Try giving some randomly selected, randomly assigned “help bits”. These “help bits” should be of course your important variables (e.g. internal state or key). Run these random experiments with N number of help bits for 1000 times, and average the time. Now run with N-1 help bits, and average the time. Repeat with N-2, N-3… until you have enough points on the graph. The produced graph should be easy to extrapolate.

Does MiniSat check my p cnf VARS CLAUSES header?

Only if you ask it to. MiniSat reads the header, but by default it doesn’t enforce it: it automatically adds variables (see newVar()) and clauses (see addClause()) as it reads them. With the -strict option, it prints PARSE ERROR! DIMACS header mismatch: wrong number of clauses if the number of clauses doesn’t match the header.

How do I make my CNF file prettier? It looks like a spaghetti!

Use comments. They are lines starting with a c, like this:

c ------------
c clauses that code down equation number 3749
10 -2 7 0
14 -8 2 0
9 -1 5 0
c -----------

Does variable numbering matter?

No. But take care: if your variable numbers start at 100000, or a large range of variable numbers are unused, then MiniSat will have to store and work with useless memory contents. So, in general, use every variable number possible from 1 up. Don’t leave gaps, and don’t start numbering from large variable numbers.

If I change the order of the clauses, MiniSat solves faster/slower!

That’s by chance. MiniSat inserts the first clause of the DIMACS file into the beginning of its literal watch-lists (see attachClause()). When MiniSat starts propagating, it will propagate the first possible propagatable variable. So, depending on which is the first, second, etc. MiniSat will behave differently.

If you need to have an average time to solve for a certain problem, you should permute the clauses and also change the random seed of the solver, for example with CryptoMiniSat’s --seed=X option.

MiniSat is so fast to solve a problem whose unknown variables are almost all false!

This is because MiniSat guesses unknown variables to false by default (see the polarity initialisation in newVar() and its use in pickBranchLit()). Once a variable has been assigned, MiniSat by default remembers its last value and guesses that next time (“phase saving”, see the -phase-saving option; -phase-saving=0 turns it off). If you use MiniSat as a library, you can set the preferred polarity of a variable yourself, see newVar() and setPolarity().

MiniSat is so slow to solve a problem whose unknown variables are almost all true!

See previous question.

I have a simple linear set of equations, and MiniSat cannot solve it!

Let’s suppose we have a linear set of equations like: ( + is the binary XOR, variables are binary)

a + b + c + ... = true
a + c + e + ... = false
...

Let’s convert these equations to CNF! The SAT solver will not solve it in any reasonable amount of time. However, Gaussian elimination will solve it in seconds! Why? Because MiniSat doesn’t understand the structure of the problem. It will simply guess some of the variables and try to make propagations. However, if the equations are dense, then MiniSat will need to guess a lot of variables before any propagations can be made. So, the search tree will be huge.

To overcome this problem, CryptoMiniSat does Gauss-Jordan elimination on XOR constraints, which is on by default. You can give it the XORs directly, or let it recover them from the CNF; see the CryptoMiniSat FAQ for the details.

How can I make my solving faster?

This is too complex of a topic to go into. What I suggest are the following:

  • Have a look at the conversion of your functions to CNF. Maybe some can be improved? Try to use the excellent espresso logic minimiser or use BOOM.
  • Do you have a lot of XOR functions? Maybe you should consider using CryptoMiniSat. It handles XOR-s natively
  • Maybe you have forgotten to add the redundant clauses during the Tseitin transformation? (see page 5 of article by Een et al.)
  • Try to encode your problem by minimising the size and the number of clauses instead of the number of variables. Naturally, there is a trade-off, but focusing solely on the number of variables can lead to problems
  • Maybe other tools would work better. Grobner base algorithms are a starting point

How can I make MiniSat find ALL the solutions to a problem?

First of all, make sure the number of solutions is not too big. Then simply solve once, and output the solution to a file: ./minisat satfile solution. Then simply put in a clause into the satfile that is false for the found solution. E.g. let’s suppose the solution was

1 = true, 2 = true, 3 = false

Then put into the satfile the line:

-1 -2 3 0

and run MiniSat again. If the solution is UNSAT, then there are no other solutions. If it is SAT, then again put in a clause that bans that one solution. Iterate this as many times as you need a solution. (There is another way of doing this by using MiniSat as a library. It’s faster, too.)

There is a somewhat more detailed example in this FAQ, under the heading “Getting more solutions”.

Why is MiniSat giving me UNSAT without even looking at my file?

You probably have a line in your file that only has a 0 in it:

 0

this is an empty clause and so it is unsatisfiable. Therefore the system of clauses is unsatisfiable. Remove this clause.

How can I control the number of clauses learnt during solving?

Tweak the learntsize_factor and the learntsize_inc variables in MiniSat. Learning a lot of clauses might slow down the solver since it needs to jump to these clauses often to see if any of them make a conflict/propagation. But having too few, learning doesn’t help to trim the search tree. But the trade-off can be different for your problem. The values that are used in MiniSat are 1/3 for the init (i.e. learntsize_factor) and 1.1 for the increase per restart (i.e. learntsize_inc).

I want to make MiniSat run faster. What can I do?

If you use the gcc compiler, compile with flags "-O3 -g0 -march=native".

I want to know exactly what happens during solving!

Use small example problems, and turn up the verbosity: MiniSat’s -verb=2, or CryptoMiniSat’s --verb, which goes up to 10. When built with SQLite support, CryptoMiniSat can also write data about the clauses it learns into an SQLite database (--sql).

How does MiniSat keep track of which variable caused a propagation/conflict?

It’s always the first literal in the clause that is causing the propagation or conflict (see propagate()’s first reference variable).

Why doesn’t MiniSat simply use a vector<Lit> to store the literals in the clauses?

Probably because from a cache&program-flow point of view, it’s simply not a good idea. vector will store a pointer to an allocated memory space, which is probably somewhere else than the other data (size, marking, etc) of the clause, so the processor would have to jump there every time. Also, when accessing the Clause’s info, e.g. size(), data that is adjacent to this memory location will be pulled into the cache automatically, pulling in exactly what will be looked at next: the literals.

What is level and trail_lim?

level(x) returns the decision level at which variable x was assigned; it is stored, together with the reason for the assignment, in vardata. trail is the stack of assigned literals, in the order they were assigned. trail_lim stores, for each decision level, the position in trail where that level starts. So the current decision level is simply decisionLevel(), which returns trail_lim.size().

When guessing (=branching on) a variable, the following is called:

newDecisionLevel();   // trail_lim.push(trail.size());
uncheckedEnqueue(next);

i.e. inside trail_lim the current position in the trail (trail.size()) is stored, and the newly guessed literal is pushed on the trail. Its reason is CRef_Undef, to indicate that it’s not a propagation, but a guess.