author | wenzelm |
Mon, 11 Sep 2023 19:30:48 +0200 | |
changeset 78659 | b5f3d1051b13 |
parent 76501 | 7956b822f239 |
permissions | -rw-r--r-- |
33982 | 1 |
(* Title: HOL/Tools/Nitpick/kodkod_sat.ML |
33192 | 2 |
Author: Jasmin Blanchette, TU Muenchen |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
33982
diff
changeset
|
3 |
Copyright 2009, 2010 |
33192 | 4 |
|
5 |
Kodkod SAT solver integration. |
|
6 |
*) |
|
7 |
||
8 |
signature KODKOD_SAT = |
|
9 |
sig |
|
10 |
val configured_sat_solvers : bool -> string list |
|
11 |
val smart_sat_solver_name : bool -> string |
|
76501 | 12 |
val sat_solver_spec : Time.time -> string -> string * string list |
33192 | 13 |
end; |
14 |
||
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33229
diff
changeset
|
15 |
structure Kodkod_SAT : KODKOD_SAT = |
33192 | 16 |
struct |
17 |
||
34998 | 18 |
open Kodkod |
19 |
||
33192 | 20 |
datatype sink = ToStdout | ToFile |
74640
85d8d9eeb4e1
discontinued pointless check of kodkodi_version, it is implicit in the bundled component;
wenzelm
parents:
74489
diff
changeset
|
21 |
datatype availability = Java | JNI |
33229
fba7527c3ef1
made Nitpick aware of the KODKODI_JAVA_LIBRARY_PATH, for detecting and properly invoking JNI-based SAT solvers
blanchet
parents:
33192
diff
changeset
|
22 |
datatype mode = Batch | Incremental |
33192 | 23 |
|
24 |
datatype sat_solver_info = |
|
33229
fba7527c3ef1
made Nitpick aware of the KODKODI_JAVA_LIBRARY_PATH, for detecting and properly invoking JNI-based SAT solvers
blanchet
parents:
33192
diff
changeset
|
25 |
Internal of availability * mode * string list | |
45077
3cb902212af5
update list of SAT solvers reflecting Kodkod 1.5
blanchet
parents:
39221
diff
changeset
|
26 |
External of string * string * string list | |
76501 | 27 |
ExternalV2 of sink * string * string * string * string * string * (Time.time -> string list) |
28 |
||
29 |
fun to_secs min time = Int.max (min, (Time.toMilliseconds time + 999) div 1000) |
|
33192 | 30 |
|
56853 | 31 |
(* for compatibility with "SAT_Solver" *) |
33192 | 32 |
val berkmin_exec = getenv "BERKMIN_EXE" |
33 |
||
34 |
val static_list = |
|
75665
707748d3d186
prefer non-JNI SAT solvers by default in Nitpick
blanchet
parents:
74640
diff
changeset
|
35 |
[("CryptoMiniSat", External ("CRYPTOMINISAT_HOME", "cryptominisat", [])), |
76501 | 36 |
("MiniSat", ExternalV2 (ToFile, "MINISAT_HOME", "minisat", "SAT", "", "UNSAT", |
37 |
fn timeout => ["-cpu-lim=" ^ string_of_int (to_secs 1 timeout)])), |
|
38 |
("zChaff", ExternalV2 (ToStdout, "ZCHAFF_HOME", "zchaff", |
|
39 |
"Instance Satisfiable", "", "Instance Unsatisfiable", K [])), |
|
40 |
("RSat", ExternalV2 (ToStdout, "RSAT_HOME", "rsat", |
|
41 |
"s SATISFIABLE", "v ", "s UNSATISFIABLE", K ["-s"])), |
|
54608 | 42 |
("Riss3g", External ("RISS3G_HOME", "riss3g", [])), |
33192 | 43 |
("BerkMin", ExternalV2 (ToStdout, "BERKMIN_HOME", |
76501 | 44 |
if berkmin_exec = "" then "BerkMin561" else berkmin_exec, "Satisfiable !!", |
45 |
"solution =", "UNSATISFIABLE !!", K [])), |
|
45077
3cb902212af5
update list of SAT solvers reflecting Kodkod 1.5
blanchet
parents:
39221
diff
changeset
|
46 |
("BerkMin_Alloy", External ("BERKMINALLOY_HOME", "berkmin", [])), |
33229
fba7527c3ef1
made Nitpick aware of the KODKODI_JAVA_LIBRARY_PATH, for detecting and properly invoking JNI-based SAT solvers
blanchet
parents:
33192
diff
changeset
|
47 |
("SAT4J", Internal (Java, Incremental, ["DefaultSAT4J"])), |
75665
707748d3d186
prefer non-JNI SAT solvers by default in Nitpick
blanchet
parents:
74640
diff
changeset
|
48 |
("SAT4J_Light", Internal (Java, Incremental, ["LightSAT4J"])), |
707748d3d186
prefer non-JNI SAT solvers by default in Nitpick
blanchet
parents:
74640
diff
changeset
|
49 |
("Lingeling_JNI", Internal (JNI, Batch, ["Lingeling"])), |
707748d3d186
prefer non-JNI SAT solvers by default in Nitpick
blanchet
parents:
74640
diff
changeset
|
50 |
("CryptoMiniSat_JNI", Internal (JNI, Batch, ["CryptoMiniSat"])), |
707748d3d186
prefer non-JNI SAT solvers by default in Nitpick
blanchet
parents:
74640
diff
changeset
|
51 |
("MiniSat_JNI", Internal (JNI, Incremental, ["MiniSat"]))] |
33192 | 52 |
|
35177 | 53 |
fun dynamic_entry_for_external name dev home exec args markers = |
74479 | 54 |
let |
74481
9333a6ee57ba
proper platform_path for executables run from Java;
wenzelm
parents:
74479
diff
changeset
|
55 |
fun make_args () = |
74486
74a36aae067a
updated to kodkodi-1.5.7. with more robust/portable management of files and processes;
wenzelm
parents:
74481
diff
changeset
|
56 |
let val inpath = name ^ serial_string () ^ ".cnf" in |
74a36aae067a
updated to kodkodi-1.5.7. with more robust/portable management of files and processes;
wenzelm
parents:
74481
diff
changeset
|
57 |
[if null markers then "External" else "ExternalV2"] @ |
74a36aae067a
updated to kodkodi-1.5.7. with more robust/portable management of files and processes;
wenzelm
parents:
74481
diff
changeset
|
58 |
[File.platform_path (Path.variable home + Path.platform_exe (Path.basic exec))] @ |
74a36aae067a
updated to kodkodi-1.5.7. with more robust/portable management of files and processes;
wenzelm
parents:
74481
diff
changeset
|
59 |
[inpath] @ (if null markers then [] else [if dev = ToFile then "out" else ""]) @ |
74a36aae067a
updated to kodkodi-1.5.7. with more robust/portable management of files and processes;
wenzelm
parents:
74481
diff
changeset
|
60 |
markers @ args |
74479 | 61 |
end |
74481
9333a6ee57ba
proper platform_path for executables run from Java;
wenzelm
parents:
74479
diff
changeset
|
62 |
in if getenv home = "" then NONE else SOME (name, make_args) end |
55889 | 63 |
|
76501 | 64 |
fun dynamic_entry_for_info _ incremental (name, Internal (Java, mode, ss)) = |
33229
fba7527c3ef1
made Nitpick aware of the KODKODI_JAVA_LIBRARY_PATH, for detecting and properly invoking JNI-based SAT solvers
blanchet
parents:
33192
diff
changeset
|
65 |
if incremental andalso mode = Batch then NONE else SOME (name, K ss) |
76501 | 66 |
| dynamic_entry_for_info _ incremental (name, Internal (JNI, mode, ss)) = |
74640
85d8d9eeb4e1
discontinued pointless check of kodkodi_version, it is implicit in the bundled component;
wenzelm
parents:
74489
diff
changeset
|
67 |
if incremental andalso mode = Batch then NONE |
74489 | 68 |
else if exists File.is_dir (Path.split (getenv "KODKODI_JAVA_LIBRARY_PATH")) |
69 |
then SOME (name, K ss) else NONE |
|
76501 | 70 |
| dynamic_entry_for_info _ false (name, External (home, exec, args)) = |
45077
3cb902212af5
update list of SAT solvers reflecting Kodkod 1.5
blanchet
parents:
39221
diff
changeset
|
71 |
dynamic_entry_for_external name ToStdout home exec args [] |
76501 | 72 |
| dynamic_entry_for_info timeout false (name, ExternalV2 (dev, home, exec, m1, m2, m3, args)) = |
73 |
dynamic_entry_for_external name dev home exec (args timeout) [m1, m2, m3] |
|
74 |
| dynamic_entry_for_info _ true _ = NONE |
|
55889 | 75 |
|
76501 | 76 |
fun dynamic_list timeout incremental = |
77 |
map_filter (dynamic_entry_for_info timeout incremental) static_list |
|
33192 | 78 |
|
76501 | 79 |
val configured_sat_solvers = map fst o dynamic_list Time.zeroTime |
80 |
val smart_sat_solver_name = fst o hd o dynamic_list Time.zeroTime |
|
33192 | 81 |
|
76501 | 82 |
fun sat_solver_spec timeout name = |
34998 | 83 |
let |
76501 | 84 |
val dyns = dynamic_list timeout false |
34998 | 85 |
fun enum_solvers solvers = |
86 |
commas (distinct (op =) (map (quote o fst) solvers)) |
|
87 |
in |
|
50489 | 88 |
(name, the (AList.lookup (op =) dyns name) ()) |
33192 | 89 |
handle Option.Option => |
90 |
error (if AList.defined (op =) static_list name then |
|
91 |
"The SAT solver " ^ quote name ^ " is not configured. The \ |
|
92 |
\following solvers are configured:\n" ^ |
|
63693
5b02f7757a4c
removed trailing final stops in Nitpick messages
blanchet
parents:
56853
diff
changeset
|
93 |
enum_solvers dyns |
33192 | 94 |
else |
63693
5b02f7757a4c
removed trailing final stops in Nitpick messages
blanchet
parents:
56853
diff
changeset
|
95 |
"Unknown SAT solver " ^ quote name ^ "\nThe following \ |
5b02f7757a4c
removed trailing final stops in Nitpick messages
blanchet
parents:
56853
diff
changeset
|
96 |
\solvers are supported:\n" ^ enum_solvers static_list) |
33192 | 97 |
end |
98 |
||
99 |
end; |