1 (***********************************************************************)
5 (* Lucca Hirschi, LRI UMR8623 *)
6 (* Université Paris-Sud & CNRS *)
8 (* Copyright 2010-2012 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 (***********************************************************************)
20 let compare n1 n2 = n1 - n2
21 let equal n1 n2 = n1 = n2
24 module NodeHash = Hashtbl.Make (Node)
26 type t = (StateSet.t*StateSet.t) NodeHash.t
27 (** Map from node to query and recognizing states *)
28 (* Note that we do not consider the nil nodes *)
31 exception Over_max_fail
34 (* Build the Oracle *)
35 let rec bu_oracle asta run tree tnode =
37 let set = (StateSet.empty,StateSet.empty) in
38 NodeHash.add run node set
39 and node = Tree.preorder tree tnode in
40 if (Tree.is_leaf tree tnode)
42 if not (tnode == Tree.nil)
47 let tfnode = Tree.first_child tree tnode
48 and tnnode = Tree.next_sibling tree tnode in
50 bu_oracle asta run tree tfnode;
51 bu_oracle asta run tree tnnode;
53 (Tree.preorder tree tfnode, Tree.preorder tree tnnode) in
55 try NodeHash.find run n
56 with Not_found -> (StateSet.empty,StateSet.empty) in
57 let (_,qf),(_,qn) = q_rec fnode,q_rec nnode in
58 let lab = Tree.tag tree tnode in
59 let _,list_tr = Asta.transitions_lab asta lab in (* only take reco. *)
60 let result_set = ref StateSet.empty in
61 let rec result = function
64 if Formula.eval_form (qf,qn) form
66 result_set := (StateSet.add q (!result_set));
70 NodeHash.add run node (StateSet.empty, !result_set)
71 (* Do not remove elt in Hahs (the old one would appear) *)
74 (* Build the over-approx. of the maximal run *)
75 let rec bu_over_max asta run tree node =
78 (* Build the maximal run *)
79 let rec tp_max asta run tree node =
82 let compute tree asta =
83 let size_tree = 10000 in (* todo *)
84 let map = NodeHash.create size_tree in
85 bu_oracle asta map tree (Tree.root tree);
86 bu_over_max asta map tree (Tree.root tree);
87 tp_max asta map tree (Tree.root tree);
91 let print_d_set fmt (s_1,s_2) =
92 Format.fprintf fmt "@[<hov 0>(%a,@ %a)@]"
93 StateSet.print s_1 StateSet.print s_2 in
94 let print_map fmt run =
95 let pp = Format.fprintf fmt in
96 if NodeHash.length run = 0
97 then Format.fprintf fmt "ø"
99 NodeHash.iter (fun cle set -> pp "| %i-->%a @ " cle print_d_set set)
101 let print_box fmt run =
102 let pp = Format.fprintf fmt in
103 pp "@[<hov 0>@. # Mapping:@. @[<hov 0>%a@]@]"
106 Format.fprintf fmt "@[<hov 0>##### RUN #####@, %a@]@." print_box run