Better perfs for unsat_core

This commit is contained in:
Guillaume Bury 2016-07-13 17:44:04 +02:00
parent ef49d5eaaa
commit 2ff1279f26
3 changed files with 22 additions and 9 deletions

View file

@ -158,18 +158,27 @@ module Make(St : Solver_types.S) = struct
{ conclusion; step = Resolution (c', d', a); } { conclusion; step = Resolution (c', d', a); }
(* Compute unsat-core (* Compute unsat-core
TODO: the uniq sort at the end may be costly, maybe remove it, TODO: replace visited bool by a int unique to each call
or compare the clauses faster ? *) of unsat_core, so that the cleanup can be removed ? *)
let unsat_core proof = let unsat_core proof =
let rec aux acc = function let rec aux res acc = function
| [] -> acc | [] -> res, acc
| c :: r -> | c :: r ->
begin match c.St.cpremise with if not c.St.visited then begin
| St.Hyp _ | St.Lemma _ -> aux (c :: acc) r c.St.visited <- true;
| St.History l -> aux acc (l @ r) match c.St.cpremise with
end | St.Hyp _ | St.Lemma _ -> aux (c :: res) acc r
| St.History h ->
let l = List.fold_left (fun acc c ->
if not c.St.visited then c :: acc else acc) r h in
aux res (c :: acc) l
end else
aux res acc r
in in
sort_uniq cmp (aux [] [proof]) let res, tmp = aux [] [] [proof] in
List.iter (fun c -> c.St.visited <- false) res;
List.iter (fun c -> c.St.visited <- false) tmp;
res
(* Iter on proofs *) (* Iter on proofs *)
module H = Hashtbl.Make(struct module H = Hashtbl.Make(struct

View file

@ -63,6 +63,7 @@ module McMake (E : Expr_intf.S)(Dummy : sig end) = struct
mutable cpremise : premise; mutable cpremise : premise;
mutable activity : float; mutable activity : float;
mutable attached : bool; mutable attached : bool;
mutable visited : bool;
} }
and reason = and reason =
@ -106,6 +107,7 @@ module McMake (E : Expr_intf.S)(Dummy : sig end) = struct
attached = false; attached = false;
c_level = -1; c_level = -1;
learnt = false; learnt = false;
visited = false;
cpremise = History [] } cpremise = History [] }
let () = let () =
@ -192,6 +194,7 @@ module McMake (E : Expr_intf.S)(Dummy : sig end) = struct
tag = tag; tag = tag;
atoms = atoms; atoms = atoms;
attached = false; attached = false;
visited = false;
learnt = is_learnt; learnt = is_learnt;
c_level = level; c_level = level;
activity = 0.; activity = 0.;

View file

@ -58,6 +58,7 @@ module type S = sig
mutable cpremise : premise; mutable cpremise : premise;
mutable activity : float; mutable activity : float;
mutable attached : bool; mutable attached : bool;
mutable visited : bool;
} }
and reason = and reason =