Unify analyze code for sat and mcsat

This commit is contained in:
Guillaume Bury 2016-08-04 22:16:52 +02:00
parent 7d57b3f1b5
commit ec6ced9809

View file

@ -521,22 +521,19 @@ module Make
and a boolean stating whether it is and a boolean stating whether it is
a UIP ("Unique Implication Point") a UIP ("Unique Implication Point")
precond: the atom list is sorted by decreasing decision level *) precond: the atom list is sorted by decreasing decision level *)
let backtrack_lvl ~is_uip : atom list -> int = function let backtrack_lvl : atom list -> int * bool = function
| [] -> 0 | [] | [_] ->
| [a] -> 0, true
assert is_uip;
0
| a :: b :: r -> | a :: b :: r ->
assert(a.var.v_level > env.base_level); assert(a.var.v_level > env.base_level);
if is_uip then (
(* backtrack below [a], so we can propagate [not a] *) (* backtrack below [a], so we can propagate [not a] *)
assert(a.var.v_level > b.var.v_level); if a.var.v_level > b.var.v_level then begin
b.var.v_level b.var.v_level, true
) else ( end else begin
assert (a.var.v_level = b.var.v_level); assert (a.var.v_level = b.var.v_level);
assert (a.var.v_level >= env.base_level); assert (a.var.v_level >= env.base_level);
max (a.var.v_level - 1) env.base_level max (a.var.v_level - 1) env.base_level, false
) end
(* result of conflict analysis, containing the learnt clause and some (* result of conflict analysis, containing the learnt clause and some
additional info. additional info.
@ -556,7 +553,7 @@ module Make
atom, and perform resolution steps with each propagation reason, until atom, and perform resolution steps with each propagation reason, until
the First UIP clause is found, or we get semantic propagations the First UIP clause is found, or we get semantic propagations
at the highest level (see mcsat paper for more explications). at the highest level (see mcsat paper for more explications).
*) *) (*
let analyze_mcsat c_clause : conflict_res = let analyze_mcsat c_clause : conflict_res =
let tr_ind = ref (Vec.size env.elt_queue) in let tr_ind = ref (Vec.size env.elt_queue) in
let is_uip = ref false in let is_uip = ref false in
@ -610,6 +607,7 @@ module Make
cr_history = List.rev !history; cr_history = List.rev !history;
cr_is_uip = !is_uip; cr_is_uip = !is_uip;
} }
*)
let get_atom i = let get_atom i =
match Vec.get env.elt_queue i with match Vec.get env.elt_queue i with
@ -627,7 +625,6 @@ module Make
let seen = ref [] in let seen = ref [] in
let c = ref c_clause in let c = ref c_clause in
let tr_ind = ref (Vec.size env.elt_queue - 1) in let tr_ind = ref (Vec.size env.elt_queue - 1) in
let size = ref 1 in
let history = ref [] in let history = ref [] in
assert (decision_level () > 0); assert (decision_level () > 0);
let conflict_level = let conflict_level =
@ -658,7 +655,6 @@ module Make
incr pathC; incr pathC;
end else begin end else begin
learnt := q :: !learnt; learnt := q :: !learnt;
incr size;
blevel := max !blevel q.var.v_level blevel := max !blevel q.var.v_level
end end
end end
@ -680,6 +676,9 @@ module Make
| 0, _ -> | 0, _ ->
cond := false; cond := false;
learnt := p.neg :: (List.rev !learnt) learnt := p.neg :: (List.rev !learnt)
| n, Some Semantic _ ->
assert (n > 0);
learnt := p.neg :: !learnt
| n, Some Bcp cl -> | n, Some Bcp cl ->
assert (n > 0); assert (n > 0);
assert (p.var.v_level >= conflict_level); assert (p.var.v_level >= conflict_level);
@ -687,16 +686,21 @@ module Make
| n, _ -> assert false | n, _ -> assert false
done; done;
List.iter (fun q -> q.var.seen <- false) !seen; List.iter (fun q -> q.var.seen <- false) !seen;
{ cr_backtrack_lvl= !blevel; let l = List.fast_sort (fun p q -> compare q.var.v_level p.var.v_level) !learnt in
cr_learnt= !learnt; let level, is_uip = backtrack_lvl l in
cr_history= List.rev !history; { cr_backtrack_lvl = level;
cr_is_uip = true; cr_learnt = l;
cr_history = List.rev !history;
cr_is_uip = is_uip;
} }
let analyze c_clause : conflict_res = let analyze c_clause : conflict_res =
analyze_sat c_clause
(*
if St.mcsat if St.mcsat
then analyze_mcsat c_clause then analyze_mcsat c_clause
else analyze_sat c_clause else analyze_sat c_clause
*)
(* add the learnt clause to the clause database, propagate, etc. *) (* add the learnt clause to the clause database, propagate, etc. *)
let record_learnt_clause (confl:clause) (cr:conflict_res): unit = let record_learnt_clause (confl:clause) (cr:conflict_res): unit =