src/HOL/Tools/sat_solver.ML
author webertj
Thu Jun 17 22:01:23 2004 +0200 (2004-06-17)
changeset 14965 7155b319eafa
parent 14805 eff7b9df27e9
child 14999 2c39efba8f67
permissions -rw-r--r--
new SAT solver interface
     1 (*  Title:      HOL/Tools/sat_solver.ML
     2     ID:         $Id$
     3     Author:     Tjark Weber
     4     Copyright   2004
     5 
     6 Interface to external SAT solvers, and (simple) built-in SAT solvers.
     7 *)
     8 
     9 signature SAT_SOLVER =
    10 sig
    11 	exception NOT_CONFIGURED
    12 
    13 	type assignment = int -> bool option
    14 	datatype result = SATISFIABLE of assignment
    15 	                | UNSATISFIABLE
    16 	                | UNKNOWN
    17 	type solver     = PropLogic.prop_formula -> result
    18 
    19 	(* auxiliary functions to create external SAT solvers *)
    20 	val write_dimacs_cnf_file : Path.T -> PropLogic.prop_formula -> unit
    21 	val write_dimacs_sat_file : Path.T -> PropLogic.prop_formula -> unit
    22 	val parse_std_result_file : Path.T -> string * string * string -> result
    23 	val make_external_solver  : string -> (PropLogic.prop_formula -> unit) -> (unit -> result) -> solver
    24 
    25 	(* generic interface *)
    26 	val solvers       : (string * solver) list ref
    27 	val add_solver    : string * solver -> unit
    28 	val invoke_solver : string -> solver  (* exception OPTION *)
    29 end;
    30 
    31 structure SatSolver : SAT_SOLVER =
    32 struct
    33 
    34 	open PropLogic;
    35 
    36 (* ------------------------------------------------------------------------- *)
    37 (* should be raised by an external SAT solver to indicate that the solver is *)
    38 (* not configured properly                                                   *)
    39 (* ------------------------------------------------------------------------- *)
    40 
    41 	exception NOT_CONFIGURED;
    42 
    43 (* ------------------------------------------------------------------------- *)
    44 (* type of partial (satisfying) assignments: 'a i = None' means that 'a' is  *)
    45 (*      a satisfying assigment regardless of the value of variable 'i'       *)
    46 (* ------------------------------------------------------------------------- *)
    47 
    48 	type assignment = int -> bool option;
    49 
    50 (* ------------------------------------------------------------------------- *)
    51 (* return type of SAT solvers: if the result is 'SATISFIABLE', a satisfying  *)
    52 (*      assignment must be returned as well                                  *)
    53 (* ------------------------------------------------------------------------- *)
    54 
    55 	datatype result = SATISFIABLE of assignment
    56 	                | UNSATISFIABLE
    57 	                | UNKNOWN;
    58 
    59 (* ------------------------------------------------------------------------- *)
    60 (* type of SAT solvers: given a propositional formula, a satisfying          *)
    61 (*      assignment may be returned                                           *)
    62 (* ------------------------------------------------------------------------- *)
    63 
    64 	type solver = prop_formula -> result;
    65 
    66 (* ------------------------------------------------------------------------- *)
    67 (* write_dimacs_cnf_file: serializes a formula 'fm' of propositional logic   *)
    68 (*      to a file in DIMACS CNF format (see "Satisfiability Suggested        *)
    69 (*      Format", May 8 1993, Section 2.1)                                    *)
    70 (* Note: 'fm' must not contain a variable index less than 1.                 *)
    71 (* Note: 'fm' must be given in CNF.                                          *)
    72 (* ------------------------------------------------------------------------- *)
    73 
    74 	(* Path.T -> prop_formula -> unit *)
    75 
    76 	fun write_dimacs_cnf_file path fm =
    77 	let
    78 		(* prop_formula -> prop_formula *)
    79 		fun cnf_True_False_elim True =
    80 			Or (BoolVar 1, Not (BoolVar 1))
    81 		  | cnf_True_False_elim False =
    82 			And (BoolVar 1, Not (BoolVar 1))
    83 		  | cnf_True_False_elim fm =
    84 			fm  (* since 'fm' is in CNF, either 'fm'='True'/'False', or 'fm' does not contain 'True'/'False' at all *)
    85 		(* prop_formula -> int *)
    86 		fun cnf_number_of_clauses (And (fm1,fm2)) =
    87 			(cnf_number_of_clauses fm1) + (cnf_number_of_clauses fm2)
    88 		  | cnf_number_of_clauses _ =
    89 			1
    90 		(* prop_formula -> string *)
    91 		fun cnf_string True =
    92 			error "formula is not in CNF"
    93 		  | cnf_string False =
    94 			error "formula is not in CNF"
    95 		  | cnf_string (BoolVar i) =
    96 			(assert (i>=1) "formula contains a variable index less than 1";
    97 			string_of_int i)
    98 		  | cnf_string (Not fm) =
    99 			"-" ^ cnf_string fm
   100 		  | cnf_string (Or (fm1,fm2)) =
   101 			cnf_string fm1 ^ " " ^ cnf_string fm2
   102 		  | cnf_string (And (fm1,fm2)) =
   103 			cnf_string fm1 ^ " 0\n" ^ cnf_string fm2
   104 	in
   105 		File.write path
   106 			(let
   107 				val fm'               = cnf_True_False_elim fm
   108 				val number_of_vars    = maxidx fm'
   109 				val number_of_clauses = cnf_number_of_clauses fm'
   110 				val cnfstring         = cnf_string fm'
   111 			in
   112 				"c This file was generated by SatSolver.write_dimacs_cnf_file\n" ^
   113 				"c (c) Tjark Weber\n" ^
   114 				"p cnf " ^ string_of_int number_of_vars ^ " " ^ string_of_int number_of_clauses ^ "\n" ^
   115 				cnfstring ^ " 0\n"
   116 			end)
   117 	end;
   118 
   119 (* ------------------------------------------------------------------------- *)
   120 (* write_dimacs_sat_file: serializes a formula 'fm' of propositional logic   *)
   121 (*      to a file in DIMACS SAT format (see "Satisfiability Suggested        *)
   122 (*      Format", May 8 1993, Section 2.2)                                    *)
   123 (* Note: 'fm' must not contain a variable index less than 1.                 *)
   124 (* ------------------------------------------------------------------------- *)
   125 
   126 	(* Path.T -> prop_formula -> unit *)
   127 
   128 	fun write_dimacs_sat_file path fm =
   129 	let
   130 		(* prop_formula -> string *)
   131 		fun sat_string True =
   132 			"*()"
   133 		  | sat_string False =
   134 			"+()"
   135 		  | sat_string (BoolVar i) =
   136 			(assert (i>=1) "formula contains a variable index less than 1";
   137 			string_of_int i)
   138 		  | sat_string (Not fm) =
   139 			"-(" ^ sat_string fm ^ ")"
   140 		  | sat_string (Or (fm1,fm2)) =
   141 			"+(" ^ sat_string fm1 ^ " " ^ sat_string fm2 ^ ")"
   142 		  | sat_string (And (fm1,fm2)) =
   143 			"*(" ^ sat_string fm1 ^ " " ^ sat_string fm2 ^ ")"
   144 	in
   145 		File.write path
   146 			(let
   147 				val number_of_vars = Int.max (maxidx fm, 1)
   148 			in
   149 				"c This file was generated by SatSolver.write_dimacs_sat_file\n" ^
   150 				"c (c) Tjark Weber\n" ^
   151 				"p sat " ^ string_of_int number_of_vars ^ "\n" ^
   152 				"(" ^ sat_string fm ^ ")\n"
   153 			end)
   154 	end;
   155 
   156 (* ------------------------------------------------------------------------- *)
   157 (* parse_std_result_file: scans a SAT solver's output file for a satisfying  *)
   158 (*      variable assignment.  Returns the assignment, or 'UNSATISFIABLE' if  *)
   159 (*      the file contains 'unsatisfiable', or 'UNKNOWN' if the file contains *)
   160 (*      neither 'satisfiable' nor 'unsatisfiable'.  Empty lines are ignored. *)
   161 (*      The assignment must be given in one or more lines immediately after  *)
   162 (*      the line that contains 'satisfiable'.  These lines must begin with   *)
   163 (*      'assignment_prefix'.  Variables must be separated by " ".  Non-      *)
   164 (*      integer strings are ignored.  If variable i is contained in the      *)
   165 (*      assignment, then i is interpreted as 'true'.  If ~i is contained in  *)
   166 (*      the assignment, then i is interpreted as 'false'.  Otherwise the     *)
   167 (*      value of i is taken to be unspecified.                               *)
   168 (* ------------------------------------------------------------------------- *)
   169 
   170 	(* Path.T -> string * string * string -> result *)
   171 
   172 	fun parse_std_result_file path (satisfiable, assignment_prefix, unsatisfiable) =
   173 	let
   174 		(* 'a option -> 'a Library.option *)
   175 		fun option (SOME a) =
   176 			Some a
   177 		  | option NONE =
   178 			None
   179 		(* string -> int list *)
   180 		fun int_list_from_string s =
   181 			mapfilter (option o Int.fromString) (space_explode " " s)
   182 		(* int list -> assignment *)
   183 		fun assignment_from_list [] i =
   184 			None  (* the SAT solver didn't provide a value for this variable *)
   185 		  | assignment_from_list (x::xs) i =
   186 			if x=i then (Some true)
   187 			else if x=(~i) then (Some false)
   188 			else assignment_from_list xs i
   189 		(* int list -> string list -> assignment *)
   190 		fun parse_assignment xs [] =
   191 			assignment_from_list xs
   192 		  | parse_assignment xs (line::lines) =
   193 			if String.isPrefix assignment_prefix line then
   194 				parse_assignment (xs @ int_list_from_string line) lines
   195 			else
   196 				assignment_from_list xs
   197 		(* string -> string -> bool *)
   198 		fun is_substring needle haystack =
   199 		let
   200 			val length1 = String.size needle
   201 			val length2 = String.size haystack
   202 		in
   203 			if length2 < length1 then
   204 				false
   205 			else if needle = String.substring (haystack, 0, length1) then
   206 				true
   207 			else is_substring needle (String.substring (haystack, 1, length2-1))
   208 		end
   209 		(* string list -> result *)
   210 		fun parse_lines [] =
   211 			UNKNOWN
   212 		  | parse_lines (line::lines) =
   213 			if is_substring satisfiable line then
   214 				SATISFIABLE (parse_assignment [] lines)
   215 			else if is_substring unsatisfiable line then
   216 				UNSATISFIABLE
   217 			else
   218 				parse_lines lines
   219 	in
   220 		(parse_lines o (filter (fn l => l <> "")) o split_lines o File.read) path
   221 	end;
   222 
   223 (* ------------------------------------------------------------------------- *)
   224 (* make_external_solver: call 'writefn', execute 'cmd', call 'readfn'        *)
   225 (* ------------------------------------------------------------------------- *)
   226 
   227 	(* string -> (PropLogic.prop_formula -> unit) -> (unit -> result) -> solver *)
   228 
   229 	fun make_external_solver cmd writefn readfn fm =
   230 		(writefn fm; system cmd; readfn ());
   231 
   232 (* ------------------------------------------------------------------------- *)
   233 (* solvers: a (reference to a) table of all registered SAT solvers           *)
   234 (* ------------------------------------------------------------------------- *)
   235 
   236 	val solvers = ref ([] : (string * solver) list);
   237 
   238 (* ------------------------------------------------------------------------- *)
   239 (* add_solver: updates 'solvers' by adding a new solver                      *)
   240 (* ------------------------------------------------------------------------- *)
   241 
   242 	(* string * solver -> unit *)
   243 
   244 	fun add_solver (name, new_solver) =
   245 		(solvers := overwrite_warn (!solvers, (name, new_solver)) ("SAT solver " ^ quote name ^ " was defined before"));
   246 
   247 (* ------------------------------------------------------------------------- *)
   248 (* invoke_solver: returns the solver associated with the given 'name'        *)
   249 (* Note: If no solver is associated with 'name', exception 'OPTION' will be  *)
   250 (*       raised.                                                             *)
   251 (* ------------------------------------------------------------------------- *)
   252 
   253 	(* string -> solver *)
   254 
   255 	fun invoke_solver name =
   256 		(the o assoc) (!solvers, name);
   257 
   258 end;  (* SatSolver *)
   259 
   260 
   261 (* ------------------------------------------------------------------------- *)
   262 (* Predefined SAT solvers                                                    *)
   263 (* ------------------------------------------------------------------------- *)
   264 
   265 (* ------------------------------------------------------------------------- *)
   266 (* Internal SAT solver, available as 'SatSolver.invoke_solver "enumerate"'   *)
   267 (* -- simply enumerates assignments until a satisfying assignment is found   *)
   268 (* ------------------------------------------------------------------------- *)
   269 
   270 let
   271 	fun enum_solver fm =
   272 	let
   273 		(* int list *)
   274 		val indices = PropLogic.indices fm
   275 		(* int list -> int list -> int list option *)
   276 		(* binary increment: list 'xs' of current bits, list 'ys' of all bits (lower bits first) *)
   277 		fun next_list _ ([]:int list) =
   278 			None
   279 		  | next_list [] (y::ys) =
   280 			Some [y]
   281 		  | next_list (x::xs) (y::ys) =
   282 			if x=y then
   283 				(* reset the bit, continue *)
   284 				next_list xs ys
   285 			else
   286 				(* set the lowest bit that wasn't set before, keep the higher bits *)
   287 				Some (y::x::xs)
   288 		(* int list -> int -> bool *)
   289 		fun assignment_from_list xs i =
   290 			i mem xs
   291 		(* int list -> SatSolver.result *)
   292 		fun solver_loop xs =
   293 			if PropLogic.eval (assignment_from_list xs) fm then
   294 				SatSolver.SATISFIABLE (Some o (assignment_from_list xs))
   295 			else
   296 				(case next_list xs indices of
   297 				  Some xs' => solver_loop xs'
   298 				| None     => SatSolver.UNSATISFIABLE)
   299 	in
   300 		(* start with the "first" assignment (all variables are interpreted as 'false') *)
   301 		solver_loop []
   302 	end
   303 in
   304 	SatSolver.add_solver ("enumerate", enum_solver)
   305 end;
   306 
   307 (* ------------------------------------------------------------------------- *)
   308 (* Internal SAT solver, available as 'SatSolver.invoke_solver "dpll"' -- a   *)
   309 (* simple implementation of the DPLL algorithm (cf. L. Zhang, S. Malik: "The *)
   310 (* Quest for Efficient Boolean Satisfiability Solvers", July 2002, Fig. 1).  *)
   311 (* ------------------------------------------------------------------------- *)
   312 
   313 let
   314 	local
   315 		open PropLogic
   316 	in
   317 		fun dpll_solver fm =
   318 		let
   319 			(* We could use 'PropLogic.defcnf fm' instead of 'PropLogic.nnf fm' *)
   320 			(* but that sometimes introduces more boolean variables than we can *)
   321 			(* handle efficiently.                                              *)
   322 			val fm' = PropLogic.nnf fm
   323 			(* int list *)
   324 			val indices = PropLogic.indices fm'
   325 			(* int list -> int -> prop_formula *)
   326 			fun partial_var_eval []      i = BoolVar i
   327 			  | partial_var_eval (x::xs) i = if x=i then True else if x=(~i) then False else partial_var_eval xs i
   328 			(* int list -> prop_formula -> prop_formula *)
   329 			fun partial_eval xs True             = True
   330 			  | partial_eval xs False            = False
   331 			  | partial_eval xs (BoolVar i)      = partial_var_eval xs i
   332 			  | partial_eval xs (Not fm)         = SNot (partial_eval xs fm)
   333 			  | partial_eval xs (Or (fm1, fm2))  = SOr (partial_eval xs fm1, partial_eval xs fm2)
   334 			  | partial_eval xs (And (fm1, fm2)) = SAnd (partial_eval xs fm1, partial_eval xs fm2)
   335 			(* prop_formula -> int list *)
   336 			fun forced_vars True              = []
   337 			  | forced_vars False             = []
   338 			  | forced_vars (BoolVar i)       = [i]
   339 			  | forced_vars (Not (BoolVar i)) = [~i]
   340 			  | forced_vars (Or (fm1, fm2))   = (forced_vars fm1) inter_int (forced_vars fm2)
   341 			  | forced_vars (And (fm1, fm2))  = (forced_vars fm1) union_int (forced_vars fm2)
   342 			  (* Above, i *and* ~i may be forced.  In this case the first occurrence takes   *)
   343 			  (* precedence, and the next partial evaluation of the formula returns 'False'. *)
   344 			  | forced_vars _                 = raise ERROR  (* formula is not in negation normal form *)
   345 			(* int list -> prop_formula -> (int list * prop_formula) *)
   346 			fun eval_and_force xs fm =
   347 			let
   348 				val fm' = partial_eval xs fm
   349 				val xs' = forced_vars fm'
   350 			in
   351 				if null xs' then
   352 					(xs, fm')
   353 				else
   354 					eval_and_force (xs@xs') fm'  (* xs and xs' should be distinct, so '@' here should have *)
   355 					                             (* the same effect as 'union_int'                         *)
   356 			end
   357 			(* int list -> int option *)
   358 			fun fresh_var xs =
   359 				Library.find_first (fn i => not (i mem_int xs) andalso not ((~i) mem_int xs)) indices
   360 			(* int list -> prop_formula -> int list option *)
   361 			(* partial assignment 'xs' *)
   362 			fun dpll xs fm =
   363 			let
   364 				val (xs', fm') = eval_and_force xs fm
   365 			in
   366 				case fm' of
   367 				  True  => Some xs'
   368 				| False => None
   369 				| _     =>
   370 					let
   371 						val x = the (fresh_var xs')  (* a fresh variable must exist since 'fm' did not evaluate to 'True'/'False' *)
   372 					in
   373 						case dpll (x::xs') fm' of  (* passing fm' rather than fm should save some simplification work *)
   374 						  Some xs'' => Some xs''
   375 						| None      => dpll ((~x)::xs') fm'  (* now try interpreting 'x' as 'False' *)
   376 					end
   377 			end
   378 			(* int list -> assignment *)
   379 			fun assignment_from_list [] i =
   380 				None  (* the DPLL procedure didn't provide a value for this variable *)
   381 			  | assignment_from_list (x::xs) i =
   382 				if x=i then (Some true)
   383 				else if x=(~i) then (Some false)
   384 				else assignment_from_list xs i
   385 		in
   386 			(* initially, no variable is interpreted yet *)
   387 			case dpll [] fm' of
   388 			  Some assignment => SatSolver.SATISFIABLE (assignment_from_list assignment)
   389 			| None            => SatSolver.UNSATISFIABLE
   390 		end
   391 	end  (* local *)
   392 in
   393 	SatSolver.add_solver ("dpll", dpll_solver)
   394 end;
   395 
   396 (* ------------------------------------------------------------------------- *)
   397 (* Internal SAT solver, available as 'SatSolver.invoke_solver "auto"': uses  *)
   398 (* all installed solvers (other than "auto" itself) until one returns either *)
   399 (* SATISFIABLE or UNSATISFIABLE                                              *)
   400 (* ------------------------------------------------------------------------- *)
   401 
   402 let
   403 	fun auto_solver fm =
   404 	let
   405 		fun loop [] =
   406 			SatSolver.UNKNOWN
   407 		  | loop ((name, solver)::solvers) =
   408 			if name="auto" then
   409 				(* do not call solver "auto" from within "auto" *)
   410 				loop solvers
   411 			else
   412 			(
   413 				(if name="dpll" orelse name="enumerate" then
   414 					warning ("Using SAT solver " ^ quote name ^ "; for better performance, consider using an external solver.")
   415 				else
   416 					());
   417 				(* apply 'solver' to 'fm' *)
   418 				(case solver fm of
   419 				  SatSolver.SATISFIABLE a => SatSolver.SATISFIABLE a
   420 				| SatSolver.UNSATISFIABLE => SatSolver.UNSATISFIABLE
   421 				| SatSolver.UNKNOWN       => loop solvers)
   422 				handle SatSolver.NOT_CONFIGURED => loop solvers
   423 			)
   424 	in
   425 		loop (rev (!SatSolver.solvers))
   426 	end
   427 in
   428 	SatSolver.add_solver ("auto", auto_solver)
   429 end;
   430 
   431 (* ------------------------------------------------------------------------- *)
   432 (* ZChaff, Version 2003.12.04 (http://www.princeton.edu/~chaff/zchaff.html)  *)
   433 (* ------------------------------------------------------------------------- *)
   434 
   435 let
   436 	fun zchaff fm =
   437 	let
   438 		val _          = if (getenv "ZCHAFF_HOME") = "" then raise SatSolver.NOT_CONFIGURED else ()
   439 		val inpath     = File.tmp_path (Path.unpack "isabelle.cnf")
   440 		val outpath    = File.tmp_path (Path.unpack "result")
   441 		val cmd        = (getenv "ZCHAFF_HOME") ^ "/zchaff " ^ (Path.pack inpath) ^ " > " ^ (Path.pack outpath)
   442 		fun writefn fm = SatSolver.write_dimacs_cnf_file inpath (PropLogic.defcnf fm)
   443 		fun readfn ()  = SatSolver.parse_std_result_file outpath ("Verify Solution successful. Instance satisfiable", "", "Instance unsatisfiable")
   444 		val _          = assert (not (File.exists inpath)) ("file " ^ quote (Path.pack inpath) ^ " exists, please delete (will not overwrite)")
   445 		val _          = assert (not (File.exists outpath)) ("file " ^ quote (Path.pack outpath) ^ " exists, please delete (will not overwrite)")
   446 		val result     = SatSolver.make_external_solver cmd writefn readfn fm
   447 		val _          = (File.rm inpath handle _ => ())
   448 		val _          = (File.rm outpath handle _ => ())
   449 	in
   450 		result
   451 	end
   452 in
   453 	SatSolver.add_solver ("zchaff", zchaff)
   454 end;
   455 
   456 (* ------------------------------------------------------------------------- *)
   457 (* BerkMin 561 (http://eigold.tripod.com/BerkMin.html)                       *)
   458 (* ------------------------------------------------------------------------- *)
   459 
   460 let
   461 	fun berkmin fm =
   462 	let
   463 		val _          = if (getenv "BERKMIN_HOME") = "" orelse (getenv "BERKMIN_EXE") = "" then raise SatSolver.NOT_CONFIGURED else ()
   464 		val inpath     = File.tmp_path (Path.unpack "isabelle.cnf")
   465 		val outpath    = File.tmp_path (Path.unpack "result")
   466 		val cmd        = (getenv "BERKMIN_HOME") ^ "/" ^ (getenv "BERKMIN_EXE") ^ " " ^ (Path.pack inpath) ^ " > " ^ (Path.pack outpath)
   467 		fun writefn fm = SatSolver.write_dimacs_cnf_file inpath (PropLogic.defcnf fm)
   468 		fun readfn ()  = SatSolver.parse_std_result_file outpath ("Satisfiable          !!", "solution =", "UNSATISFIABLE          !!")
   469 		val _          = assert (not (File.exists inpath)) ("file " ^ quote (Path.pack inpath) ^ " exists, please delete (will not overwrite)")
   470 		val _          = assert (not (File.exists outpath)) ("file " ^ quote (Path.pack outpath) ^ " exists, please delete (will not overwrite)")
   471 		val result     = SatSolver.make_external_solver cmd writefn readfn fm
   472 		val _          = (File.rm inpath handle _ => ())
   473 		val _          = (File.rm outpath handle _ => ())
   474 	in
   475 		result
   476 	end
   477 in
   478 	SatSolver.add_solver ("berkmin", berkmin)
   479 end;
   480 
   481 (* ------------------------------------------------------------------------- *)
   482 (* Jerusat 1.3 (http://www.cs.tau.ac.il/~ale1/)                              *)
   483 (* ------------------------------------------------------------------------- *)
   484 
   485 let
   486 	fun jerusat fm =
   487 	let
   488 		val _          = if (getenv "JERUSAT_HOME") = "" then raise SatSolver.NOT_CONFIGURED else ()
   489 		val inpath     = File.tmp_path (Path.unpack "isabelle.cnf")
   490 		val outpath    = File.tmp_path (Path.unpack "result")
   491 		val cmd        = (getenv "JERUSAT_HOME") ^ "/Jerusat1.3 " ^ (Path.pack inpath) ^ " > " ^ (Path.pack outpath)
   492 		fun writefn fm = SatSolver.write_dimacs_cnf_file inpath (PropLogic.defcnf fm)
   493 		fun readfn ()  = SatSolver.parse_std_result_file outpath ("s SATISFIABLE", "v ", "s UNSATISFIABLE")
   494 		val _          = assert (not (File.exists inpath)) ("file " ^ quote (Path.pack inpath) ^ " exists, please delete (will not overwrite)")
   495 		val _          = assert (not (File.exists outpath)) ("file " ^ quote (Path.pack outpath) ^ " exists, please delete (will not overwrite)")
   496 		val result     = SatSolver.make_external_solver cmd writefn readfn fm
   497 		val _          = (File.rm inpath handle _ => ())
   498 		val _          = (File.rm outpath handle _ => ())
   499 	in
   500 		result
   501 	end
   502 in
   503 	SatSolver.add_solver ("jerusat", jerusat)
   504 end;
   505 
   506 (* ------------------------------------------------------------------------- *)
   507 (* Add code for other SAT solvers below.                                     *)
   508 (* ------------------------------------------------------------------------- *)
   509 
   510 (*
   511 let
   512 	fun mysolver fm = ...
   513 in
   514 	SatSolver.add_solver ("myname", (fn fm => if mysolver_is_configured then mysolver fm else raise SatSolver.NOT_CONFIGURED));  -- register the solver
   515 end;
   516 
   517 -- the solver is now available as SatSolver.invoke_solver "myname"
   518 *)