Check now also whecks model if sat.

Time/Memory limits now only applies to proof search (and not to model checking of proof building anymore).
This commit is contained in:
Guillaume Bury 2014-11-18 16:16:02 +01:00
parent 4ee3566aa0
commit 8e0dfc539c
4 changed files with 31 additions and 22 deletions

View file

@ -713,6 +713,7 @@ module Make (F : Formula_intf.S)
let eval lit = let eval lit =
let var, negated = make_var lit in let var, negated = make_var lit in
assert (var.pa.is_true || var.na.is_true);
let truth = var.pa.is_true in let truth = var.pa.is_true in
if negated then not truth else truth if negated then not truth else truth

View file

@ -145,6 +145,8 @@ module Make(Dummy:sig end) = struct
| None -> assert false | None -> assert false
| Some c -> SmtSolver.Proof.prove_unsat c | Some c -> SmtSolver.Proof.prove_unsat c
let eval = SmtSolver.eval
let unsat_core = SmtSolver.Proof.unsat_core let unsat_core = SmtSolver.Proof.unsat_core
let print_atom = Fsmt.print let print_atom = Fsmt.print

View file

@ -34,6 +34,9 @@ module Make(Dummy: sig end) : sig
val assume : atom list list -> unit val assume : atom list list -> unit
(** Add a list of clauses to the set of assumptions. *) (** Add a list of clauses to the set of assumptions. *)
val eval : atom -> bool
(** Returns the valuation of the given atom in the current state of the prover *)
val get_proof : unit -> proof val get_proof : unit -> proof
(** Returns the resolution proof found, if [solve] returned [Unsat]. *) (** Returns the resolution proof found, if [solve] returned [Unsat]. *)

View file

@ -3,6 +3,7 @@ module F = Smt.Fsmt
module T = Smt.Tseitin module T = Smt.Tseitin
module S = Smt.Make(struct end) module S = Smt.Make(struct end)
exception Incorrect_model
exception Out_of_time exception Out_of_time
exception Out_of_space exception Out_of_space
@ -81,13 +82,6 @@ let print_proof proof = match !output with
| Standard -> () | Standard -> ()
| Dot -> S.print_proof std proof | Dot -> S.print_proof std proof
(*
let print_assign () = match !output with
| Standard -> S.iter_atoms (fun a ->
Format.fprintf std "%a -> %s,@ " S.print_atom a (if S.eval a then "T" else "F"))
| Dot -> ()
*)
let rec print_cl fmt = function let rec print_cl fmt = function
| [] -> Format.fprintf fmt "[]" | [] -> Format.fprintf fmt "[]"
| [a] -> F.print fmt a | [a] -> F.print fmt a
@ -99,11 +93,18 @@ let print_lcl l =
let print_lclause l = let print_lclause l =
List.iter (fun c -> Format.fprintf std "%a@\n" S.print_clause c) l List.iter (fun c -> Format.fprintf std "%a@\n" S.print_clause c) l
let print_cnf cnf = match !output with
| Standard -> print_lcl cnf
| Dot -> ()
let print_unsat_core u = match !output with
| Standard -> print_lclause u
| Dot -> ()
(* Arguments parsing *) (* Arguments parsing *)
let file = ref "" let file = ref ""
let p_cnf = ref false let p_cnf = ref false
let p_assign = ref false let p_check = ref false
let p_proof_check = ref false
let p_proof_print = ref false let p_proof_print = ref false
let p_unsat_core = ref false let p_unsat_core = ref false
let time_limit = ref 300. let time_limit = ref 300.
@ -144,14 +145,12 @@ let argspec = Arg.align [
" Enable stack traces"; " Enable stack traces";
"-cnf", Arg.Set p_cnf, "-cnf", Arg.Set p_cnf,
" Prints the cnf used."; " Prints the cnf used.";
"-check", Arg.Set p_proof_check, "-check", Arg.Set p_check,
" Build, check and print the proof (if output is set), if unsat"; " Build, check and print the proof (if output is set), if unsat";
"-gc", Arg.Unit setup_gc_stat, "-gc", Arg.Unit setup_gc_stat,
" Outputs statistics about the GC"; " Outputs statistics about the GC";
"-i", Arg.String set_input, "-i", Arg.String set_input,
" Sets the input format (default auto)"; " Sets the input format (default auto)";
"-model", Arg.Set p_assign,
" Outputs the boolean model found if sat";
"-o", Arg.String set_output, "-o", Arg.String set_output,
" Sets the output format (default none)"; " Sets the output format (default none)";
"-size", Arg.String (int_arg size_limit), "-size", Arg.String (int_arg size_limit),
@ -184,33 +183,37 @@ let main () =
Arg.usage argspec usage; Arg.usage argspec usage;
exit 2 exit 2
end; end;
ignore(Gc.create_alarm check); let al = Gc.create_alarm check in
(* Interesting stuff happening *) (* Interesting stuff happening *)
let cnf = get_cnf () in let cnf = get_cnf () in
if !p_cnf then if !p_cnf then
print_lcl cnf; print_cnf cnf;
S.assume cnf; S.assume cnf;
match S.solve () with let res = S.solve () in
Gc.delete_alarm al;
match res with
| S.Sat -> | S.Sat ->
print "Sat" print "Sat";
(* if !p_check then
if !p_assign then if not (List.for_all (List.exists S.eval) cnf) then
print_assign () raise Incorrect_model
*)
| S.Unsat -> | S.Unsat ->
print "Unsat"; print "Unsat";
if !p_proof_check then begin if !p_check then begin
let p = S.get_proof () in let p = S.get_proof () in
print_proof p; print_proof p;
if !p_unsat_core then if !p_unsat_core then
print_lclause (S.unsat_core p) print_unsat_core (S.unsat_core p)
end end
let () = let () =
try try
main () main ()
with with
| Incorrect_model ->
print "Internal error : incorrect *sat* model";
exit 2
| Out_of_time -> | Out_of_time ->
print "Time limit exceeded"; print "Time limit exceeded";
exit 2 exit 2