mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 03:05:31 -05:00
wip: check models
This commit is contained in:
parent
173908cadc
commit
7f5c6d4131
3 changed files with 13 additions and 7 deletions
|
|
@ -26,6 +26,8 @@ class type t =
|
||||||
method lit_of_term : ?sign:bool -> Term.t -> Lit.t
|
method lit_of_term : ?sign:bool -> Term.t -> Lit.t
|
||||||
(** Convert a term into a simplified literal. *)
|
(** Convert a term into a simplified literal. *)
|
||||||
|
|
||||||
|
method tst : Term.store
|
||||||
|
|
||||||
method solve :
|
method solve :
|
||||||
?on_exit:(unit -> unit) list ->
|
?on_exit:(unit -> unit) list ->
|
||||||
?on_progress:(unit -> unit) ->
|
?on_progress:(unit -> unit) ->
|
||||||
|
|
@ -52,6 +54,7 @@ class type t =
|
||||||
(** TODO: remove, use Tracer instead *)
|
(** TODO: remove, use Tracer instead *)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let tst (self : #t) : Term.store = self#tst
|
||||||
let assert_term (self : #t) t : unit = self#assert_term t
|
let assert_term (self : #t) t : unit = self#assert_term t
|
||||||
let assert_clause (self : #t) c p : unit = self#assert_clause c p
|
let assert_clause (self : #t) c p : unit = self#assert_clause c p
|
||||||
let assert_clause_l (self : #t) c p : unit = self#assert_clause_l c p
|
let assert_clause_l (self : #t) c p : unit = self#assert_clause_l c p
|
||||||
|
|
|
||||||
|
|
@ -263,6 +263,7 @@ let solve ?(on_exit = []) ?(on_progress = fun _ -> ())
|
||||||
|
|
||||||
let as_asolver (self : t) : Sidekick_abstract_solver.Asolver.t =
|
let as_asolver (self : t) : Sidekick_abstract_solver.Asolver.t =
|
||||||
object
|
object
|
||||||
|
method tst = SI.tst self.si
|
||||||
method assert_term t : unit = assert_term self t
|
method assert_term t : unit = assert_term self t
|
||||||
method assert_clause c p : unit = add_clause self c p
|
method assert_clause c p : unit = add_clause self c p
|
||||||
method assert_clause_l c p : unit = add_clause_l self c p
|
method assert_clause_l c p : unit = add_clause_l self c p
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ type t = {
|
||||||
progress: Progress_bar.t option;
|
progress: Progress_bar.t option;
|
||||||
solver: Asolver.t;
|
solver: Asolver.t;
|
||||||
build_model: Build_model.t;
|
build_model: Build_model.t;
|
||||||
|
asserts: Term.t Vec.t;
|
||||||
time_start: float;
|
time_start: float;
|
||||||
time_limit: float;
|
time_limit: float;
|
||||||
memory_limit: float;
|
memory_limit: float;
|
||||||
|
|
@ -42,6 +43,7 @@ let create ?(pp_cnf = false) ?proof_file ?(pp_model = false) ?(check = false)
|
||||||
{
|
{
|
||||||
time_start;
|
time_start;
|
||||||
build_model = Build_model.create ();
|
build_model = Build_model.create ();
|
||||||
|
asserts = Vec.create ();
|
||||||
progress;
|
progress;
|
||||||
solver;
|
solver;
|
||||||
proof_file;
|
proof_file;
|
||||||
|
|
@ -67,6 +69,8 @@ let decl_fun (self : t) f args ret const : unit =
|
||||||
let build_model (self : t) (sat : Solver.sat_result) : Model.t =
|
let build_model (self : t) (sat : Solver.sat_result) : Model.t =
|
||||||
Build_model.build self.build_model sat
|
Build_model.build self.build_model sat
|
||||||
|
|
||||||
|
let check_model (self : t) (m : Model.t) : unit = assert false
|
||||||
|
|
||||||
(* call the solver to check satisfiability *)
|
(* call the solver to check satisfiability *)
|
||||||
let solve (self : t) ~assumptions () : Solver.res =
|
let solve (self : t) ~assumptions () : Solver.res =
|
||||||
let t1 = now () in
|
let t1 = now () in
|
||||||
|
|
@ -96,15 +100,9 @@ let solve (self : t) ~assumptions () : Solver.res =
|
||||||
| Asolver.Check_res.Sat sat ->
|
| Asolver.Check_res.Sat sat ->
|
||||||
if self.pp_model then (
|
if self.pp_model then (
|
||||||
let m = build_model self sat in
|
let m = build_model self sat in
|
||||||
(* TODO: use actual {!Model} in the solver? or build it afterwards *)
|
if self.check then check_model self m;
|
||||||
Fmt.printf "%a@." Model.pp m
|
Fmt.printf "%a@." Model.pp m
|
||||||
);
|
);
|
||||||
(* TODO
|
|
||||||
if check then (
|
|
||||||
Solver.check_model s;
|
|
||||||
CCOpt.iter (fun h -> check_smt_model (Solver.solver s) h m) hyps;
|
|
||||||
);
|
|
||||||
*)
|
|
||||||
let t3 = now () in
|
let t3 = now () in
|
||||||
Fmt.printf "sat@.";
|
Fmt.printf "sat@.";
|
||||||
Fmt.printf "; (%.3f/%.3f/%.3f)@." (t1 -. time_start) (t2 -. t1) (t3 -. t2)
|
Fmt.printf "; (%.3f/%.3f/%.3f)@." (t1 -. time_start) (t2 -. t1) (t3 -. t2)
|
||||||
|
|
@ -184,6 +182,7 @@ let process_stmt (self : t) (stmt : Statement.t) : unit or_error =
|
||||||
E.return ()
|
E.return ()
|
||||||
| Statement.Stmt_assert t ->
|
| Statement.Stmt_assert t ->
|
||||||
if self.pp_cnf then Format.printf "(@[<hv1>assert@ %a@])@." Term.pp t;
|
if self.pp_cnf then Format.printf "(@[<hv1>assert@ %a@])@." Term.pp t;
|
||||||
|
if self.check then Vec.push self.asserts t;
|
||||||
let lit = Asolver.lit_of_term self.solver t in
|
let lit = Asolver.lit_of_term self.solver t in
|
||||||
Asolver.assert_clause self.solver [| lit |] (fun () ->
|
Asolver.assert_clause self.solver [| lit |] (fun () ->
|
||||||
Proof.Sat_rules.sat_input_clause [ lit ]);
|
Proof.Sat_rules.sat_input_clause [ lit ]);
|
||||||
|
|
@ -192,6 +191,8 @@ let process_stmt (self : t) (stmt : Statement.t) : unit or_error =
|
||||||
if self.pp_cnf then
|
if self.pp_cnf then
|
||||||
Format.printf "(@[<hv1>assert-clause@ %a@])@." (Util.pp_list Term.pp) c_ts;
|
Format.printf "(@[<hv1>assert-clause@ %a@])@." (Util.pp_list Term.pp) c_ts;
|
||||||
|
|
||||||
|
if self.check then
|
||||||
|
Vec.push self.asserts (Form.or_l (Asolver.tst self.solver) c_ts);
|
||||||
let c = CCList.map (fun t -> Asolver.lit_of_term self.solver t) c_ts in
|
let c = CCList.map (fun t -> Asolver.lit_of_term self.solver t) c_ts in
|
||||||
|
|
||||||
(* proof of assert-input + preprocessing *)
|
(* proof of assert-input + preprocessing *)
|
||||||
|
|
@ -206,6 +207,7 @@ let process_stmt (self : t) (stmt : Statement.t) : unit or_error =
|
||||||
(match Asolver.last_res self.solver with
|
(match Asolver.last_res self.solver with
|
||||||
| Some (Solver.Sat sat) ->
|
| Some (Solver.Sat sat) ->
|
||||||
let m = build_model self sat in
|
let m = build_model self sat in
|
||||||
|
if self.check then check_model self m;
|
||||||
Fmt.printf "%a@." Model.pp m
|
Fmt.printf "%a@." Model.pp m
|
||||||
| _ -> Error.errorf "cannot access model");
|
| _ -> Error.errorf "cannot access model");
|
||||||
E.return ()
|
E.return ()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue