mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-08 20:25:31 -05:00
Replaced List.map with List.rev_map
Added Vec.set_unsafe and fixed a few bugs
This commit is contained in:
parent
ea1757875a
commit
3422634923
7 changed files with 37 additions and 13 deletions
|
|
@ -463,15 +463,16 @@ module Make (F : Formula_intf.S)
|
||||||
(* returns true if the clause is used as a reason for a propagation,
|
(* returns true if the clause is used as a reason for a propagation,
|
||||||
and therefore can be needed in case of conflict. In this case
|
and therefore can be needed in case of conflict. In this case
|
||||||
the clause can't be forgotten *)
|
the clause can't be forgotten *)
|
||||||
let locked c =
|
let locked c = false (*
|
||||||
Vec.exists
|
Vec.exists
|
||||||
(fun v -> match v.reason with
|
(fun v -> match v.reason with
|
||||||
| Some c' -> c ==c'
|
| Some c' -> c ==c'
|
||||||
| _ -> false
|
| _ -> false
|
||||||
) env.vars
|
) env.vars
|
||||||
|
*)
|
||||||
|
|
||||||
(* remove some learnt clauses *)
|
(* remove some learnt clauses *)
|
||||||
let reduce_db () =
|
let reduce_db () = () (*
|
||||||
let extra_lim = env.clause_inc /. (to_float (Vec.size env.learnts)) in
|
let extra_lim = env.clause_inc /. (to_float (Vec.size env.learnts)) in
|
||||||
Vec.sort env.learnts f_sort_db;
|
Vec.sort env.learnts f_sort_db;
|
||||||
let lim2 = Vec.size env.learnts in
|
let lim2 = Vec.size env.learnts in
|
||||||
|
|
@ -492,6 +493,7 @@ module Make (F : Formula_intf.S)
|
||||||
begin Vec.set env.learnts !j c; incr j end
|
begin Vec.set env.learnts !j c; incr j end
|
||||||
done;
|
done;
|
||||||
Vec.shrink env.learnts (lim2 - !j)
|
Vec.shrink env.learnts (lim2 - !j)
|
||||||
|
*)
|
||||||
|
|
||||||
(* remove from [vec] the clauses that are satisfied in the current trail *)
|
(* remove from [vec] the clauses that are satisfied in the current trail *)
|
||||||
let remove_satisfied vec =
|
let remove_satisfied vec =
|
||||||
|
|
@ -879,14 +881,13 @@ module Make (F : Formula_intf.S)
|
||||||
None -> () | Some dep -> report_t_unsat dep
|
None -> () | Some dep -> report_t_unsat dep
|
||||||
|
|
||||||
let init_solver cnf ~cnumber =
|
let init_solver cnf ~cnumber =
|
||||||
let nbv, _ = made_vars_info () in
|
let nbv = made_vars_info env.vars in
|
||||||
let nbc = env.nb_init_clauses + List.length cnf in
|
let nbc = env.nb_init_clauses + List.length cnf in
|
||||||
Vec.grow_to_by_double env.vars nbv;
|
Vec.grow_to_by_double env.vars nbv;
|
||||||
Iheap.grow_to_by_double env.order nbv;
|
Iheap.grow_to_by_double env.order nbv;
|
||||||
List.iter
|
List.iter
|
||||||
(List.iter
|
(List.iter
|
||||||
(fun a ->
|
(fun a ->
|
||||||
Vec.set env.vars a.var.vid a.var;
|
|
||||||
insert_var_order a.var
|
insert_var_order a.var
|
||||||
)
|
)
|
||||||
) cnf;
|
) cnf;
|
||||||
|
|
@ -899,7 +900,7 @@ module Make (F : Formula_intf.S)
|
||||||
|
|
||||||
|
|
||||||
let assume cnf ~cnumber =
|
let assume cnf ~cnumber =
|
||||||
let cnf = List.map (List.map St.add_atom) cnf in
|
let cnf = List.rev_map (List.rev_map St.add_atom) cnf in
|
||||||
init_solver cnf ~cnumber
|
init_solver cnf ~cnumber
|
||||||
|
|
||||||
let eval lit =
|
let eval lit =
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,10 @@ module Make (F : Formula_intf.S) = struct
|
||||||
incr cpt_mk_var;
|
incr cpt_mk_var;
|
||||||
var, negated
|
var, negated
|
||||||
|
|
||||||
let made_vars_info () = !cpt_mk_var, MA.fold (fun lit var acc -> var::acc)!ma []
|
let made_vars_info vars =
|
||||||
|
Vec.grow_to_by_double vars !cpt_mk_var;
|
||||||
|
MA.iter (fun _ var -> Vec.set_unsafe vars var.vid var) !ma;
|
||||||
|
!cpt_mk_var
|
||||||
|
|
||||||
let add_atom lit =
|
let add_atom lit =
|
||||||
let var, negated = make_var lit in
|
let var, negated = make_var lit in
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ module type S = sig
|
||||||
val to_float : int -> float
|
val to_float : int -> float
|
||||||
|
|
||||||
val to_int : float -> int
|
val to_int : float -> int
|
||||||
val made_vars_info : unit -> int * var list
|
val made_vars_info : var Vec.t -> int
|
||||||
val clear : unit -> unit
|
val clear : unit -> unit
|
||||||
|
|
||||||
val pp_atom : Buffer.t -> atom -> unit
|
val pp_atom : Buffer.t -> atom -> unit
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ let clear {heap; indices} =
|
||||||
let insert cmp s n =
|
let insert cmp s n =
|
||||||
if not (in_heap s n) then
|
if not (in_heap s n) then
|
||||||
begin
|
begin
|
||||||
Vec.set s.indices n (Vec.size s.heap);
|
Vec.set_unsafe s.indices n (Vec.size s.heap);
|
||||||
Vec.push s.heap n;
|
Vec.push s.heap n;
|
||||||
percolate_up cmp s (Vec.get s.indices n)
|
percolate_up cmp s (Vec.get s.indices n)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ let check () =
|
||||||
|
|
||||||
(* Entry file parsing *)
|
(* Entry file parsing *)
|
||||||
let get_cnf () =
|
let get_cnf () =
|
||||||
List.map (List.map S.make) (Parser.parse !file)
|
List.rev_map (List.rev_map S.make) (Parser.parse !file)
|
||||||
|
|
||||||
let print_cnf cnf =
|
let print_cnf cnf =
|
||||||
Format.printf "CNF :@\n";
|
Format.printf "CNF :@\n";
|
||||||
|
|
|
||||||
26
util/vec.ml
26
util/vec.ml
|
|
@ -13,11 +13,18 @@
|
||||||
|
|
||||||
type 'a t = { mutable dummy: 'a; mutable data : 'a array; mutable sz : int }
|
type 'a t = { mutable dummy: 'a; mutable data : 'a array; mutable sz : int }
|
||||||
|
|
||||||
let make capa d = {data = Array.make capa d; sz = 0; dummy = d}
|
let _size_too_big()=
|
||||||
|
failwith "Vec: capacity exceeds maximum array size"
|
||||||
|
|
||||||
|
let make capa d =
|
||||||
|
if capa > Sys.max_array_length then _size_too_big();
|
||||||
|
{data = Array.make capa d; sz = 0; dummy = d}
|
||||||
|
|
||||||
let make_empty d = {data = [||]; sz=0; dummy=d }
|
let make_empty d = {data = [||]; sz=0; dummy=d }
|
||||||
|
|
||||||
let init capa f d = {data = Array.init capa (fun i -> f i); sz = capa; dummy = d}
|
let init capa f d =
|
||||||
|
if capa > Sys.max_array_length then _size_too_big();
|
||||||
|
{data = Array.init capa (fun i -> f i); sz = capa; dummy = d}
|
||||||
|
|
||||||
let from_array data sz d =
|
let from_array data sz d =
|
||||||
assert (sz <= Array.length data);
|
assert (sz <= Array.length data);
|
||||||
|
|
@ -45,12 +52,18 @@ let grow_to t new_capa =
|
||||||
let capa = Array.length data in
|
let capa = Array.length data in
|
||||||
t.data <- Array.init new_capa (fun i -> if i < capa then data.(i) else t.dummy)
|
t.data <- Array.init new_capa (fun i -> if i < capa then data.(i) else t.dummy)
|
||||||
|
|
||||||
let grow_to_double_size t = grow_to t (2* Array.length t.data)
|
let grow_to_double_size t =
|
||||||
|
if Array.length t.data = Sys.max_array_length then _size_too_big();
|
||||||
|
let size = min Sys.max_array_length (2* Array.length t.data) in
|
||||||
|
grow_to t size
|
||||||
|
|
||||||
let rec grow_to_by_double t new_capa =
|
let rec grow_to_by_double t new_capa =
|
||||||
|
if new_capa > Sys.max_array_length then _size_too_big ();
|
||||||
let data = t.data in
|
let data = t.data in
|
||||||
let capa = ref (Array.length data + 1) in
|
let capa = ref (Array.length data + 1) in
|
||||||
while !capa < new_capa do capa := 2 * !capa done;
|
while !capa < new_capa do
|
||||||
|
capa := min (2 * !capa) Sys.max_array_length;
|
||||||
|
done;
|
||||||
grow_to t !capa
|
grow_to t !capa
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -75,6 +88,11 @@ let set t i v =
|
||||||
t.sz <- max t.sz (i+1); (* can set first empty slot *)
|
t.sz <- max t.sz (i+1); (* can set first empty slot *)
|
||||||
Array.unsafe_set t.data i v
|
Array.unsafe_set t.data i v
|
||||||
|
|
||||||
|
let set_unsafe t i v =
|
||||||
|
if i < 0 || i >= Array.length t.data then invalid_arg "vec.set_unsafe";
|
||||||
|
t.sz <- max t.sz (i+1);
|
||||||
|
Array.unsafe_set t.data i v
|
||||||
|
|
||||||
let copy t =
|
let copy t =
|
||||||
let data = Array.copy t.data in
|
let data = Array.copy t.data in
|
||||||
{t with data; }
|
{t with data; }
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,8 @@ val set : 'a t -> int -> 'a -> unit
|
||||||
free slot if [not (is_full vec)], or
|
free slot if [not (is_full vec)], or
|
||||||
@raise Invalid_argument if the index is not valid *)
|
@raise Invalid_argument if the index is not valid *)
|
||||||
|
|
||||||
|
val set_unsafe : 'a t -> int -> 'a -> unit
|
||||||
|
|
||||||
val copy : 'a t -> 'a t
|
val copy : 'a t -> 'a t
|
||||||
(** Fresh copy *)
|
(** Fresh copy *)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue