feat(sat): add counters for decision level/trail depth

This commit is contained in:
Simon Cruanes 2022-08-18 22:03:15 -04:00
parent a21389063a
commit 1c30fb1f95
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -418,6 +418,11 @@ let clause_bump_activity self (c : clause) : unit =
self.clause_incr <- self.clause_incr *. 1e-20 self.clause_incr <- self.clause_incr *. 1e-20
) )
let emit_counters_ (self : t) =
if Profile.enabled () then
Profile.count "sat"
[ "decisions", decision_level self; "trail", AVec.size self.trail ]
(* Simplification of clauses. (* Simplification of clauses.
When adding new clauses, it is desirable to 'simplify' them, i.e When adding new clauses, it is desirable to 'simplify' them, i.e
@ -644,8 +649,10 @@ let cancel_until (self : t) lvl =
let (module P) = self.plugin in let (module P) = self.plugin in
P.pop_levels n; P.pop_levels n;
Delayed_actions.clear_on_backtrack self.delayed_actions; Delayed_actions.clear_on_backtrack self.delayed_actions;
(* TODO: for scoped clause pools, backtrack them *) (* TODO: for scoped clause pools, backtrack them *)
self.next_decisions <- [] self.next_decisions <- [];
emit_counters_ self
); );
() ()
@ -1616,7 +1623,10 @@ let pick_branch_lit ~full self : bool =
true true
) )
in in
pick_lit ()
let res = pick_lit () in
emit_counters_ self;
res
(* do some amount of search, until the number of conflicts or clause learnt (* do some amount of search, until the number of conflicts or clause learnt
reaches the given parameters *) reaches the given parameters *)
@ -1697,13 +1707,15 @@ let solve_ ~on_progress (self : t) : unit =
in in
while true do while true do
on_progress (); on_progress ();
emit_counters_ self;
try try
self.max_clauses_learnt := int_of_float !max_learnt; self.max_clauses_learnt := int_of_float !max_learnt;
search self ~on_progress ~max_conflicts:(int_of_float !max_conflicts) search self ~on_progress ~max_conflicts:(int_of_float !max_conflicts)
with with
| Restart -> | Restart ->
max_conflicts := !max_conflicts *. restart_inc; max_conflicts := !max_conflicts *. restart_inc;
max_learnt := !max_learnt *. learntsize_inc max_learnt := !max_learnt *. learntsize_inc;
emit_counters_ self
| E_sat -> | E_sat ->
assert ( assert (
self.elt_head = AVec.size self.trail self.elt_head = AVec.size self.trail
@ -1975,6 +1987,8 @@ let solve ?(on_progress = fun _ -> ()) ?(assumptions = []) (self : t) : res =
with_local_assumptions_ self assumptions @@ fun () -> with_local_assumptions_ self assumptions @@ fun () ->
try try
solve_ ~on_progress self; solve_ ~on_progress self;
Log.debug 3 "(sat.return Sat)";
Sat (mk_sat self) Sat (mk_sat self)
with E_unsat us -> Unsat (mk_unsat self us) with E_unsat us -> Unsat (mk_unsat self us)