mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-07 11:45:41 -05:00
perf(sat): use Atom.Vec for temporary atom array
This commit is contained in:
parent
74326b39c0
commit
bbe366989c
2 changed files with 36 additions and 31 deletions
|
|
@ -101,13 +101,13 @@ module Make(Plugin : PLUGIN)
|
||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
(* variables *)
|
(* variables *)
|
||||||
v_of_lit: var Lit_tbl.t;
|
v_of_lit: var Lit_tbl.t; (* lit -> var *)
|
||||||
v_level: int Vec.t;
|
v_level: int Vec.t; (* decision/assignment level, or -1 *)
|
||||||
v_heap_idx: int Vec.t;
|
v_heap_idx: int Vec.t; (* index in priority heap *)
|
||||||
v_weight: Vec_float.t;
|
v_weight: Vec_float.t; (* heuristic activity *)
|
||||||
v_reason: reason option Vec.t;
|
v_reason: reason option Vec.t; (* reason for assignment *)
|
||||||
v_seen: Bitvec.t;
|
v_seen: Bitvec.t; (* generic temporary marker *)
|
||||||
v_default_polarity: Bitvec.t;
|
v_default_polarity: Bitvec.t; (* default polarity in decisions *)
|
||||||
mutable v_count : int;
|
mutable v_count : int;
|
||||||
|
|
||||||
(* atoms *)
|
(* atoms *)
|
||||||
|
|
@ -679,7 +679,7 @@ module Make(Plugin : PLUGIN)
|
||||||
|
|
||||||
(* temporaries *)
|
(* temporaries *)
|
||||||
|
|
||||||
temp_atom_vec : atom Vec.t;
|
temp_atom_vec : AVec.t;
|
||||||
temp_clause_vec : CVec.t;
|
temp_clause_vec : CVec.t;
|
||||||
|
|
||||||
mutable var_incr : float;
|
mutable var_incr : float;
|
||||||
|
|
@ -728,7 +728,7 @@ module Make(Plugin : PLUGIN)
|
||||||
|
|
||||||
to_clear=Vec.create();
|
to_clear=Vec.create();
|
||||||
temp_clause_vec=CVec.create();
|
temp_clause_vec=CVec.create();
|
||||||
temp_atom_vec=Vec.create();
|
temp_atom_vec=AVec.create();
|
||||||
|
|
||||||
th_head = 0;
|
th_head = 0;
|
||||||
elt_head = 0;
|
elt_head = 0;
|
||||||
|
|
@ -1161,18 +1161,18 @@ module Make(Plugin : PLUGIN)
|
||||||
(* minimize conflict by removing atoms whose propagation history
|
(* minimize conflict by removing atoms whose propagation history
|
||||||
is ultimately self-subsuming with [lits] *)
|
is ultimately self-subsuming with [lits] *)
|
||||||
let minimize_conflict (self:t) (_c_level:int)
|
let minimize_conflict (self:t) (_c_level:int)
|
||||||
(learnt: atom Vec.t) : unit =
|
(learnt: AVec.t) : unit =
|
||||||
let store = self.store in
|
let store = self.store in
|
||||||
|
|
||||||
(* abstraction of the levels involved in the conflict at all,
|
(* abstraction of the levels involved in the conflict at all,
|
||||||
as logical "or" of each literal's approximate level *)
|
as logical "or" of each literal's approximate level *)
|
||||||
let abstract_levels =
|
let abstract_levels =
|
||||||
Vec.fold (fun lvl a -> lvl lor abstract_level_ self (Atom.var a)) 0 learnt
|
AVec.fold_left (fun lvl a -> lvl lor abstract_level_ self (Atom.var a)) 0 learnt
|
||||||
in
|
in
|
||||||
|
|
||||||
let j = ref 1 in
|
let j = ref 1 in
|
||||||
for i=1 to Vec.size learnt - 1 do
|
for i=1 to AVec.size learnt - 1 do
|
||||||
let a = Vec.get learnt i in
|
let a = AVec.get learnt i in
|
||||||
let keep =
|
let keep =
|
||||||
begin match Atom.reason store a with
|
begin match Atom.reason store a with
|
||||||
| Some Decision -> true (* always keep decisions *)
|
| Some Decision -> true (* always keep decisions *)
|
||||||
|
|
@ -1182,13 +1182,13 @@ module Make(Plugin : PLUGIN)
|
||||||
end
|
end
|
||||||
in
|
in
|
||||||
if keep then (
|
if keep then (
|
||||||
Vec.set learnt !j a;
|
AVec.set learnt !j a;
|
||||||
incr j
|
incr j
|
||||||
) else (
|
) else (
|
||||||
Stat.incr self.n_minimized_away;
|
Stat.incr self.n_minimized_away;
|
||||||
)
|
)
|
||||||
done;
|
done;
|
||||||
Vec.shrink learnt !j;
|
AVec.shrink learnt !j;
|
||||||
()
|
()
|
||||||
|
|
||||||
(* result of conflict analysis, containing the learnt clause and some
|
(* result of conflict analysis, containing the learnt clause and some
|
||||||
|
|
@ -1206,7 +1206,7 @@ module Make(Plugin : PLUGIN)
|
||||||
let to_unmark = self.to_clear in (* for cleanup *)
|
let to_unmark = self.to_clear in (* for cleanup *)
|
||||||
Vec.clear to_unmark;
|
Vec.clear to_unmark;
|
||||||
let learnt = self.temp_atom_vec in
|
let learnt = self.temp_atom_vec in
|
||||||
Vec.clear learnt;
|
AVec.clear learnt;
|
||||||
|
|
||||||
(* loop variables *)
|
(* loop variables *)
|
||||||
let pathC = ref 0 in
|
let pathC = ref 0 in
|
||||||
|
|
@ -1258,7 +1258,7 @@ module Make(Plugin : PLUGIN)
|
||||||
if Atom.level store q >= conflict_level then (
|
if Atom.level store q >= conflict_level then (
|
||||||
incr pathC;
|
incr pathC;
|
||||||
) else (
|
) else (
|
||||||
Vec.push learnt q;
|
AVec.push learnt q;
|
||||||
blevel := max !blevel (Atom.level store q)
|
blevel := max !blevel (Atom.level store q)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -1282,7 +1282,7 @@ module Make(Plugin : PLUGIN)
|
||||||
match !pathC, Atom.reason store p with
|
match !pathC, Atom.reason store p with
|
||||||
| 0, _ ->
|
| 0, _ ->
|
||||||
continue := false;
|
continue := false;
|
||||||
Vec.push learnt (Atom.neg p)
|
AVec.push learnt (Atom.neg p)
|
||||||
| n, Some (Bcp cl | Bcp_lazy (lazy cl)) ->
|
| n, Some (Bcp cl | Bcp_lazy (lazy cl)) ->
|
||||||
assert (n > 0);
|
assert (n > 0);
|
||||||
assert (Atom.level store p >= conflict_level);
|
assert (Atom.level store p >= conflict_level);
|
||||||
|
|
@ -1300,8 +1300,8 @@ module Make(Plugin : PLUGIN)
|
||||||
(* put high-level literals first, so that:
|
(* put high-level literals first, so that:
|
||||||
- they make adequate watch lits
|
- they make adequate watch lits
|
||||||
- the first literal is the UIP, if any *)
|
- the first literal is the UIP, if any *)
|
||||||
let cr_learnt = Vec.to_array learnt in
|
let cr_learnt = AVec.to_array learnt in
|
||||||
Vec.clear learnt;
|
AVec.clear learnt;
|
||||||
Array.sort (fun p q -> compare (Atom.level store q) (Atom.level store p)) cr_learnt;
|
Array.sort (fun p q -> compare (Atom.level store q) (Atom.level store p)) cr_learnt;
|
||||||
|
|
||||||
(* put_high_level_atoms_first a; *)
|
(* put_high_level_atoms_first a; *)
|
||||||
|
|
@ -1750,7 +1750,7 @@ module Make(Plugin : PLUGIN)
|
||||||
let reduce_clause_db (self:t) : unit =
|
let reduce_clause_db (self:t) : unit =
|
||||||
let store = self.store in
|
let store = self.store in
|
||||||
|
|
||||||
Log.debugf 3 (fun k->k "(@[sat.gc.start :max-learnt %d@])"
|
Log.debugf 3 (fun k->k "(@[sat.gc-clauses.start :max-learnt %d@])"
|
||||||
!(self.max_clauses_learnt));
|
!(self.max_clauses_learnt));
|
||||||
|
|
||||||
let to_be_gc = self.temp_clause_vec in (* clauses to collect *)
|
let to_be_gc = self.temp_clause_vec in (* clauses to collect *)
|
||||||
|
|
@ -1759,14 +1759,14 @@ module Make(Plugin : PLUGIN)
|
||||||
(* atoms whose watches will need to be rebuilt to filter out
|
(* atoms whose watches will need to be rebuilt to filter out
|
||||||
dead clauses *)
|
dead clauses *)
|
||||||
let dirty_atoms = self.temp_atom_vec in
|
let dirty_atoms = self.temp_atom_vec in
|
||||||
assert (Vec.is_empty dirty_atoms);
|
assert (AVec.is_empty dirty_atoms);
|
||||||
|
|
||||||
(* [a] is watching at least one removed clause, we'll need to
|
(* [a] is watching at least one removed clause, we'll need to
|
||||||
trim its watchlist *)
|
trim its watchlist *)
|
||||||
let[@inline] mark_dirty_atom a =
|
let[@inline] mark_dirty_atom a =
|
||||||
if not (Atom.marked store a) then (
|
if not (Atom.marked store a) then (
|
||||||
Atom.mark store a;
|
Atom.mark store a;
|
||||||
Vec.push dirty_atoms a;
|
AVec.push dirty_atoms a;
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
|
|
||||||
|
|
@ -1774,13 +1774,12 @@ module Make(Plugin : PLUGIN)
|
||||||
which we must therefore keep for now as they might participate in
|
which we must therefore keep for now as they might participate in
|
||||||
conflict resolution *)
|
conflict resolution *)
|
||||||
let iter_clauses_on_trail ~f : unit =
|
let iter_clauses_on_trail ~f : unit =
|
||||||
AVec.iter
|
AVec.iter self.trail
|
||||||
~f:(fun a ->
|
~f:(fun a ->
|
||||||
match Atom.reason store a with
|
match Atom.reason store a with
|
||||||
| Some (Bcp c) -> f c
|
| Some (Bcp c) -> f c
|
||||||
| Some (Bcp_lazy lc) when Lazy.is_val lc -> f (Lazy.force lc)
|
| Some (Bcp_lazy lc) when Lazy.is_val lc -> f (Lazy.force lc)
|
||||||
| _ -> ())
|
| _ -> ());
|
||||||
self.trail;
|
|
||||||
in
|
in
|
||||||
|
|
||||||
iter_clauses_on_trail ~f:(fun c -> Clause.set_marked store c true);
|
iter_clauses_on_trail ~f:(fun c -> Clause.set_marked store c true);
|
||||||
|
|
@ -1835,14 +1834,13 @@ module Make(Plugin : PLUGIN)
|
||||||
let n_collected = CVec.size to_be_gc in
|
let n_collected = CVec.size to_be_gc in
|
||||||
|
|
||||||
(* update watchlist of dirty atoms *)
|
(* update watchlist of dirty atoms *)
|
||||||
Vec.iter
|
AVec.iter dirty_atoms
|
||||||
(fun a ->
|
~f:(fun a ->
|
||||||
assert (Atom.marked store a);
|
assert (Atom.marked store a);
|
||||||
Atom.unmark store a;
|
Atom.unmark store a;
|
||||||
let w = Atom.watched store a in
|
let w = Atom.watched store a in
|
||||||
CVec.filter_in_place (fun c -> not (Clause.dead store c)) w)
|
CVec.filter_in_place (fun c -> not (Clause.dead store c)) w);
|
||||||
dirty_atoms;
|
AVec.clear dirty_atoms;
|
||||||
Vec.clear dirty_atoms;
|
|
||||||
|
|
||||||
(* actually remove the clauses now that they are detached *)
|
(* actually remove the clauses now that they are detached *)
|
||||||
CVec.iter ~f:(Clause.dealloc store) to_be_gc;
|
CVec.iter ~f:(Clause.dealloc store) to_be_gc;
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ module type EXTENSIONS = sig
|
||||||
|
|
||||||
val to_array : t -> elt array
|
val to_array : t -> elt array
|
||||||
|
|
||||||
|
val fold_left : ('a -> elt -> 'a) -> 'a -> t -> 'a
|
||||||
|
|
||||||
val pp : elt CCFormat.printer -> t CCFormat.printer
|
val pp : elt CCFormat.printer -> t CCFormat.printer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -69,6 +71,11 @@ module Make_extensions(B: BASE_RO)
|
||||||
a
|
a
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let fold_left f acc self =
|
||||||
|
let r = ref acc in
|
||||||
|
iter self ~f:(fun x -> r := f !r x);
|
||||||
|
!r
|
||||||
|
|
||||||
let pp ppx out self =
|
let pp ppx out self =
|
||||||
Format.fprintf out "[@[";
|
Format.fprintf out "[@[";
|
||||||
iteri self
|
iteri self
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue