[breaking] Changed if_sat interface

In Plugin, and Theory, if_sat function now has the same type as assume
Additionally, some insertions into the heap have been moved to avoid
some unnecessary operations.
This commit is contained in:
Guillaume Bury 2016-11-16 17:33:10 +01:00
parent 3af700bbd0
commit b4d62d6f3b
9 changed files with 57 additions and 38 deletions

View file

@ -84,12 +84,13 @@ module Make
let mk_unsat () : (_,_) unsat_state = let mk_unsat () : (_,_) unsat_state =
pp_all 99; pp_all 99;
let unsat_conflict () = match S.unsat_conflict () with let unsat_conflict () =
match S.unsat_conflict () with
| None -> assert false | None -> assert false
| Some c -> c | Some c -> c
in in
let get_proof () = let get_proof () =
let c = unsat_conflict() in let c = unsat_conflict () in
S.Proof.prove_unsat c S.Proof.prove_unsat c
in in
{ unsat_conflict; get_proof; } { unsat_conflict; get_proof; }

View file

@ -224,7 +224,7 @@ module Make
| E_lit l -> Iheap.insert f_weight env.order l.lid | E_lit l -> Iheap.insert f_weight env.order l.lid
| E_var v -> | E_var v ->
Iheap.insert f_weight env.order v.vid; Iheap.insert f_weight env.order v.vid;
iter_sub (fun t -> insert_var_order (E_lit t)) v iter_sub (fun t -> insert_var_order (elt_of_lit t)) v
(* Rather than iterate over all the heap when we want to decrease all the (* Rather than iterate over all the heap when we want to decrease all the
variables/literals activity, we instead increase the value by which variables/literals activity, we instead increase the value by which
@ -358,23 +358,15 @@ module Make
A clause is attached (to its watching lits) when it is first added, A clause is attached (to its watching lits) when it is first added,
either because it is assumed or learnt. either because it is assumed or learnt.
A clause is detached once it dies (because of pop())
*) *)
let attach_clause c = let attach_clause c =
if not c.attached then begin assert (not c.attached);
Log.debugf 60 "Attaching %a" (fun k -> k St.pp_clause c); Log.debugf 60 "Attaching %a" (fun k -> k St.pp_clause c);
c.attached <- true; Array.iter (fun x -> insert_var_order (elt_of_var x.var)) c.atoms;
Vec.push c.atoms.(0).neg.watched c; Vec.push c.atoms.(0).neg.watched c;
Vec.push c.atoms.(1).neg.watched c; Vec.push c.atoms.(1).neg.watched c;
end c.attached <- true;
()
let detach_clause c =
if c.attached then begin
c.attached <- false;
Log.debugf 10 "Removing clause @[%a@]" (fun k->k St.pp_clause c);
Vec.remove c.atoms.(0).neg.watched c;
Vec.remove c.atoms.(1).neg.watched c;
end
(* Is a clause satisfied ? *) (* Is a clause satisfied ? *)
let satisfied c = Array_util.exists (fun atom -> atom.is_true) c.atoms let satisfied c = Array_util.exists (fun atom -> atom.is_true) c.atoms
@ -825,7 +817,6 @@ module Make
let nbv = St.nb_elt () in let nbv = St.nb_elt () in
let nbc = env.nb_init_clauses + Stack.length env.clauses_to_add in let nbc = env.nb_init_clauses + Stack.length env.clauses_to_add in
Iheap.grow_to_by_double env.order nbv; Iheap.grow_to_by_double env.order nbv;
St.iter_elt insert_var_order;
Vec.grow_to_by_double env.clauses_hyps nbc; Vec.grow_to_by_double env.clauses_hyps nbc;
Vec.grow_to_by_double env.clauses_learnt nbc; Vec.grow_to_by_double env.clauses_learnt nbc;
env.nb_init_clauses <- nbc; env.nb_init_clauses <- nbc;
@ -1128,13 +1119,14 @@ module Make
n_of_learnts := !n_of_learnts *. env.learntsize_inc n_of_learnts := !n_of_learnts *. env.learntsize_inc
| Sat -> | Sat ->
assert (env.elt_head = Vec.size env.elt_queue); assert (env.elt_head = Vec.size env.elt_queue);
Plugin.if_sat (full_slice ()); begin match Plugin.if_sat (full_slice ()) with
flush_clauses(); | Plugin_intf.Sat -> ()
if is_unsat () then raise Unsat | Plugin_intf.Unsat (l, p) ->
else if env.elt_head = Vec.size env.elt_queue (* sanity check *) let atoms = List.rev_map new_atom l in
&& env.elt_head = St.nb_elt () let c = make_clause (fresh_tname ()) atoms (Lemma p) in
(* this is the important test to know if the search is finished *) Stack.push c env.clauses_to_add
then raise Sat end;
if Stack.is_empty env.clauses_to_add then raise Sat
end end
done done
with Sat -> () with Sat -> ()
@ -1206,6 +1198,26 @@ module Make
List.iter aux l List.iter aux l
| Some _ -> () | Some _ -> ()
(* Check satisfiability *)
let check_clause c =
Array_util.exists (fun a -> a.is_true) c.atoms
let check_vec v =
Vec.for_all check_clause v
let check_stack s =
try
Stack.iter (fun c -> if not (check_clause c) then raise Exit) s;
true
with Exit ->
false
let check () =
Stack.is_empty env.clauses_to_add &&
check_stack env.clauses_root &&
check_vec env.clauses_hyps &&
check_vec env.clauses_learnt &&
check_vec env.clauses_temp
(* Unsafe access to internal data *) (* Unsafe access to internal data *)

View file

@ -61,6 +61,9 @@ module Make
val model : unit -> (St.term * St.term) list val model : unit -> (St.term * St.term) list
(** Returns the model found if the formula is satisfiable. *) (** Returns the model found if the formula is satisfiable. *)
val check : unit -> bool
(** Check the satisfiability of the current model. Only has meaning
if the solver finished proof search and has returned [Sat]. *)
(** {2 Internal data} (** {2 Internal data}
These functions expose some internal data stored by the solver, as such These functions expose some internal data stored by the solver, as such

View file

@ -71,14 +71,15 @@ module type S = sig
(** Assume the formulas in the slice, possibly pushing new formulas to be propagated, (** Assume the formulas in the slice, possibly pushing new formulas to be propagated,
and returns the result of the new assumptions. *) and returns the result of the new assumptions. *)
val if_sat : (term, formula, proof) slice -> (formula, proof) res
(** Called at the end of the search in case a model has been found. If no new clause is
pushed and the function returns [Sat], then proof search ends and 'sat' is returned,
else search is resumed. *)
val backtrack : level -> unit val backtrack : level -> unit
(** Backtrack to the given level. After a call to [backtrack l], the theory should be in the (** Backtrack to the given level. After a call to [backtrack l], the theory should be in the
same state as when it returned the value [l], *) same state as when it returned the value [l], *)
val if_sat : (term, formula, proof) slice -> unit
(** Called at the end of the search in case a model has been found. If no new clause is
pushed, then 'sat' is returned, else search is resumed. *)
val assign : term -> term val assign : term -> term
(** Returns an assignment value for the given term. *) (** Returns an assignment value for the given term. *)

View file

@ -53,13 +53,13 @@ module type S = sig
(** Assume the formulas in the slice, possibly pushing new formulas to be propagated, (** Assume the formulas in the slice, possibly pushing new formulas to be propagated,
and returns the result of the new assumptions. *) and returns the result of the new assumptions. *)
val if_sat : (formula, proof) slice -> (formula, proof) res
(** Called at the end of the search in case a model has been found. If no new clause is
pushed, then 'sat' is returned, else search is resumed. *)
val backtrack : level -> unit val backtrack : level -> unit
(** Backtrack to the given level. After a call to [backtrack l], the theory should be in the (** Backtrack to the given level. After a call to [backtrack l], the theory should be in the
same state as when it returned the value [l], *) same state as when it returned the value [l], *)
val if_sat : (formula, proof) slice -> unit
(** Called at the end of the search in case a model has been found. If no new clause is
pushed, then 'sat' is returned, else search is resumed. *)
end end

View file

@ -90,7 +90,8 @@ module Tsmt = struct
Plugin_intf.Unknown Plugin_intf.Unknown
end end
let if_sat _ = () let if_sat _ =
Plugin_intf.Sat
end end

View file

@ -46,9 +46,9 @@ module Tsmt = struct
Log.debug 8 "Making explanation clause..."; Log.debug 8 "Making explanation clause...";
Unsat (to_clause x, ()) Unsat (to_clause x, ())
let backtrack l = env := l let if_sat _ = Theory_intf.Sat
let if_sat _ = () let backtrack l = env := l
end end

View file

@ -287,3 +287,4 @@ let () =
| Out_of_space -> | Out_of_space ->
print "Spaceout"; print "Spaceout";
exit 3 exit 3

View file

@ -24,7 +24,7 @@ module DummyTheory(F : Formula_intf.S) = struct
let current_level () = () let current_level () = ()
let assume _ = Theory_intf.Sat let assume _ = Theory_intf.Sat
let backtrack _ = () let backtrack _ = ()
let if_sat _ = () let if_sat _ = Theory_intf.Sat
end end
module Plugin(E : Formula_intf.S) module Plugin(E : Formula_intf.S)