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-18 17:36:06 CEST by Kim Nguyen>
23 module Make (T : Tree.S) :
25 val eval : Ata.t -> T.t -> T.node -> T.node list
39 type cache = StateSet.t Cache.N1.t
40 let get c t n = Cache.N1.find c (T.preorder t n)
42 let set c t n v = Cache.N1.add c (T.preorder t n) v
45 let top_down_run auto tree node cache _i =
46 let redo = ref false in
48 if node != T.nil then begin
49 let parent = T.parent tree node in
50 let fc = T.first_child tree node in
51 let ns = T.next_sibling tree node in
52 let tag = T.tag tree node in
54 let c = get cache tree node in
55 if c == Cache.N1.dummy cache then
56 { c with Ata.todo = Ata.get_trans auto tag auto.Ata.states }
61 TRACE(Html.trace (T.preorder tree node) _i "Config0<br/>sat: %a<br/>unsat: %a<br/>todo: %a<br/>"
62 StateSet.print config0.Ata.sat
63 StateSet.print config0.Ata.unsat
64 (Ata.TransList.print ~sep:"<br/>") config0.Ata.todo)
67 let ps = get cache tree parent in
68 let fcs = get cache tree fc in
69 let nss = get cache tree ns in
70 let is_left = node == T.first_child tree parent
71 and is_right = node == T.next_sibling tree parent
72 and has_left = fc != T.nil
73 and has_right = ns != T.nil
74 and kind = T.kind tree node
77 Ata.eval_trans2 auto fcs nss ps config0
78 is_left is_right has_left has_right kind
81 TRACE(Html.trace (T.preorder tree node) _i "Config1<br/>sat: %a<br/>unsat: %a<br/>todo: %a<br/>"
82 StateSet.print config1.Ata.sat
83 StateSet.print config1.Ata.unsat
84 (Ata.TransList.print ~sep:"<br/>") config1.Ata.todo)
86 if not (Ata.eq_config config0 config1) then set cache tree node config1;
88 let fcs1 = get cache tree fc in
92 is_left is_right has_left has_right kind
95 TRACE(Html.trace (T.preorder tree node) _i "Config2<br/>sat: %a<br/>unsat: %a<br/>todo: %a<br/>"
96 StateSet.print config2.Ata.sat
97 StateSet.print config2.Ata.unsat
98 (Ata.TransList.print ~sep:"<br/>") config2.Ata.todo)
101 if not (Ata.eq_config config1 config2) then set cache tree node config2;
105 fcs1 (get cache tree ns) ps config2
106 is_left is_right has_left has_right kind
109 TRACE(Html.trace (T.preorder tree node) _i "Config3<br/>sat: %a<br/>unsat: %a<br/>todo: %a<br/>"
110 StateSet.print config3.Ata.sat
111 StateSet.print config3.Ata.unsat
112 (Ata.TransList.print ~sep:"<br/>") config3.Ata.todo)
114 if not (Ata.eq_config config2 config3) then set cache tree node config3;
115 (* We do set the redo flat if : *)
117 !redo (* already set *)
118 || (Ata.TransList.nil == config3.Ata.todo) (* no more transition to check *)
119 || (Ata.eq_config config0 config3) (* did not gain any new information *)
127 let get_results auto tree node cache =
128 let rec loop node acc =
129 if node == T.nil then acc
131 let acc0 = loop (T.next_sibling tree node) acc in
132 let acc1 = loop (T.first_child tree node) acc0 in
134 if StateSet.intersect (get cache tree node).Ata.sat auto.Ata.selection_states then
141 let eval auto tree node =
142 let cache = Cache.N1.create { Ata.sat = StateSet.empty;
143 Ata.unsat = StateSet.empty;
144 Ata.todo = Ata.TransList.nil }
146 let redo = ref true in
151 redo := top_down_run auto tree node cache !iter;
154 at_exit (fun () -> eprintf "INFO: %i iterations\n" !iter);
155 let r = get_results auto tree node cache in
156 TRACE(Html.gen_trace (module T : Tree.S with type t = T.t) (tree));