mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 03:05:31 -05:00
comments and Vec.exists, used in Solver
This commit is contained in:
parent
38d16e8874
commit
1257dba6b1
4 changed files with 34 additions and 19 deletions
|
|
@ -119,6 +119,16 @@ let fold f acc t =
|
||||||
_fold f acc' t (i+1)
|
_fold f acc' t (i+1)
|
||||||
in _fold f acc t 0
|
in _fold f acc t 0
|
||||||
|
|
||||||
|
exception ExitVec
|
||||||
|
|
||||||
|
let exists p t =
|
||||||
|
try
|
||||||
|
for i = 0 to t.sz - 1 do
|
||||||
|
if p (Array.unsafe_get t.data i) then raise ExitVec
|
||||||
|
done;
|
||||||
|
false
|
||||||
|
with ExitVec -> true
|
||||||
|
|
||||||
(*
|
(*
|
||||||
template<class V, class T>
|
template<class V, class T>
|
||||||
static inline void remove(V& ts, const T& t)
|
static inline void remove(V& ts, const T& t)
|
||||||
|
|
|
||||||
|
|
@ -90,3 +90,6 @@ val iter : ('a -> unit) -> 'a t -> unit
|
||||||
val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
|
val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
|
||||||
(** Fold over elements *)
|
(** Fold over elements *)
|
||||||
|
|
||||||
|
val exists : ('a -> bool) -> 'a t -> bool
|
||||||
|
(** Does there exist an element that satisfies the predicate? *)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -230,12 +230,7 @@ module Make (F : Formula_intf.S)
|
||||||
let remove_clause c = detach_clause c
|
let remove_clause c = detach_clause c
|
||||||
|
|
||||||
let satisfied c =
|
let satisfied c =
|
||||||
try
|
Vec.exists (fun atom -> atom.is_true) c.atoms
|
||||||
for i = 0 to Vec.size c.atoms - 1 do
|
|
||||||
if (Vec.get c.atoms i).is_true then raise Exit
|
|
||||||
done;
|
|
||||||
false
|
|
||||||
with Exit -> true
|
|
||||||
|
|
||||||
(* annule tout jusqu'a lvl *exclu* *)
|
(* annule tout jusqu'a lvl *exclu* *)
|
||||||
let cancel_until lvl =
|
let cancel_until lvl =
|
||||||
|
|
@ -391,6 +386,7 @@ module Make (F : Formula_intf.S)
|
||||||
(* eprintf "th inconsistent : %a @." Ex.print dep; *)
|
(* eprintf "th inconsistent : %a @." Ex.print dep; *)
|
||||||
Some dep
|
Some dep
|
||||||
|
|
||||||
|
(* boolean propagation, using unit clauses *)
|
||||||
let propagate () =
|
let propagate () =
|
||||||
let num_props = ref 0 in
|
let num_props = ref 0 in
|
||||||
let res = ref None in
|
let res = ref None in
|
||||||
|
|
@ -406,6 +402,7 @@ module Make (F : Formula_intf.S)
|
||||||
env.simpDB_props <- env.simpDB_props - !num_props;
|
env.simpDB_props <- env.simpDB_props - !num_props;
|
||||||
!res
|
!res
|
||||||
|
|
||||||
|
(* conflict analysis *)
|
||||||
let analyze c_clause =
|
let analyze c_clause =
|
||||||
let pathC = ref 0 in
|
let pathC = ref 0 in
|
||||||
let learnt = ref [] in
|
let learnt = ref [] in
|
||||||
|
|
@ -453,6 +450,8 @@ module Make (F : Formula_intf.S)
|
||||||
List.iter (fun q -> q.var.seen <- false) !seen;
|
List.iter (fun q -> q.var.seen <- false) !seen;
|
||||||
!blevel, !learnt, !history, !size
|
!blevel, !learnt, !history, !size
|
||||||
|
|
||||||
|
(* heuristic comparison between clauses, by their size (unary/binary or not)
|
||||||
|
and activity *)
|
||||||
let f_sort_db c1 c2 =
|
let f_sort_db c1 c2 =
|
||||||
let sz1 = Vec.size c1.atoms in
|
let sz1 = Vec.size c1.atoms in
|
||||||
let sz2 = Vec.size c2.atoms in
|
let sz2 = Vec.size c2.atoms in
|
||||||
|
|
@ -462,18 +461,18 @@ module Make (F : Formula_intf.S)
|
||||||
if sz1 > 2 && (sz2 = 2 || c < 0) then -1
|
if sz1 > 2 && (sz2 = 2 || c < 0) then -1
|
||||||
else 1
|
else 1
|
||||||
|
|
||||||
let locked c = false(*
|
(* returns true if the clause is used as a reason for a propagation,
|
||||||
try
|
and therefore can be needed in case of conflict. In this case
|
||||||
for i = 0 to Vec.size env.vars - 1 do
|
the clause can't be forgotten *)
|
||||||
match (Vec.get env.vars i).reason with
|
let locked c =
|
||||||
| Some c' when c ==c' -> raise Exit
|
Vec.exists
|
||||||
| _ -> ()
|
(fun v -> match v.reason with
|
||||||
done;
|
| Some c' -> c ==c'
|
||||||
false
|
| _ -> false
|
||||||
with Exit -> true*)
|
) env.vars
|
||||||
|
|
||||||
let reduce_db () = ()
|
(* remove some learnt clauses *)
|
||||||
(*
|
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
|
||||||
|
|
@ -494,8 +493,8 @@ 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 *)
|
||||||
let remove_satisfied vec =
|
let remove_satisfied vec =
|
||||||
let j = ref 0 in
|
let j = ref 0 in
|
||||||
let k = Vec.size vec - 1 in
|
let k = Vec.size vec - 1 in
|
||||||
|
|
@ -795,7 +794,8 @@ module Make (F : Formula_intf.S)
|
||||||
check_vec env.clauses;
|
check_vec env.clauses;
|
||||||
check_vec env.learnts
|
check_vec env.learnts
|
||||||
|
|
||||||
|
(* fixpoint of propagation and decisions until a model is found, or a
|
||||||
|
conflict is reached *)
|
||||||
let solve () =
|
let solve () =
|
||||||
if env.is_unsat then raise (Unsat env.unsat_core);
|
if env.is_unsat then raise (Unsat env.unsat_core);
|
||||||
let n_of_conflicts = ref (to_float env.restart_first) in
|
let n_of_conflicts = ref (to_float env.restart_first) in
|
||||||
|
|
@ -817,6 +817,7 @@ module Make (F : Formula_intf.S)
|
||||||
|
|
||||||
exception Trivial
|
exception Trivial
|
||||||
|
|
||||||
|
(* TODO: could be more efficient than [@] everywhere? *)
|
||||||
let partition atoms init =
|
let partition atoms init =
|
||||||
let rec partition_aux trues unassigned falses init = function
|
let rec partition_aux trues unassigned falses init = function
|
||||||
| [] -> trues @ unassigned @ falses, init
|
| [] -> trues @ unassigned @ falses, init
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ module type S = sig
|
||||||
val assume : cs:bool -> formula -> explanation -> t -> t
|
val assume : cs:bool -> formula -> explanation -> t -> t
|
||||||
(** Return a new theory state with the formula as assumption.
|
(** Return a new theory state with the formula as assumption.
|
||||||
@raise Inconsistent if the new state would be inconsistent. *)
|
@raise Inconsistent if the new state would be inconsistent. *)
|
||||||
|
(* TODO: remove (apparently) useless [cs] parameter *)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue