A general purpose SAT solver.
A SAT problem consists of a set of variables and a set of clauses which must be satisfied.
A literal is either a variable (e.g. A
) or a negated variable (not A
).
A clause is a boolean expression made up of literals. e.g. A and B and not(C)
Indicate that the problem is unsolvable, before even starting. This is a convenience feature so that clients don't need a separate code path for problems they discover during setup vs problems discovered by the solver.
If the first variable is true, at least one of the others must be.
implies p a bs
is equivalent to at_least_one p ((neg a) :: bs)
.
reason
is used in debug messages.
Add a clause preventing more than one literal in the list from being True
.
run_solver decider
tries to solve the SAT problem. It simplifies it as much as possible first. When it
has two paths which both appear possible, it calls decider ()
to choose which to explore first. If this
leads to a solution, it will be used. If not, the other path will be tried. If decider
returns None
,
we try setting the remaining variables to False
(decider
will not be called again unless we backtrack).
Use this to tidy up at the end, when you no longer care about the order.
Return the first literal in the list whose value is Undecided
, or None
if they're all decided.
The decider function may find this useful.