mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 11:15:43 -05:00
make Solver.t more lightweight by removing some useless fields
This commit is contained in:
parent
a65309d5e6
commit
c14f0ba020
1 changed files with 21 additions and 64 deletions
|
|
@ -34,6 +34,18 @@ module Make
|
||||||
let info = 5
|
let info = 5
|
||||||
let debug = 50
|
let debug = 50
|
||||||
|
|
||||||
|
let var_decay : float = 1. /. 0.95
|
||||||
|
(* inverse of the activity factor for variables. Default 1/0.999 *)
|
||||||
|
|
||||||
|
let clause_decay : float = 1. /. 0.999
|
||||||
|
(* inverse of the activity factor for clauses. Default 1/0.95 *)
|
||||||
|
|
||||||
|
let restart_inc : float = 1.5
|
||||||
|
(* multiplicative factor for restart limit, default 1.5 *)
|
||||||
|
|
||||||
|
let learntsize_inc : float = 1.1
|
||||||
|
(* multiplicative factor for [learntsize_factor] at each restart, default 1.1 *)
|
||||||
|
|
||||||
(* Singleton type containing the current state *)
|
(* Singleton type containing the current state *)
|
||||||
type t = {
|
type t = {
|
||||||
st : St.t;
|
st : St.t;
|
||||||
|
|
@ -88,49 +100,21 @@ module Make
|
||||||
th_head = elt_head = length trail
|
th_head = elt_head = length trail
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
|
||||||
mutable simpDB_props : int;
|
|
||||||
(* remaining number of propagations before the next call to [simplify ()] *)
|
|
||||||
mutable simpDB_assigns : int;
|
|
||||||
(* number of toplevel assignments since last call to [simplify ()] *)
|
|
||||||
|
|
||||||
|
|
||||||
order : H.t;
|
order : H.t;
|
||||||
(* Heap ordered by variable activity *)
|
(* Heap ordered by variable activity *)
|
||||||
|
|
||||||
var_decay : float;
|
|
||||||
(* inverse of the activity factor for variables. Default 1/0.999 *)
|
|
||||||
clause_decay : float;
|
|
||||||
(* inverse of the activity factor for clauses. Default 1/0.95 *)
|
|
||||||
|
|
||||||
mutable var_incr : float;
|
mutable var_incr : float;
|
||||||
(* increment for variables' activity *)
|
(* increment for variables' activity *)
|
||||||
|
|
||||||
mutable clause_incr : float;
|
mutable clause_incr : float;
|
||||||
(* increment for clauses' activity *)
|
(* increment for clauses' activity *)
|
||||||
|
|
||||||
remove_satisfied : bool;
|
|
||||||
(* Wether to remove satisfied learnt clauses when simplifying *)
|
|
||||||
|
|
||||||
|
|
||||||
restart_inc : float;
|
|
||||||
(* multiplicative factor for restart limit, default 1.5 *)
|
|
||||||
mutable restart_first : int;
|
mutable restart_first : int;
|
||||||
(* intial restart limit, default 100 *)
|
(* intial restart limit, default 100 *)
|
||||||
|
|
||||||
|
|
||||||
learntsize_inc : float;
|
|
||||||
(* multiplicative factor for [learntsize_factor] at each restart, default 1.1 *)
|
|
||||||
mutable learntsize_factor : float;
|
mutable learntsize_factor : float;
|
||||||
(* initial limit for the number of learnt clauses, 1/3 of initial
|
(* initial limit for the number of learnt clauses, 1/3 of initial
|
||||||
number of clauses by default *)
|
number of clauses by default *)
|
||||||
|
|
||||||
mutable starts : int;
|
|
||||||
mutable decisions : int;
|
|
||||||
mutable propagations : int;
|
|
||||||
mutable conflicts : int;
|
|
||||||
mutable clauses_literals : int;
|
|
||||||
mutable learnts_literals : int;
|
|
||||||
mutable nb_init_clauses : int;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(* Starting environment. *)
|
(* Starting environment. *)
|
||||||
|
|
@ -158,27 +142,10 @@ module Make
|
||||||
|
|
||||||
var_incr = 1.;
|
var_incr = 1.;
|
||||||
clause_incr = 1.;
|
clause_incr = 1.;
|
||||||
var_decay = 1. /. 0.95;
|
|
||||||
clause_decay = 1. /. 0.999;
|
|
||||||
|
|
||||||
simpDB_assigns = -1;
|
|
||||||
simpDB_props = 0;
|
|
||||||
|
|
||||||
remove_satisfied = false;
|
|
||||||
|
|
||||||
restart_inc = 1.5;
|
|
||||||
restart_first = 100;
|
restart_first = 100;
|
||||||
|
|
||||||
learntsize_factor = 1. /. 3. ;
|
learntsize_factor = 1. /. 3. ;
|
||||||
learntsize_inc = 1.1;
|
|
||||||
|
|
||||||
starts = 0;
|
|
||||||
decisions = 0;
|
|
||||||
propagations = 0;
|
|
||||||
conflicts = 0;
|
|
||||||
clauses_literals = 0;
|
|
||||||
learnts_literals = 0;
|
|
||||||
nb_init_clauses = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let create ?(size=`Big) ?st () : t =
|
let create ?(size=`Big) ?st () : t =
|
||||||
|
|
@ -268,11 +235,11 @@ module Make
|
||||||
(* Rather than iterate over all the heap when we want to decrease all the
|
(* Rather than iterate over all the heap when we want to decrease all the
|
||||||
variables/literals activity, we instead increase the value by which
|
variables/literals activity, we instead increase the value by which
|
||||||
we increase the activity of 'interesting' var/lits. *)
|
we increase the activity of 'interesting' var/lits. *)
|
||||||
let var_decay_activity st =
|
let[@inline] var_decay_activity st =
|
||||||
st.var_incr <- st.var_incr *. st.var_decay
|
st.var_incr <- st.var_incr *. var_decay
|
||||||
|
|
||||||
let clause_decay_activity st =
|
let[@inline] clause_decay_activity st =
|
||||||
st.clause_incr <- st.clause_incr *. st.clause_decay
|
st.clause_incr <- st.clause_incr *. clause_decay
|
||||||
|
|
||||||
(* increase activity of [v] *)
|
(* increase activity of [v] *)
|
||||||
let var_bump_activity_aux st v =
|
let var_bump_activity_aux st v =
|
||||||
|
|
@ -804,7 +771,6 @@ module Make
|
||||||
let add_boolean_conflict st (confl:clause): unit =
|
let add_boolean_conflict st (confl:clause): unit =
|
||||||
Log.debugf info (fun k -> k "Boolean conflict: %a" Clause.debug confl);
|
Log.debugf info (fun k -> k "Boolean conflict: %a" Clause.debug confl);
|
||||||
st.next_decision <- None;
|
st.next_decision <- None;
|
||||||
st.conflicts <- st.conflicts + 1;
|
|
||||||
assert (decision_level st >= base_level st);
|
assert (decision_level st >= base_level st);
|
||||||
if decision_level st = base_level st ||
|
if decision_level st = base_level st ||
|
||||||
Array.for_all (fun a -> a.var.v_level <= base_level st) confl.atoms then (
|
Array.for_all (fun a -> a.var.v_level <= base_level st) confl.atoms then (
|
||||||
|
|
@ -895,18 +861,14 @@ module Make
|
||||||
Log.debugf info (fun k->k "Trivial clause ignored : @[%a@]" Clause.debug init)
|
Log.debugf info (fun k->k "Trivial clause ignored : @[%a@]" Clause.debug init)
|
||||||
|
|
||||||
let flush_clauses st =
|
let flush_clauses st =
|
||||||
if not (Stack.is_empty st.clauses_to_add) then begin
|
if not (Stack.is_empty st.clauses_to_add) then (
|
||||||
let nbv = St.nb_elt st.st in
|
let nbv = St.nb_elt st.st in
|
||||||
let nbc = st.nb_init_clauses + Stack.length st.clauses_to_add in
|
|
||||||
H.grow_to_at_least st.order nbv;
|
H.grow_to_at_least st.order nbv;
|
||||||
Vec.grow_to_at_least st.clauses_hyps nbc;
|
|
||||||
Vec.grow_to_at_least st.clauses_learnt nbc;
|
|
||||||
st.nb_init_clauses <- nbc;
|
|
||||||
while not (Stack.is_empty st.clauses_to_add) do
|
while not (Stack.is_empty st.clauses_to_add) do
|
||||||
let c = Stack.pop st.clauses_to_add in
|
let c = Stack.pop st.clauses_to_add in
|
||||||
add_clause st c
|
add_clause st c
|
||||||
done
|
done
|
||||||
end
|
)
|
||||||
|
|
||||||
type watch_res =
|
type watch_res =
|
||||||
| Watch_kept
|
| Watch_kept
|
||||||
|
|
@ -1091,8 +1053,6 @@ module Make
|
||||||
end;
|
end;
|
||||||
st.elt_head <- st.elt_head + 1;
|
st.elt_head <- st.elt_head + 1;
|
||||||
done;
|
done;
|
||||||
st.propagations <- st.propagations + !num_props;
|
|
||||||
st.simpDB_props <- st.simpDB_props - !num_props;
|
|
||||||
match !res with
|
match !res with
|
||||||
| None -> theory_propagate st
|
| None -> theory_propagate st
|
||||||
| _ -> !res
|
| _ -> !res
|
||||||
|
|
@ -1111,7 +1071,6 @@ module Make
|
||||||
pick_branch_lit st
|
pick_branch_lit st
|
||||||
) else match Plugin.eval atom.lit with
|
) else match Plugin.eval atom.lit with
|
||||||
| Plugin_intf.Unknown ->
|
| Plugin_intf.Unknown ->
|
||||||
st.decisions <- st.decisions + 1;
|
|
||||||
new_decision_level st;
|
new_decision_level st;
|
||||||
let current_level = decision_level st in
|
let current_level = decision_level st in
|
||||||
enqueue_bool st atom ~level:current_level Decision
|
enqueue_bool st atom ~level:current_level Decision
|
||||||
|
|
@ -1131,7 +1090,6 @@ module Make
|
||||||
pick_branch_lit st
|
pick_branch_lit st
|
||||||
else (
|
else (
|
||||||
let value = Plugin.assign l.term in
|
let value = Plugin.assign l.term in
|
||||||
st.decisions <- st.decisions + 1;
|
|
||||||
new_decision_level st;
|
new_decision_level st;
|
||||||
let current_level = decision_level st in
|
let current_level = decision_level st in
|
||||||
enqueue_assign st l value current_level
|
enqueue_assign st l value current_level
|
||||||
|
|
@ -1145,7 +1103,6 @@ module Make
|
||||||
reaches the given parameters *)
|
reaches the given parameters *)
|
||||||
let search (st:t) n_of_conflicts n_of_learnts : unit =
|
let search (st:t) n_of_conflicts n_of_learnts : unit =
|
||||||
let conflictC = ref 0 in
|
let conflictC = ref 0 in
|
||||||
st.starts <- st.starts + 1;
|
|
||||||
while true do
|
while true do
|
||||||
match propagate st with
|
match propagate st with
|
||||||
| Some confl -> (* Conflict *)
|
| Some confl -> (* Conflict *)
|
||||||
|
|
@ -1215,8 +1172,8 @@ module Make
|
||||||
search st (to_int !n_of_conflicts) (to_int !n_of_learnts)
|
search st (to_int !n_of_conflicts) (to_int !n_of_learnts)
|
||||||
with
|
with
|
||||||
| Restart ->
|
| Restart ->
|
||||||
n_of_conflicts := !n_of_conflicts *. st.restart_inc;
|
n_of_conflicts := !n_of_conflicts *. restart_inc;
|
||||||
n_of_learnts := !n_of_learnts *. st.learntsize_inc
|
n_of_learnts := !n_of_learnts *. learntsize_inc
|
||||||
| Sat ->
|
| Sat ->
|
||||||
assert (st.elt_head = Vec.size st.trail);
|
assert (st.elt_head = Vec.size st.trail);
|
||||||
begin match Plugin.if_sat (full_slice st) with
|
begin match Plugin.if_sat (full_slice st) with
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue