mirror of
https://github.com/c-cube/sidekick.git
synced 2026-01-29 04:44:52 -05:00
refactor: change backtracking API (push/pop_levels)
This commit is contained in:
parent
f26f74e119
commit
ced266663e
2 changed files with 22 additions and 30 deletions
|
|
@ -736,8 +736,6 @@ module Make(Plugin : PLUGIN)
|
||||||
|
|
||||||
elt_levels : int Vec.t;
|
elt_levels : int Vec.t;
|
||||||
(* decision levels in [trail] *)
|
(* decision levels in [trail] *)
|
||||||
th_levels : Plugin.level Vec.t;
|
|
||||||
(* theory states corresponding to elt_levels *)
|
|
||||||
|
|
||||||
mutable assumptions: atom Vec.t;
|
mutable assumptions: atom Vec.t;
|
||||||
(* current assumptions *)
|
(* current assumptions *)
|
||||||
|
|
@ -796,7 +794,6 @@ module Make(Plugin : PLUGIN)
|
||||||
|
|
||||||
trail = Vec.create ();
|
trail = Vec.create ();
|
||||||
elt_levels = Vec.create();
|
elt_levels = Vec.create();
|
||||||
th_levels = Vec.create();
|
|
||||||
assumptions= Vec.create();
|
assumptions= Vec.create();
|
||||||
|
|
||||||
order = H.create();
|
order = H.create();
|
||||||
|
|
@ -1040,7 +1037,7 @@ module Make(Plugin : PLUGIN)
|
||||||
assert (st.th_head = Vec.size st.trail);
|
assert (st.th_head = Vec.size st.trail);
|
||||||
assert (st.elt_head = Vec.size st.trail);
|
assert (st.elt_head = Vec.size st.trail);
|
||||||
Vec.push st.elt_levels (Vec.size st.trail);
|
Vec.push st.elt_levels (Vec.size st.trail);
|
||||||
Vec.push st.th_levels (Plugin.current_level st.th); (* save the current theory state *)
|
Plugin.push_level st.th;
|
||||||
()
|
()
|
||||||
|
|
||||||
(* Attach/Detach a clause.
|
(* Attach/Detach a clause.
|
||||||
|
|
@ -1108,13 +1105,13 @@ module Make(Plugin : PLUGIN)
|
||||||
)
|
)
|
||||||
done;
|
done;
|
||||||
(* Recover the right theory state. *)
|
(* Recover the right theory state. *)
|
||||||
Plugin.backtrack st.th (Vec.get st.th_levels lvl);
|
let n = decision_level st - lvl in
|
||||||
|
assert (n>0);
|
||||||
|
Plugin.pop_levels st.th n;
|
||||||
(* Resize the vectors according to their new size. *)
|
(* Resize the vectors according to their new size. *)
|
||||||
Vec.shrink st.trail !head;
|
Vec.shrink st.trail !head;
|
||||||
Vec.shrink st.elt_levels lvl;
|
Vec.shrink st.elt_levels lvl;
|
||||||
Vec.shrink st.th_levels lvl;
|
|
||||||
);
|
);
|
||||||
assert (Vec.size st.elt_levels = Vec.size st.th_levels);
|
|
||||||
()
|
()
|
||||||
|
|
||||||
let pp_unsat_cause out = function
|
let pp_unsat_cause out = function
|
||||||
|
|
@ -1974,6 +1971,8 @@ module Make(Plugin : PLUGIN)
|
||||||
check_vec st.clauses_hyps &&
|
check_vec st.clauses_hyps &&
|
||||||
check_vec st.clauses_learnt
|
check_vec st.clauses_learnt
|
||||||
|
|
||||||
|
let[@inline] theory st = st.th
|
||||||
|
|
||||||
(* Unsafe access to internal data *)
|
(* Unsafe access to internal data *)
|
||||||
|
|
||||||
let hyps env = env.clauses_hyps
|
let hyps env = env.clauses_hyps
|
||||||
|
|
@ -2112,11 +2111,10 @@ module Make_pure_sat(F: Solver_intf.FORMULA) =
|
||||||
end
|
end
|
||||||
type t = unit
|
type t = unit
|
||||||
type proof = Solver_intf.void
|
type proof = Solver_intf.void
|
||||||
type level = unit
|
let push_level () = ()
|
||||||
let current_level () = ()
|
let pop_levels _ _ = ()
|
||||||
let assume () _ = ()
|
let assume () _ = ()
|
||||||
let if_sat () _ = ()
|
let if_sat () _ = ()
|
||||||
let backtrack () _ = ()
|
|
||||||
let eval () _ = Solver_intf.Unknown
|
let eval () _ = Solver_intf.Unknown
|
||||||
let assign () t = t
|
let assign () t = t
|
||||||
let mcsat = false
|
let mcsat = false
|
||||||
|
|
|
||||||
|
|
@ -168,12 +168,11 @@ module type PLUGIN_CDCL_T = sig
|
||||||
|
|
||||||
type proof
|
type proof
|
||||||
|
|
||||||
type level
|
val push_level : t -> unit
|
||||||
(** The type for levels to allow backtracking. *)
|
(** Create a new backtrack level *)
|
||||||
|
|
||||||
val current_level : t -> level
|
val pop_levels : t -> int -> unit
|
||||||
(** Return the current level of the theory (either the empty/beginning state, or the
|
(** Pop [n] levels of the theory *)
|
||||||
last level returned by the [assume] function). *)
|
|
||||||
|
|
||||||
val assume : t -> (void, Formula.t, proof) slice -> unit
|
val assume : t -> (void, Formula.t, proof) slice -> unit
|
||||||
(** Assume the formulas in the slice, possibly pushing new formulas to be
|
(** Assume the formulas in the slice, possibly pushing new formulas to be
|
||||||
|
|
@ -184,10 +183,6 @@ module type PLUGIN_CDCL_T = sig
|
||||||
If no new clause is pushed, then proof search ends and 'sat' is returned;
|
If no new clause is pushed, then proof search ends and 'sat' is returned;
|
||||||
if lemmas are added, search is resumed;
|
if lemmas are added, search is resumed;
|
||||||
if a conflict clause is added, search backtracks and then resumes. *)
|
if a conflict clause is added, search backtracks and then resumes. *)
|
||||||
|
|
||||||
val backtrack : t -> level -> unit
|
|
||||||
(** 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], *)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
(** Signature for theories to be given to the Model Constructing Solver. *)
|
(** Signature for theories to be given to the Model Constructing Solver. *)
|
||||||
|
|
@ -197,12 +192,12 @@ module type PLUGIN_MCSAT = sig
|
||||||
|
|
||||||
include EXPR
|
include EXPR
|
||||||
|
|
||||||
type level
|
|
||||||
(** The type for levels to allow backtracking. *)
|
|
||||||
|
|
||||||
val current_level : t -> level
|
val push_level : t -> unit
|
||||||
(** Return the current level of the theory (either the empty/beginning state, or the
|
(** Create a new backtrack level *)
|
||||||
last level returned by the [assume] function). *)
|
|
||||||
|
val pop_levels : t -> int -> unit
|
||||||
|
(** Pop [n] levels of the theory *)
|
||||||
|
|
||||||
val assume : t -> (Term.t, Formula.t, proof) slice -> unit
|
val assume : t -> (Term.t, Formula.t, proof) slice -> unit
|
||||||
(** Assume the formulas in the slice, possibly pushing new formulas to be
|
(** Assume the formulas in the slice, possibly pushing new formulas to be
|
||||||
|
|
@ -214,10 +209,6 @@ module type PLUGIN_MCSAT = sig
|
||||||
if lemmas are added, search is resumed;
|
if lemmas are added, search is resumed;
|
||||||
if a conflict clause is added, search backtracks and then resumes. *)
|
if a conflict clause is added, search backtracks and then resumes. *)
|
||||||
|
|
||||||
val backtrack : t -> level -> unit
|
|
||||||
(** 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], *)
|
|
||||||
|
|
||||||
val assign : t -> Term.t -> Term.t
|
val assign : t -> Term.t -> Term.t
|
||||||
(** Returns an assignment value for the given term. *)
|
(** Returns an assignment value for the given term. *)
|
||||||
|
|
||||||
|
|
@ -393,6 +384,9 @@ module type S = sig
|
||||||
@param size the initial size of internal data structures. The bigger,
|
@param size the initial size of internal data structures. The bigger,
|
||||||
the faster, but also the more RAM it uses. *)
|
the faster, but also the more RAM it uses. *)
|
||||||
|
|
||||||
|
val theory : t -> theory
|
||||||
|
(** Access the theory state *)
|
||||||
|
|
||||||
(** {2 Types} *)
|
(** {2 Types} *)
|
||||||
|
|
||||||
(** Result type for the solver *)
|
(** Result type for the solver *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue