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-03-13 14:56:29 CET by Kim Nguyen>
24 module Make (T : Tree.Sig.S) = struct
26 type cache = (int, StateSet.t) Hashtbl.t
29 try Hashtbl.find c (T.preorder t n)
30 with Not_found -> StateSet.empty
32 let set c t n v = Hashtbl.replace c (T.preorder t n) v
33 let eval_form phi tree node fcs nss ps ss =
35 match Ata.SFormula.expr phi with
37 | Formula.False -> false
39 let p, b, q = Ata.Atom.node a in
43 | First_child -> StateSet.mem q fcs
44 | Next_sibling -> StateSet.mem q nss
45 | Parent | Previous_sibling -> StateSet.mem q ps
46 | Stay -> StateSet.mem q ss
48 node == (T.first_child tree (T.parent tree node))
50 node == (T.next_sibling tree (T.parent tree node))
51 | Is k -> k == (T.kind tree node)
53 T.nil != T.first_child tree node
55 T.nil != T.next_sibling tree node
57 if Ata.is_move p && (not b) then
58 eprintf "Warning: Invalid negative atom %a" Ata.Atom.print a;
60 | Formula.And(phi1, phi2) -> loop phi1 && loop phi2
61 | Formula.Or (phi1, phi2) -> loop phi1 || loop phi2
65 let eval_trans l tree node fcs nss ps ss acc =
66 List.fold_left (fun (acct, accs) ((q, phi) as trs) ->
67 if StateSet.mem q accs then (acct, accs) else
68 if eval_form phi tree node fcs nss ps ss then
69 (acct, StateSet.add q accs)
74 let top_down_run auto tree node cache _i =
75 let redo = ref false in
77 if node != T.nil then begin
78 let parent = T.parent tree node in
79 let fc = T.first_child tree node in
80 let ns = T.next_sibling tree node in
81 let states0 = get cache tree node in
82 let tag = T.tag tree node in
83 let trans0 = Ata.get_trans auto auto.Ata.states tag in
84 let ps = get cache tree parent in
85 let fcs = get cache tree fc in
86 let nss = get cache tree ns in
88 eval_trans trans0 tree node fcs nss ps states0 states0
90 if states1 != states0 then set cache tree node states1;
92 let fcs1 = get cache tree fc in
94 eval_trans trans1 tree node fcs1 nss ps states1 states1
96 if states2 != states1 then set cache tree node states2;
99 eval_trans trans2 tree node fcs1 (get cache tree ns) ps states2 states2
101 if states3 != states2 then set cache tree node states3;
102 if states0 != states3 && (not !redo) then redo := true
108 let get_results auto tree node cache =
109 let rec loop node acc =
110 if node == T.nil then acc
112 let acc0 = loop (T.next_sibling tree node) acc in
113 let acc1 = loop (T.first_child tree node) acc0 in
115 if StateSet.intersect (get cache tree node) auto.Ata.selection_states then
122 let eval auto tree node =
123 let cache = Hashtbl.create 511 in
124 let redo = ref true in
127 redo := top_down_run auto tree node cache !iter;
130 get_results auto tree node cache