Replaced Either.destruct by explicit matching

This commit is contained in:
Guillaume Bury 2016-03-04 15:50:13 +01:00
parent ea518c6ab3
commit 0883615b99
3 changed files with 113 additions and 113 deletions

View file

@ -82,7 +82,6 @@ module Make
mutable progress_estimate : float; mutable progress_estimate : float;
(* progression estimate, updated by [search ()] *) (* progression estimate, updated by [search ()] *)
remove_satisfied : bool; remove_satisfied : bool;
(* Wether to remove satisfied learnt clauses when simplifying *) (* Wether to remove satisfied learnt clauses when simplifying *)
@ -224,12 +223,11 @@ module Make
get_elt_level (St.get_elt i) < 0 get_elt_level (St.get_elt i) < 0
(* Var/clause activity *) (* Var/clause activity *)
let insert_var_order e = destruct_elt e let insert_var_order = function
(fun v -> Iheap.insert f_weight env.order v.lid) | Either.Left l -> Iheap.insert f_weight env.order l.lid
(fun v -> | Either.Right v ->
Iheap.insert f_weight env.order v.vid; Iheap.insert f_weight env.order v.vid;
iter_sub (fun t -> Iheap.insert f_weight env.order t.lid) v iter_sub (fun t -> Iheap.insert f_weight env.order t.lid) v
)
let var_decay_activity () = let var_decay_activity () =
env.var_incr <- env.var_incr *. env.var_decay env.var_incr <- env.var_incr *. env.var_decay
@ -382,13 +380,12 @@ module Make
env.elt_head <- Vec.get env.elt_levels lvl; env.elt_head <- Vec.get env.elt_levels lvl;
env.th_head <- env.elt_head; env.th_head <- env.elt_head;
for c = env.elt_head to Vec.size env.elt_queue - 1 do for c = env.elt_head to Vec.size env.elt_queue - 1 do
destruct (Vec.get env.elt_queue c) match (Vec.get env.elt_queue c) with
(fun l -> | Either.Left l ->
l.assigned <- None; l.assigned <- None;
l.l_level <- -1; l.l_level <- -1;
insert_var_order (elt_of_lit l) insert_var_order (elt_of_lit l)
) | Either.Right a ->
(fun a ->
if a.var.v_level <= lvl then begin if a.var.v_level <= lvl then begin
Vec.set env.elt_queue env.elt_head (of_atom a); Vec.set env.elt_queue env.elt_head (of_atom a);
env.elt_head <- env.elt_head + 1 env.elt_head <- env.elt_head + 1
@ -398,7 +395,7 @@ module Make
a.var.v_level <- -1; a.var.v_level <- -1;
a.var.reason <- Bcp None; a.var.reason <- Bcp None;
insert_var_order (elt_of_var a.var) insert_var_order (elt_of_var a.var)
end) end
done; done;
Th.backtrack (Vec.get env.th_levels lvl); (* recover the right tenv *) Th.backtrack (Vec.get env.th_levels lvl); (* recover the right tenv *)
Vec.shrink env.elt_queue ((Vec.size env.elt_queue) - env.elt_head); Vec.shrink env.elt_queue ((Vec.size env.elt_queue) - env.elt_head);
@ -498,9 +495,10 @@ module Make
| _ -> | _ ->
decr tr_ind; decr tr_ind;
Log.debugf 20 "Looking at trail element %d" (fun k->k !tr_ind); Log.debugf 20 "Looking at trail element %d" (fun k->k !tr_ind);
destruct (Vec.get env.elt_queue !tr_ind) match Vec.get env.elt_queue !tr_ind with
(fun _ -> ()) (* TODO remove *) | Either.Left _ -> ()
(fun a -> match a.var.reason with | Either.Right a ->
begin match a.var.reason with
| Bcp (Some d) -> | Bcp (Some d) ->
let tmp, res = Proof.resolve (Proof.merge !c (Proof.to_list d)) in let tmp, res = Proof.resolve (Proof.merge !c (Proof.to_list d)) in
begin match tmp with begin match tmp with
@ -515,7 +513,7 @@ module Make
end end
| Bcp None -> () | Bcp None -> ()
| Semantic _ -> () | Semantic _ -> ()
) end
done; assert false done; assert false
with Exit -> with Exit ->
let learnt = List.sort (fun a b -> Pervasives.compare b.var.v_level a.var.v_level) !c in let learnt = List.sort (fun a b -> Pervasives.compare b.var.v_level a.var.v_level) !c in
@ -523,8 +521,8 @@ module Make
blevel, learnt, List.rev !history, !is_uip, !c_level blevel, learnt, List.rev !history, !is_uip, !c_level
let get_atom i = let get_atom i =
destruct (Vec.get env.elt_queue i) match Vec.get env.elt_queue i with
(fun _ -> assert false) (fun x -> x) | Either.Left _ -> assert false | Either.Right x -> x
let analyze_sat c_clause = let analyze_sat c_clause =
let pathC = ref 0 in let pathC = ref 0 in
@ -731,9 +729,11 @@ module Make
ignore (th_eval a); ignore (th_eval a);
a a
let slice_get i = destruct (Vec.get env.elt_queue i) let slice_get i =
(function {l_level; term; assigned = Some v} -> Th.Assign (term, v), l_level | _ -> assert false) match Vec.get env.elt_queue i with
(fun a -> Th.Lit a.lit, a.var.v_level) | Either.Right a -> Th.Lit a.lit, a.var.v_level
| Either.Left {l_level; term; assigned = Some v} -> Th.Assign (term, v), l_level
| Either.Left _ -> assert false
let slice_push l lemma = let slice_push l lemma =
let atoms = List.rev_map (fun x -> new_atom x) l in let atoms = List.rev_map (fun x -> new_atom x) l in
@ -790,12 +790,13 @@ module Make
let num_props = ref 0 in let num_props = ref 0 in
let res = ref None in let res = ref None in
while env.elt_head < Vec.size env.elt_queue do while env.elt_head < Vec.size env.elt_queue do
destruct (Vec.get env.elt_queue env.elt_head) begin match Vec.get env.elt_queue env.elt_head with
(fun a -> ()) | Either.Left _ -> ()
(fun a -> | Either.Right a ->
incr num_props; incr num_props;
propagate_atom a res); propagate_atom a res
env.elt_head <- env.elt_head + 1 end;
env.elt_head <- env.elt_head + 1;
done; done;
env.propagations <- env.propagations + !num_props; env.propagations <- env.propagations + !num_props;
env.simpDB_props <- env.simpDB_props - !num_props; env.simpDB_props <- env.simpDB_props - !num_props;
@ -897,8 +898,8 @@ module Make
env.next_decision <- None; env.next_decision <- None;
pick_branch_aux atom pick_branch_aux atom
| None -> | None ->
destruct_elt (St.get_elt (Iheap.remove_min f_weight env.order)) begin match St.get_elt (Iheap.remove_min f_weight env.order) with
(fun l -> | Either.Left l ->
if l.l_level >= 0 then if l.l_level >= 0 then
pick_branch_lit () pick_branch_lit ()
else begin else begin
@ -907,8 +908,10 @@ module Make
new_decision_level(); new_decision_level();
let current_level = decision_level () in let current_level = decision_level () in
enqueue_assign l value current_level enqueue_assign l value current_level
end) end
(fun v -> pick_branch_aux v.pa) | Either.Right v ->
pick_branch_aux v.pa
end
let search n_of_conflicts n_of_learnts = let search n_of_conflicts n_of_learnts =
@ -1017,9 +1020,9 @@ module Make
let model () = let model () =
let opt = function Some a -> a | None -> assert false in let opt = function Some a -> a | None -> assert false in
Vec.fold (fun acc e -> destruct e Vec.fold (fun acc e -> match e with
(fun v -> (v.term, opt v.assigned) :: acc) | Either.Left v -> (v.term, opt v.assigned) :: acc
(fun _ -> acc) | Either.Right _ -> acc
) [] env.elt_queue ) [] env.elt_queue
(* Backtrack to decision_level 0, with trail_lim && theory env specified *) (* Backtrack to decision_level 0, with trail_lim && theory env specified *)
@ -1028,14 +1031,13 @@ module Make
env.th_head <- th_lvl; env.th_head <- th_lvl;
env.elt_head <- elt_lvl; env.elt_head <- elt_lvl;
for c = env.elt_head to Vec.size env.elt_queue - 1 do for c = env.elt_head to Vec.size env.elt_queue - 1 do
destruct (Vec.get env.elt_queue c) match Vec.get env.elt_queue c with
(fun l -> | Either.Left l ->
l.assigned <- None; l.assigned <- None;
l.l_level <- -1; l.l_level <- -1;
insert_var_order (elt_of_lit l) insert_var_order (elt_of_lit l)
) | Either.Right a ->
(fun a -> begin match a.var.reason with
match a.var.reason with
| Bcp Some { c_level } when c_level > push_lvl -> | Bcp Some { c_level } when c_level > push_lvl ->
a.is_true <- false; a.is_true <- false;
a.neg.is_true <- false; a.neg.is_true <- false;
@ -1053,7 +1055,7 @@ module Make
a.var.reason <- Bcp None; a.var.reason <- Bcp None;
insert_var_order (elt_of_var a.var) insert_var_order (elt_of_var a.var)
end end
) end
done; done;
Th.backtrack th_env; (* recover the right theory env *) Th.backtrack th_env; (* recover the right theory env *)
Vec.shrink env.elt_queue ((Vec.size env.elt_queue) - env.elt_head); Vec.shrink env.elt_queue ((Vec.size env.elt_queue) - env.elt_head);
@ -1086,7 +1088,9 @@ module Make
(if i = ul.ul_elt_lvl then "*" else " ") (if i = ul.ul_elt_lvl then "*" else " ")
(if i = ul.ul_th_lvl then "*" else " ") (if i = ul.ul_th_lvl then "*" else " ")
i (fun fmt e -> i (fun fmt e ->
destruct e (St.pp_lit fmt) (St.pp_atom fmt)) match e with
| Either.Left l -> St.pp_lit fmt l
| Either.Right a -> St.pp_atom fmt a)
(Vec.get env.elt_queue i) (Vec.get env.elt_queue i)
done done
in in

View file

@ -203,8 +203,6 @@ module McMake (E : Expr_intf.S) = struct
let elt_of_lit = Either.mk_left let elt_of_lit = Either.mk_left
let elt_of_var = Either.mk_right let elt_of_var = Either.mk_right
let destruct_elt = Either.destruct
let get_elt_id = function let get_elt_id = function
| Either.Left l -> l.lid | Either.Right v -> v.vid | Either.Left l -> l.lid | Either.Right v -> v.vid
let get_elt_level = function let get_elt_level = function

View file

@ -69,17 +69,16 @@ module type S = sig
| History of clause list | History of clause list
(** {2 Decisions and propagations} *) (** {2 Decisions and propagations} *)
type t type t = (lit, atom) Either.t
(** Either a lit of an atom *) (** Either a lit of an atom *)
val of_lit : lit -> t val of_lit : lit -> t
val of_atom : atom -> t val of_atom : atom -> t
val destruct : t -> (lit -> 'a) -> (atom -> 'a) -> 'a
(** Constructors and destructors *) (** Constructors and destructors *)
(** {2 Elements} *) (** {2 Elements} *)
type elt type elt = (lit, var) Either.t
(** Either a lit of a var *) (** Either a lit of a var *)
val nb_elt : unit -> int val nb_elt : unit -> int
@ -89,7 +88,6 @@ module type S = sig
val elt_of_lit : lit -> elt val elt_of_lit : lit -> elt
val elt_of_var : var -> elt val elt_of_var : var -> elt
val destruct_elt : elt -> (lit -> 'a) -> (var -> 'a) -> 'a
(** Constructors & destructor for elements *) (** Constructors & destructor for elements *)
val get_elt_id : elt -> int val get_elt_id : elt -> int