Remember more added clauses

This commit is contained in:
Guillaume Bury 2016-07-13 16:23:34 +02:00
parent 510a8aaa34
commit 245941efdb
4 changed files with 54 additions and 46 deletions

1
_tags
View file

@ -1,5 +1,4 @@
<util/*.cmx>: for-pack(Msat) <util/*.cmx>: for-pack(Msat)
#<util/*.native>:
<smt/*.cmx>: for-pack(Msat) <smt/*.cmx>: for-pack(Msat)
<sat/*.cmx>: for-pack(Msat) <sat/*.cmx>: for-pack(Msat)
<solver/*.cmx>: for-pack(Msat) <solver/*.cmx>: for-pack(Msat)

View file

@ -351,24 +351,29 @@ module Make
(* Adding/removing clauses *) (* Adding/removing clauses *)
let attach_clause c = let attach_clause c =
Vec.push (Vec.get c.atoms 0).neg.watched c; if not c.attached then begin
Vec.push (Vec.get c.atoms 1).neg.watched c; c.attached <- true;
if c.learnt then Vec.push (Vec.get c.atoms 0).neg.watched c;
env.learnts_literals <- env.learnts_literals + Vec.size c.atoms Vec.push (Vec.get c.atoms 1).neg.watched c;
else if c.learnt then
env.clauses_literals <- env.clauses_literals + Vec.size c.atoms env.learnts_literals <- env.learnts_literals + Vec.size c.atoms
else
env.clauses_literals <- env.clauses_literals + Vec.size c.atoms
end
let detach_clause c = let detach_clause c =
Log.debugf 10 "Removing clause @[%a@]" (fun k->k St.pp_clause c); if c.attached then begin
c.removed <- true; c.attached <- false;
(* Not necessary, cleanup is done during propagation Log.debugf 10 "Removing clause @[%a@]" (fun k->k St.pp_clause c);
Vec.remove (Vec.get c.atoms 0).neg.watched c; (* Not necessary, cleanup is done during propagation
Vec.remove (Vec.get c.atoms 1).neg.watched c; Vec.remove (Vec.get c.atoms 0).neg.watched c;
*) Vec.remove (Vec.get c.atoms 1).neg.watched c;
if c.learnt then *)
env.learnts_literals <- env.learnts_literals - Vec.size c.atoms if c.learnt then
else env.learnts_literals <- env.learnts_literals - Vec.size c.atoms
env.clauses_literals <- env.clauses_literals - Vec.size c.atoms else
env.clauses_literals <- env.clauses_literals - Vec.size c.atoms
end
let remove_clause c = detach_clause c let remove_clause c = detach_clause c
@ -413,13 +418,16 @@ module Make
let simpl_reason = function let simpl_reason = function
| (Bcp cl) as r -> | (Bcp cl) as r ->
let l, history = partition (Vec.to_list cl.atoms) in Log.debugf 90 "Simplifying reason: %a" (fun k -> k St.pp_clause cl);
let atoms = Vec.to_list cl.atoms in
let l, history = partition atoms in
begin match l with begin match l with
| [ a ] -> | [ a ] ->
if history = [] then r if history = [] then r
else else begin
let tmp_cl = make_clause (fresh_tname ()) l 1 true (History (cl :: history)) in let tmp_cl = make_clause (fresh_tname ()) l 1 true (History (cl :: history)) in
Bcp tmp_cl Bcp tmp_cl
end
| _ -> assert false | _ -> assert false
end end
| r -> r | r -> r
@ -605,7 +613,7 @@ module Make
clause_bump_activity lclause; clause_bump_activity lclause;
if is_uip then if is_uip then
enqueue_bool fuip blevel (Bcp lclause) enqueue_bool fuip blevel (Bcp lclause)
else begin else begin
env.next_decision <- Some fuip.neg env.next_decision <- Some fuip.neg
end end
end; end;
@ -622,28 +630,28 @@ module Make
record_learnt_clause confl blevel learnt (History history) is_uip record_learnt_clause confl blevel learnt (History history) is_uip
(* Add a new clause *) (* Add a new clause *)
let add_clause ?(force=false) init0 = let add_clause ?(force=false) init =
Log.debugf 90 "Adding clause:@[<hov>%a@]" (fun k -> k St.pp_clause init0); Log.debugf 90 "Adding clause:@[<hov>%a@]" (fun k -> k St.pp_clause init);
let vec = match init0.cpremise with let vec = match init.cpremise with
| Lemma _ -> env.clauses_learnt | Lemma _ -> env.clauses_theory
| History [] -> env.clauses_hyps | History [] -> env.clauses_hyps
| History _ -> assert false | History _ -> assert false
in in
try try
let atoms, history = partition (Vec.to_list init0.atoms) in let atoms, history = partition (Vec.to_list init.atoms) in
let size = List.length atoms in let size = List.length atoms in
let clause =
if history = [] then init
else make_clause ?tag:init.tag (fresh_name ())
atoms size true (History (init :: history))
in
Log.debugf 4 "New clause:@ @[%a@]" (fun k->k St.pp_clause clause);
Vec.push vec clause;
match atoms with match atoms with
| [] -> | [] ->
Log.debugf 1 "New clause (unsat) :@ @[%a@]" (fun k->k St.pp_clause init0); report_unsat clause
report_unsat init0
| a::b::_ -> | a::b::_ ->
let clause =
if history = [] then init0
else make_clause ?tag:init0.tag (fresh_name ()) atoms size true (History (init0 :: history))
in
Log.debugf 4 "New clause:@ @[%a@]" (fun k->k St.pp_clause clause);
attach_clause clause; attach_clause clause;
Vec.push vec clause;
if a.neg.is_true then begin if a.neg.is_true then begin
let lvl = List.fold_left (fun m a -> max m a.var.v_level) 0 atoms in let lvl = List.fold_left (fun m a -> max m a.var.v_level) 0 atoms in
cancel_until lvl; cancel_until lvl;
@ -656,9 +664,10 @@ module Make
| [a] -> | [a] ->
Log.debugf 5 "New unit clause, propagating : %a" (fun k->k St.pp_atom a); Log.debugf 5 "New unit clause, propagating : %a" (fun k->k St.pp_atom a);
cancel_until 0; cancel_until 0;
enqueue_bool a 0 (Bcp init0) enqueue_bool a 0 (Bcp clause)
with Trivial -> with Trivial ->
Log.debugf 5 "Trivial clause ignored : @[%a@]" (fun k->k St.pp_clause init0) Vec.push vec init;
Log.debugf 5 "Trivial clause ignored : @[%a@]" (fun k->k St.pp_clause init)
let propagate_in_clause a c i watched new_sz = let propagate_in_clause a c i watched new_sz =
let atoms = c.atoms in let atoms = c.atoms in
@ -709,7 +718,7 @@ module Make
try try
for i = 0 to Vec.size watched - 1 do for i = 0 to Vec.size watched - 1 do
let c = Vec.get watched i in let c = Vec.get watched i in
if not c.removed then propagate_in_clause a c i watched new_sz_w if c.attached then propagate_in_clause a c i watched new_sz_w
done; done;
with Conflict c -> with Conflict c ->
assert (!res = None); assert (!res = None);
@ -786,10 +795,10 @@ module Make
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
begin match Vec.get env.elt_queue env.elt_head with begin match Vec.get env.elt_queue env.elt_head with
| Either.Left _ -> () | Either.Left _ -> ()
| Either.Right a -> | Either.Right a ->
incr num_props; incr num_props;
propagate_atom a res propagate_atom a res
end; end;
env.elt_head <- env.elt_head + 1; env.elt_head <- env.elt_head + 1;
done; done;
@ -958,8 +967,8 @@ module Make
add_clause c; add_clause c;
(* Clauses can be added after search has begun (and thus we are not at level 0, (* Clauses can be added after search has begun (and thus we are not at level 0,
so better not do anything at this point. so better not do anything at this point.
match propagate () with match propagate () with
| None -> () | Some confl -> report_unsat confl | None -> () | Some confl -> report_unsat confl
*) *)
in in
List.iter aux cnf List.iter aux cnf

View file

@ -62,7 +62,7 @@ module McMake (E : Expr_intf.S)(Dummy : sig end) = struct
c_level : int; c_level : int;
mutable cpremise : premise; mutable cpremise : premise;
mutable activity : float; mutable activity : float;
mutable removed : bool; mutable attached : bool;
} }
and reason = and reason =
@ -102,7 +102,7 @@ module McMake (E : Expr_intf.S)(Dummy : sig end) = struct
tag = None; tag = None;
atoms = Vec.make_empty dummy_atom; atoms = Vec.make_empty dummy_atom;
activity = -1.; activity = -1.;
removed = false; attached = false;
c_level = -1; c_level = -1;
learnt = false; learnt = false;
cpremise = History [] } cpremise = History [] }
@ -191,7 +191,7 @@ module McMake (E : Expr_intf.S)(Dummy : sig end) = struct
{ name = name; { name = name;
tag = tag; tag = tag;
atoms = atoms; atoms = atoms;
removed = false; attached = false;
learnt = is_learnt; learnt = is_learnt;
c_level = level; c_level = level;
activity = 0.; activity = 0.;

View file

@ -57,7 +57,7 @@ module type S = sig
c_level : int; c_level : int;
mutable cpremise : premise; mutable cpremise : premise;
mutable activity : float; mutable activity : float;
mutable removed : bool; mutable attached : bool;
} }
and reason = and reason =