From b8d4ee198ac2e08234823655a1542d9616292191 Mon Sep 17 00:00:00 2001 From: Guillaume Bury Date: Thu, 3 Nov 2016 10:38:03 +0100 Subject: [PATCH] Better dimacs printing --- src/core/external.ml | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/core/external.ml b/src/core/external.ml index 09fa446c..b3fde322 100644 --- a/src/core/external.ml +++ b/src/core/external.ml @@ -106,27 +106,47 @@ module Make let get_tag cl = St.(cl.tag) let export_dimacs fmt () = - let n = St.nb_elt () in + (* Local assertions *) let tmp = S.temp () in + assert (Vec.for_all (function + | { St.cpremise = St.Local; _} -> true | _ -> false + ) tmp); + (* Problem hypothses *) let hyps = S.hyps () in + assert (Vec.for_all (function + | { St.cpremise = St.Hyp; _} -> true | _ -> false + ) hyps); + (* Learnt clauses, then filtered to only keep only + the theory lemmas; all other learnt clauses should be logical + consequences of the rest. *) let learnt = S.history () in - let m = Vec.size hyps + Vec.size learnt in - let aux fmt c = - let c' = match c.St.cpremise with - | St.Hyp | St.Lemma _ -> c - | St.History ( { St.cpremise = (St.Hyp | St.Lemma _) } as d :: _) -> d - | _ -> c (* FIXME *) - in - St.pp_dimacs fmt c' - in + let lemmas = Vec.make (Vec.size learnt) St.dummy_clause in + Vec.iter (fun c -> + match c.St.cpremise with + | St.Hyp | St.Local -> assert false + | St.Lemma _ -> Vec.push lemmas c + | St.History l -> + begin match l with + | [] -> assert false + | d :: _ -> + begin match d.St.cpremise with + | St.Lemma _ -> Vec.push lemmas d + | St.Hyp | St.Local | St.History _ -> () + end + end + ) learnt; + (* Number of atoms and clauses *) + let n = St.nb_elt () in + let m = Vec.size tmp + Vec.size hyps + Vec.size lemmas in + (* Actual printing *) let pp s fmt vec = - Format.fprintf fmt "c %s@,%a@," s (Vec.print ~sep:"" aux) vec + Format.fprintf fmt "c %s@,%a@," s (Vec.print ~sep:"" St.pp_dimacs) vec in Format.fprintf fmt "@[p cnf %d %d@,%a%a%a@]@." n m (pp "Local assumptions") tmp (pp "Hypotheses") hyps - (pp "Learnt") learnt + (pp "Lemmas") lemmas end