mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-10 05:03:59 -05:00
Added propagation function in slice
This commit is contained in:
parent
4b25650c4d
commit
fe41b38501
3 changed files with 35 additions and 14 deletions
|
|
@ -26,6 +26,7 @@ module Tsmt = struct
|
||||||
length : int;
|
length : int;
|
||||||
get : int -> assumption * int;
|
get : int -> assumption * int;
|
||||||
push : formula list -> proof -> unit;
|
push : formula list -> proof -> unit;
|
||||||
|
propagate : formula -> int -> unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
type level = {
|
type level = {
|
||||||
|
|
@ -87,6 +88,8 @@ module Tsmt = struct
|
||||||
| Fsmt.Equal(a, b)
|
| Fsmt.Equal(a, b)
|
||||||
| Fsmt.Distinct (a, b) -> f a; f b
|
| Fsmt.Distinct (a, b) -> f a; f b
|
||||||
|
|
||||||
|
let max (a: int) (b: int) = if a < b then b else a
|
||||||
|
|
||||||
let eval = function
|
let eval = function
|
||||||
| Fsmt.Prop _ -> Unknown
|
| Fsmt.Prop _ -> Unknown
|
||||||
| Fsmt.Equal (a, b) ->
|
| Fsmt.Equal (a, b) ->
|
||||||
|
|
|
||||||
|
|
@ -287,13 +287,17 @@ module Make (E : Expr_intf.S)
|
||||||
raise Unsat
|
raise Unsat
|
||||||
|
|
||||||
let enqueue_bool a lvl reason =
|
let enqueue_bool a lvl reason =
|
||||||
assert (not a.is_true && not a.neg.is_true && a.var.level < 0
|
assert (not a.neg.is_true);
|
||||||
&& a.var.tag.reason = Bcp None && lvl >= 0);
|
if a.is_true then
|
||||||
a.is_true <- true;
|
Log.debug 10 "Litteral %a alreayd in queue" pp_atom a
|
||||||
a.var.level <- lvl;
|
else begin
|
||||||
a.var.tag.reason <- reason;
|
assert (a.var.level < 0 && a.var.tag.reason = Bcp None && lvl >= 0);
|
||||||
Log.debug 8 "Enqueue: %a" pp_atom a;
|
a.is_true <- true;
|
||||||
Vec.push env.trail (Either.mk_right a)
|
a.var.level <- lvl;
|
||||||
|
a.var.tag.reason <- reason;
|
||||||
|
Log.debug 8 "Enqueue: %a" pp_atom a;
|
||||||
|
Vec.push env.trail (Either.mk_right a)
|
||||||
|
end
|
||||||
|
|
||||||
let enqueue_assign v value lvl =
|
let enqueue_assign v value lvl =
|
||||||
v.tag.assigned <- Some value;
|
v.tag.assigned <- Some value;
|
||||||
|
|
@ -331,11 +335,11 @@ module Make (E : Expr_intf.S)
|
||||||
| _ -> false
|
| _ -> false
|
||||||
in
|
in
|
||||||
try while true do
|
try while true do
|
||||||
let l, atoms = max_lvl_atoms !c in
|
let _, atoms = max_lvl_atoms !c in
|
||||||
Log.debug 15 "Current conflict clause :";
|
Log.debug 15 "Current conflict clause :";
|
||||||
List.iter (fun a -> Log.debug 15 " |- %a" St.pp_atom a) !c;
|
List.iter (fun a -> Log.debug 15 " |- %a" St.pp_atom a) !c;
|
||||||
match atoms with
|
match atoms with
|
||||||
| [] | _ :: [] ->
|
| [] | _ :: [] ->
|
||||||
Log.debug 15 "Found UIP clause";
|
Log.debug 15 "Found UIP clause";
|
||||||
is_uip := true;
|
is_uip := true;
|
||||||
raise Exit
|
raise Exit
|
||||||
|
|
@ -361,7 +365,8 @@ module Make (E : Expr_intf.S)
|
||||||
c := res
|
c := res
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
end
|
end
|
||||||
| _ -> Log.debug 15 "Decision : %a" St.pp_atom a)
|
| Bcp None -> Log.debug 15 "Decision : %a" St.pp_atom a
|
||||||
|
| Semantic _ -> Log.debug 15 "Semantic propagation : %a" St.pp_atom a)
|
||||||
done; assert false
|
done; assert false
|
||||||
with Exit ->
|
with Exit ->
|
||||||
let learnt = List.sort (fun a b -> Pervasives.compare b.var.level a.var.level) !c in
|
let learnt = List.sort (fun a b -> Pervasives.compare b.var.level a.var.level) !c in
|
||||||
|
|
@ -429,7 +434,7 @@ module Make (E : Expr_intf.S)
|
||||||
else begin
|
else begin
|
||||||
env.decisions <- env.decisions + 1;
|
env.decisions <- env.decisions + 1;
|
||||||
new_decision_level();
|
new_decision_level();
|
||||||
enqueue_bool fuip blevel (Bcp None)
|
enqueue_bool fuip.neg blevel (Bcp None)
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
var_decay_activity ();
|
var_decay_activity ();
|
||||||
|
|
@ -597,6 +602,7 @@ module Make (E : Expr_intf.S)
|
||||||
|
|
||||||
(* Propagation (boolean and theory *)
|
(* Propagation (boolean and theory *)
|
||||||
let _th_cnumber = ref 0
|
let _th_cnumber = ref 0
|
||||||
|
|
||||||
let slice_get i = Either.destruct (Vec.get env.trail i)
|
let slice_get i = Either.destruct (Vec.get env.trail i)
|
||||||
(function {level; tag={term; assigned = Some v}} -> Th.Assign (term, v), level | _ -> assert false)
|
(function {level; tag={term; assigned = Some v}} -> Th.Assign (term, v), level | _ -> assert false)
|
||||||
(fun a -> Th.Lit a.lit, a.var.level)
|
(fun a -> Th.Lit a.lit, a.var.level)
|
||||||
|
|
@ -605,14 +611,25 @@ module Make (E : Expr_intf.S)
|
||||||
decr _th_cnumber;
|
decr _th_cnumber;
|
||||||
let atoms = List.rev_map (fun x -> add_atom x) l in
|
let atoms = List.rev_map (fun x -> add_atom x) l in
|
||||||
Iheap.grow_to_by_double env.order (St.nb_vars ());
|
Iheap.grow_to_by_double env.order (St.nb_vars ());
|
||||||
List.iter (fun a -> insert_var_order (Either.mk_right a.var)) atoms;
|
List.iter (fun a ->
|
||||||
|
insert_var_order (Either.mk_right a.var);
|
||||||
|
match Th.eval a.lit with
|
||||||
|
| Th.Unknown -> ()
|
||||||
|
| Th.Valued (b, lvl) ->
|
||||||
|
let atom = if b then a else a.neg in
|
||||||
|
enqueue_bool atom lvl (Semantic lvl)
|
||||||
|
) atoms;
|
||||||
add_clause ~cnumber:!_th_cnumber atoms (Lemma lemma)
|
add_clause ~cnumber:!_th_cnumber atoms (Lemma lemma)
|
||||||
|
|
||||||
|
let slice_propagate f lvl =
|
||||||
|
enqueue_bool (add_atom f) lvl (Semantic lvl)
|
||||||
|
|
||||||
let current_slice () = Th.({
|
let current_slice () = Th.({
|
||||||
start = env.tatoms_qhead;
|
start = env.tatoms_qhead;
|
||||||
length = (Vec.size env.trail) - env.tatoms_qhead;
|
length = (Vec.size env.trail) - env.tatoms_qhead;
|
||||||
get = slice_get;
|
get = slice_get;
|
||||||
push = slice_push;
|
push = slice_push;
|
||||||
|
propagate = slice_propagate;
|
||||||
})
|
})
|
||||||
|
|
||||||
let rec theory_propagate () =
|
let rec theory_propagate () =
|
||||||
|
|
@ -732,7 +749,7 @@ module Make (E : Expr_intf.S)
|
||||||
Log.debug 5 "Deciding on %a" St.pp_semantic_var v;
|
Log.debug 5 "Deciding on %a" St.pp_semantic_var v;
|
||||||
enqueue_assign v value current_level)
|
enqueue_assign v value current_level)
|
||||||
(fun v ->
|
(fun v ->
|
||||||
if v.level>= 0 then begin
|
if v.level >= 0 then begin
|
||||||
assert (v.tag.pa.is_true || v.tag.na.is_true);
|
assert (v.tag.pa.is_true || v.tag.na.is_true);
|
||||||
pick_branch_lit ()
|
pick_branch_lit ()
|
||||||
end else match Th.eval v.tag.pa.lit with
|
end else match Th.eval v.tag.pa.lit with
|
||||||
|
|
@ -745,7 +762,7 @@ module Make (E : Expr_intf.S)
|
||||||
enqueue_bool v.tag.pa current_level (Bcp None)
|
enqueue_bool v.tag.pa current_level (Bcp None)
|
||||||
| Th.Valued (b, lvl) ->
|
| Th.Valued (b, lvl) ->
|
||||||
let a = if b then v.tag.pa else v.tag.na in
|
let a = if b then v.tag.pa else v.tag.na in
|
||||||
enqueue_bool a lvl (Bcp None))
|
enqueue_bool a lvl (Semantic lvl))
|
||||||
|
|
||||||
let search n_of_conflicts n_of_learnts =
|
let search n_of_conflicts n_of_learnts =
|
||||||
let conflictC = ref 0 in
|
let conflictC = ref 0 in
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ module type S = sig
|
||||||
length : int;
|
length : int;
|
||||||
get : int -> assumption * int;
|
get : int -> assumption * int;
|
||||||
push : formula list -> proof -> unit;
|
push : formula list -> proof -> unit;
|
||||||
|
propagate : formula -> int -> unit;
|
||||||
}
|
}
|
||||||
(** The type for a slice of litterals to assume/propagate in the theory.
|
(** The type for a slice of litterals to assume/propagate in the theory.
|
||||||
[get] operations should only be used for integers [ start <= i < start + length].
|
[get] operations should only be used for integers [ start <= i < start + length].
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue