1 (***********************************************************************)
5 (* Kim Nguyen, LRI UMR8623 *)
6 (* Université Paris-Sud & CNRS *)
8 (* Copyright 2010-2013 Université Paris-Sud and Centre National de la *)
9 (* Recherche Scientifique. All rights reserved. This file is *)
10 (* distributed under the terms of the GNU Lesser General Public *)
11 (* License, with the special exception on linking described in file *)
14 (***********************************************************************)
17 Time-stamp: <Last modified on 2013-04-23 15:45:14 CEST by Kim Nguyen>
23 module Make (T : Tree.S) :
25 val eval : Ata.t -> T.t -> T.node -> T.node list
37 let html tree node i config msg =
38 let config = config.Ata.Config.node in
39 let oldi = config.Ata.round in
40 Html.trace (T.preorder tree node) i oldi
41 "%s<br/>sat: %a<br/>unsat: %a<br/>todo: %around: %i<br/>"
43 StateSet.print config.Ata.sat
44 StateSet.print config.Ata.unsat
45 (Ata.TransList.print ~sep:"<br/>") config.Ata.todo oldi
48 type cache = StateSet.t Cache.N1.t
49 let get c t n = Cache.N1.find c (T.preorder t n)
52 v.Ata.Config.node.Ata.round <- i;
53 Cache.N1.add c (T.preorder t n) v
56 let top_down_run auto tree node cache _i =
57 let redo = ref false in
59 if node != T.nil then begin
60 let parent = T.parent tree node in
61 let fc = T.first_child tree node in
62 let ns = T.next_sibling tree node in
63 let tag = T.tag tree node in
65 let c = get cache tree node in
66 if c == Cache.N1.dummy cache then
68 { c.Ata.Config.node with
69 Ata.todo = Ata.get_trans auto tag auto.Ata.states;
70 summary = Ata.node_summary
71 (node == T.first_child tree parent) (* is_left *)
72 (node == T.next_sibling tree parent) (* is_right *)
73 (fc != T.nil) (* has_left *)
74 (ns != T.nil) (* has_right *)
75 (T.kind tree node) (* kind *)
80 TRACE(html tree node _i config0 "Entering node");
82 let ps = get cache tree parent in
83 let fcs = get cache tree fc in
84 let nss = get cache tree ns in
85 let config1 = Ata.eval_trans auto fcs nss ps config0 in
87 TRACE(html tree node _i config1 "Updating transitions");
89 if config0 != config1 then set cache tree node config1 _i;
91 let fcs1 = get cache tree fc in
92 let config2 = Ata.eval_trans auto fcs1 nss ps config1 in
94 TRACE(html tree node _i config2 "Updating transitions (after first-child)");
96 if config1 != config2 then set cache tree node config2 _i;
98 let config3 = Ata.eval_trans auto fcs1 (get cache tree ns) ps config2 in
100 TRACE(html tree node _i config3 "Updating transitions (after next-sibling)");
102 if config2 != config3 then set cache tree node config3 _i;
103 (* We do set the redo flat if : *)
105 config0 == config3 (* did not gain any new information *)
106 || !redo (* already set *)
107 || Ata.TransList.nil == config3.Ata.Config.node.Ata.todo ) (* no more transition to check *)
114 let get_results auto tree node cache =
115 let rec loop node acc =
116 if node == T.nil then acc
118 let acc0 = loop (T.next_sibling tree node) acc in
119 let acc1 = loop (T.first_child tree node) acc0 in
121 if StateSet.intersect
122 (get cache tree node).Ata.Config.node.Ata.sat
123 auto.Ata.selection_states then node::acc1
128 let eval auto tree node =
129 let cache = Cache.N1.create
130 (Ata.Config.make { Ata.sat = StateSet.empty;
131 Ata.unsat = StateSet.empty;
132 Ata.todo = Ata.TransList.nil;
133 Ata.summary = Ata.dummy_summary;
137 let redo = ref true in
142 Ata.reset auto; (* prevents the .cache2 and .cache4 memoization tables from growing too much *)
143 redo := top_down_run auto tree node cache !iter;
146 at_exit (fun () -> eprintf "@[STATS: %i iterations@]@." !iter);
147 let r = get_results auto tree node cache in
148 TRACE(Html.gen_trace (module T : Tree.S with type t = T.t) (tree));