Module Sat.Make
Parameters
Signature
type var_value=|True|False|Undecidedtype litA literal is either a variable (e.g.
A) or a negated variable (not A).
Setting up the problem.
val create : unit -> tCreate a problem.
type solution= lit -> boolGet the assignment for this literal in the discovered solution.
val impossible : t -> unit -> unitIndicate 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.
type added_result=|AddedFact of bool|AddedClause of clause
val at_least_one : t -> ?reason:string -> lit list -> unitAdd a clause requiring at least one literal to be
True. e.g.A or B or not(C).reasonis used in debug messages.
val implies : t -> ?reason:string -> lit -> lit list -> unitIf the first variable is true, at least one of the others must be.
implies p a bsis equivalent toat_least_one p ((neg a) :: bs).reasonis used in debug messages.
val at_most_one : t -> lit list -> at_most_one_clauseAdd a clause preventing more than one literal in the list from being
True.
val run_solver : t -> (unit -> lit option) -> solution optionrun_solver decidertries to solve the SAT problem. It simplifies it as much as possible first. When it has two paths which both appear possible, it callsdecider ()to choose which to explore first. If this leads to a solution, it will be used. If not, the other path will be tried. IfdeciderreturnsNone, we try setting the remaining variables toFalse(deciderwill not be called again unless we backtrack). Use this to tidy up at the end, when you no longer care about the order.
val get_best_undecided : at_most_one_clause -> lit optionReturn the first literal in the list whose value is
Undecided, orNoneif they're all decided. The decider function may find this useful.
val get_selected : at_most_one_clause -> lit optionReturn the selected literal, if any.
Debugging
type reason=|Clause of clause|External of string