1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (*****************************************************************************)
30 (* Enrico Tassi <tassi@cs.unibo.it> *)
33 (* This module implements the aciclic graph of universes. *)
35 (*****************************************************************************)
39 (*****************************************************************************)
40 (** switch implementation **)
41 (*****************************************************************************)
43 let fast_implementation = ref true ;;
45 (*****************************************************************************)
47 (*****************************************************************************)
51 (*****************************************************************************)
52 (** Types and default values **)
53 (*****************************************************************************)
55 type universe = int * UriManager.uri option
57 module UniverseType = struct
59 let compare = Pervasives.compare
62 module SOF = Set.Make(UniverseType)
74 module MAL = Map.Make(UniverseType)
76 type arc_type = GE | GT | EQ
78 type bag = entry MAL.t
89 let empty_bag = MAL.empty
91 let are_set_eq s1 s2 =
94 let are_entry_eq v1 v2 =
95 (are_set_eq v1.gt_closure v2.gt_closure ) &&
96 (are_set_eq v1.ge_closure v2.ge_closure ) &&
97 (are_set_eq v1.eq_closure v2.eq_closure ) &&
98 (*(are_set_eq v1.in_gegt_of v2.in_gegt_of ) &&*)
99 (are_set_eq v1.one_s_ge v2.one_s_ge ) &&
100 (are_set_eq v1.one_s_gt v2.one_s_gt ) &&
101 (are_set_eq v1.one_s_eq v2.one_s_eq )
103 let are_ugraph_eq = MAL.equal are_entry_eq
105 (*****************************************************************************)
106 (** Pretty printings **)
107 (*****************************************************************************)
109 let string_of_universe (i,u) =
112 "(" ^ ((string_of_int i) ^ "," ^ (UriManager.string_of_uri u) ^ ")")
113 | None -> "(" ^ (string_of_int i) ^ ",None)"
115 let string_of_universe_set l =
116 SOF.fold (fun x s -> s ^ (string_of_universe x) ^ " ") l ""
118 let string_of_node n =
120 "eq_c: " ^ (string_of_universe_set n.eq_closure) ^ "; " ^
121 "ge_c: " ^ (string_of_universe_set n.ge_closure) ^ "; " ^
122 "gt_c: " ^ (string_of_universe_set n.gt_closure) ^ "; " ^
123 "i_gegt: " ^ (string_of_universe_set n.in_gegt_of) ^ "}\n"
125 let string_of_arc (a,u,v) =
126 (string_of_universe u) ^ " " ^ a ^ " " ^ (string_of_universe v)
128 let string_of_mal m =
131 rc := !rc ^ sprintf "%s --> %s" (string_of_universe k)
132 (string_of_node v)) m;
135 let string_of_bag b =
138 (*****************************************************************************)
140 (*****************************************************************************)
141 let time_spent = ref 0.0;;
142 let partial = ref 0.0 ;;
144 let reset_spent_time () = time_spent := 0.0;;
145 let get_spent_time () = !time_spent ;;
146 let begin_spending () =
147 (*assert (!partial = 0.0);*)
148 partial := Unix.gettimeofday ()
151 let end_spending () =
152 assert (!partial > 0.0);
153 let interval = (Unix.gettimeofday ()) -. !partial in
155 time_spent := !time_spent +. interval
159 (*****************************************************************************)
161 (*****************************************************************************)
168 Not_found -> empty_entry
170 (* FIXME: May be faster if we make it by hand *)
171 let merge_closures f nodes m =
172 SOF.fold (fun x i -> SOF.union (f (repr x m)) i ) nodes SOF.empty
175 (*****************************************************************************)
176 (** _fats implementation **)
177 (*****************************************************************************)
179 let rec closure_of_fast ru m =
180 let eq_c = closure_eq_fast ru m in
181 let ge_c = closure_ge_fast ru m in
182 let gt_c = closure_gt_fast ru m in
187 in_gegt_of = ru.in_gegt_of;
188 one_s_eq = ru.one_s_eq;
189 one_s_ge = ru.one_s_ge;
190 one_s_gt = ru.one_s_gt
193 and closure_eq_fast ru m =
195 let j = ru.one_s_eq in
196 let _Uj = merge_closures (fun x -> x.eq_closure) j m in
197 let one_step_eq = ru.one_s_eq in
198 (SOF.union one_step_eq _Uj)
202 and closure_ge_fast ru m =
204 let j = SOF.union ru.one_s_ge (SOF.union ru.one_s_gt ru.one_s_eq) in
205 let _Uj = merge_closures (fun x -> x.ge_closure) j m in
211 and closure_gt_fast ru m =
213 let j = ru.one_s_gt in
214 let k = ru.one_s_ge in
215 let l = ru.one_s_eq in
216 let _Uj = merge_closures (fun x -> x.ge_closure) j m in
217 let _Uk = merge_closures (fun x -> x.gt_closure) k m in
218 let _Ul = merge_closures (fun x -> x.gt_closure) l m in
219 let one_step_gt = ru.one_s_gt in
220 (SOF.union (SOF.union (SOF.union _Ul one_step_gt) _Uk) _Uj)
224 and print_rec_status u ru =
225 print_endline ("Aggiusto " ^ (string_of_universe u) ^
226 "e ottengo questa chiusura\n " ^ (string_of_node ru))
228 and adjust_fast u m =
230 let gt_c = closure_gt_fast ru m in
231 let ge_c = closure_ge_fast ru m in
232 let eq_c = closure_eq_fast ru m in
233 let changed_eq = not (are_set_eq eq_c ru.eq_closure) in
235 (not (are_set_eq gt_c ru.gt_closure)) ||
236 (not (are_set_eq ge_c ru.ge_closure))
238 if ((not changed_gegt) && (not changed_eq)) then
246 in_gegt_of = ru.in_gegt_of;
247 one_s_eq = ru.one_s_eq;
248 one_s_ge = ru.one_s_ge;
249 one_s_gt = ru.one_s_gt}
251 let m = MAL.add u ru' m in
253 SOF.fold (fun x m -> adjust_fast x m)
254 (SOF.union ru'.eq_closure ru'.in_gegt_of) m
259 m (*adjust_fast u m*)
262 and add_gt_arc_fast u v m =
264 let ru' = {ru with one_s_gt = SOF.add v ru.one_s_gt} in
265 let m' = MAL.add u ru' m in
266 let rv = repr v m' in
267 let rv' = {rv with in_gegt_of = SOF.add u rv.in_gegt_of} in
268 let m'' = MAL.add v rv' m' in
271 and add_ge_arc_fast u v m =
273 let ru' = { ru with one_s_ge = SOF.add v ru.one_s_ge} in
274 let m' = MAL.add u ru' m in
275 let rv = repr v m' in
276 let rv' = {rv with in_gegt_of = SOF.add u rv.in_gegt_of} in
277 let m'' = MAL.add v rv' m' in
280 and add_eq_arc_fast u v m =
283 let ru' = {ru with one_s_eq = SOF.add v ru.one_s_eq} in
284 (*TESI: let ru' = {ru' with in_gegt_of = SOF.add v ru.in_gegt_of} in *)
285 let m' = MAL.add u ru' m in
286 let rv' = {rv with one_s_eq = SOF.add u rv.one_s_eq} in
287 (*TESI: let rv' = {rv' with in_gegt_of = SOF.add u rv.in_gegt_of} in *)
288 let m'' = MAL.add v rv' m' in
289 adjust_fast v (*(adjust_fast u*) m'' (* ) *)
293 (*****************************************************************************)
294 (** safe implementation **)
295 (*****************************************************************************)
300 let j = ru.one_s_eq in
301 let _Uj = merge_closures (fun x -> x.eq_closure) j m in
302 let one_step_eq = ru.one_s_eq in
303 (SOF.union one_step_eq _Uj)
306 let j = SOF.union ru.one_s_ge (SOF.union ru.one_s_gt ru.one_s_eq) in
307 let _Uj = merge_closures (fun x -> x.ge_closure) j m in
312 let j = ru.one_s_gt in
313 let k = ru.one_s_ge in
314 let l = ru.one_s_eq in
315 let _Uj = merge_closures (fun x -> x.ge_closure) j m in
316 let _Uk = merge_closures (fun x -> x.gt_closure) k m in
317 let _Ul = merge_closures (fun x -> x.gt_closure) l m in
318 let one_step_gt = ru.one_s_gt in
319 (SOF.union (SOF.union (SOF.union _Ul one_step_gt) _Uk) _Uj)
325 in_gegt_of = ru.in_gegt_of;
326 one_s_eq = ru.one_s_eq;
327 one_s_ge = ru.one_s_ge;
328 one_s_gt = ru.one_s_gt
331 let rec simple_adjust m =
333 MAL.mapi (fun x _ -> closure_of x m) m
335 if not (are_ugraph_eq m m') then(
340 let add_eq_arc u v m =
343 let ru' = {ru with one_s_eq = SOF.add v ru.one_s_eq} in
344 let m' = MAL.add u ru' m in
345 let rv' = {rv with one_s_eq = SOF.add u rv.one_s_eq} in
346 let m'' = MAL.add v rv' m' in
349 let add_ge_arc u v m =
351 let ru' = { ru with one_s_ge = SOF.add v ru.one_s_ge} in
352 let m' = MAL.add u ru' m in
355 let add_gt_arc u v m =
357 let ru' = {ru with one_s_gt = SOF.add v ru.one_s_gt} in
358 let m' = MAL.add u ru' m in
362 (*****************************************************************************)
363 (** Outhern interface, that chooses between _fast and safe **)
364 (*****************************************************************************)
367 given the 2 nodes plus the current bag, adds the arc, recomputes the
368 closures and returns the new map
370 let add_eq fast u v b =
372 add_eq_arc_fast u v b
377 given the 2 nodes plus the current bag, adds the arc, recomputes the
378 closures and returns the new map
380 let add_ge fast u v b =
382 add_ge_arc_fast u v b
386 given the 2 nodes plus the current bag, adds the arc, recomputes the
387 closures and returns the new map
389 let add_gt fast u v b =
391 add_gt_arc_fast u v b
396 (*****************************************************************************)
397 (** Other real code **)
398 (*****************************************************************************)
400 exception UniverseInconsistency of string
402 let error arc node1 closure_type node2 closure =
403 let s = "\n ===== Universe Inconsistency detected =====\n\n" ^
405 "\t" ^ (string_of_arc arc) ^ "\n" ^
407 "\t" ^ (string_of_universe node1) ^ "\n" ^
408 " is in the " ^ closure_type ^ " closure\n" ^
409 "\t{" ^ (string_of_universe_set closure) ^ "}\n" ^
411 "\t" ^ (string_of_universe node2) ^ "\n\n" ^
412 " ===== Universe Inconsistency detected =====\n" in
414 raise (UniverseInconsistency s)
417 let fill_empty_nodes_with_uri (g, already_contained) l uri =
418 let fill_empty_universe u =
420 (i,None) -> (i,Some uri)
421 | (i,Some _) as u -> u
423 let fill_empty_set s =
424 SOF.fold (fun e s -> SOF.add (fill_empty_universe e) s) s SOF.empty
426 let fill_empty_entry e = {
427 eq_closure = (fill_empty_set e.eq_closure) ;
428 ge_closure = (fill_empty_set e.ge_closure) ;
429 gt_closure = (fill_empty_set e.gt_closure) ;
430 in_gegt_of = (fill_empty_set e.in_gegt_of) ;
431 one_s_eq = (fill_empty_set e.one_s_eq) ;
432 one_s_ge = (fill_empty_set e.one_s_ge) ;
433 one_s_gt = (fill_empty_set e.one_s_gt) ;
438 MAL.add (fill_empty_universe k) (fill_empty_entry v) m) m MAL.empty
440 let l' = List.map fill_empty_universe l in
441 (m', already_contained),l'
444 (*****************************************************************************)
445 (** World interface **)
446 (*****************************************************************************)
448 type universe_graph = bag * UriManager.UriSet.t
449 (* the graph , the cache of already merged ugraphs *)
451 let empty_ugraph = empty_bag, UriManager.UriSet.empty
453 let current_index_anon = ref (-1)
454 let current_index_named = ref (-1)
456 let restart_numbering () = current_index_named := (-1)
458 let fresh ?uri ?id () =
462 current_index_anon := !current_index_anon + 1;
464 | None, Some _ -> assert false
466 current_index_named := !current_index_named + 1;
468 | Some _, Some id -> id
472 let name_universe u uri =
474 | (i, None) -> (i, Some uri)
477 let print_ugraph (g, _) =
478 prerr_endline (string_of_bag g)
480 let add_eq ?(fast=(!fast_implementation)) u v b =
481 (* should we check to no add twice the same?? *)
484 if SOF.mem v ru.gt_closure then
485 error ("EQ",u,v) v "GT" u ru.gt_closure
489 if SOF.mem u rv.gt_closure then
490 error ("EQ",u,v) u "GT" v rv.gt_closure
495 let add_ge ?(fast=(!fast_implementation)) u v b =
496 (* should we check to no add twice the same?? *)
499 if SOF.mem u rv.gt_closure then
500 error ("GE",u,v) u "GT" v rv.gt_closure
504 let add_gt ?(fast=(!fast_implementation)) u v b =
505 (* should we check to no add twice the same?? *)
507 FIXME : check the thesis... no need to check GT and EQ closure since the
508 GE is a superset of both
514 error ("GT",u,v) u "==" v SOF.empty
517 (*if SOF.mem u rv.gt_closure then
518 error ("GT",u,v) u "GT" v rv.gt_closure
521 if SOF.mem u rv.ge_closure then
522 error ("GT",u,v) u "GE" v rv.ge_closure
525 if SOF.mem u rv.eq_closure then
526 error ("GT",u,v) u "EQ" v rv.eq_closure
532 (*****************************************************************************)
533 (** START: Decomment this for performance comparisons **)
534 (*****************************************************************************)
536 let add_eq ?(fast=(!fast_implementation)) u v (b,already_contained) =
537 (*prerr_endline "add_eq";*)
539 let rc = add_eq ~fast u v b in
543 let add_ge ?(fast=(!fast_implementation)) u v (b,already_contained) =
544 (* prerr_endline "add_ge"; *)
546 let rc = add_ge ~fast u v b in
550 let add_gt ?(fast=(!fast_implementation)) u v (b,already_contained) =
551 (* prerr_endline "add_gt"; *)
553 let rc = add_gt ~fast u v b in
558 let profiler_eq = HExtlib.profile "CicUniv.add_eq"
559 let profiler_ge = HExtlib.profile "CicUniv.add_ge"
560 let profiler_gt = HExtlib.profile "CicUniv.add_gt"
561 let add_gt ?fast u v b =
562 profiler_gt.HExtlib.profile (fun _ -> add_gt ?fast u v b) ()
563 let add_ge ?fast u v b =
564 profiler_ge.HExtlib.profile (fun _ -> add_ge ?fast u v b) ()
565 let add_eq ?fast u v b =
566 profiler_eq.HExtlib.profile (fun _ -> add_eq ?fast u v b) ()
569 (*****************************************************************************)
570 (** END: Decomment this for performance comparisons **)
571 (*****************************************************************************)
573 let merge_ugraphs ~base_ugraph ~increment:(increment, uri_of_increment) =
574 let merge_brutal (u,_) v =
581 let m = add_gt k u x in m)
582 (SOF.union v.one_s_gt v.gt_closure)
585 let m = add_ge k u x in m)
586 (SOF.union v.one_s_ge v.ge_closure)
589 let m = add_eq k u x in m)
590 (SOF.union v.one_s_eq v.eq_closure) x)))
593 let base, already_contained = base_ugraph in
594 if MAL.is_empty base then
597 MAL.is_empty (fst increment) ||
598 UriManager.UriSet.mem uri_of_increment already_contained
602 fst (merge_brutal increment base_ugraph),
603 UriManager.UriSet.add uri_of_increment already_contained
605 (* profiling code; WARNING: the time spent during profiling can be
606 greater than the profiled time
607 let profiler_merge = HExtlib.profile "CicUniv.merge_ugraphs"
608 let merge_ugraphs ~base_ugraph ~increment =
609 profiler_merge.HExtlib.profile
610 (fun _ -> merge_ugraphs ~base_ugraph ~increment) ()
613 (*****************************************************************************)
614 (** Xml sesialization and parsing **)
615 (*****************************************************************************)
617 let xml_of_universe name u =
621 None,"id",(string_of_int i) ;
622 None,"uri",(UriManager.string_of_uri u)]
624 raise (Failure "we can serialize only universes with uri")
628 List.map (xml_of_universe "node") (SOF.elements s)
630 List.fold_left (fun s x -> [< s ; x >] ) [<>] l
632 let xml_of_entry_content e =
633 let stream_of_field f name =
634 let eq_c = xml_of_set f in
636 Xml.xml_nempty name [] eq_c
641 (stream_of_field e.eq_closure "eq_closure");
642 (stream_of_field e.gt_closure "gt_closure");
643 (stream_of_field e.ge_closure "ge_closure");
644 (stream_of_field e.in_gegt_of "in_gegt_of");
645 (stream_of_field e.one_s_eq "one_s_eq");
646 (stream_of_field e.one_s_gt "one_s_gt");
647 (stream_of_field e.one_s_ge "one_s_ge")
650 let xml_of_entry u e =
656 raise (Failure "we can serialize only universes (entry) with uri")
658 let ent = Xml.xml_nempty "entry" [
659 None,"id",(string_of_int i) ;
660 None,"uri",(UriManager.string_of_uri u'')] in
661 let content = xml_of_entry_content e in
664 let write_xml_of_ugraph filename (m,_) l =
667 Xml.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
668 Xml.xml_nempty "ugraph" []
669 ([< (MAL.fold ( fun k v s -> [< s ; (xml_of_entry k v) >]) m [<>]) ;
671 (fun s u -> [< s ; xml_of_universe "owned_node" u >]) [<>] l) >])>]
673 Xml.pp ~gzip:true tokens (Some filename)
678 let rec clean_ugraph (m,already_contained) f =
680 MAL.fold (fun k v x -> if (f k) then MAL.add k v x else x ) m MAL.empty in
681 let m'' = MAL.fold (fun k v x ->
683 eq_closure = SOF.filter f v.eq_closure;
684 ge_closure = SOF.filter f v.ge_closure;
685 gt_closure = SOF.filter f v.gt_closure;
686 in_gegt_of = SOF.filter f v.in_gegt_of;
687 one_s_eq = SOF.filter f v.one_s_eq;
688 one_s_ge = SOF.filter f v.one_s_ge;
689 one_s_gt = SOF.filter f v.one_s_gt
691 MAL.add k v' x ) m' MAL.empty in
693 MAL.fold (fun k v l -> if v = empty_entry && not(f k) then
695 k::l end else l) m'' []
699 (m'', already_contained) (fun u -> (f u) && not (List.mem u e_l))
702 (fun k v x -> if v <> empty_entry then MAL.add k v x else x)
706 let clean_ugraph g l =
707 clean_ugraph g (fun u -> List.mem u l)
711 "ge_closure" -> (fun e u->{e with ge_closure=SOF.add u e.ge_closure})
712 | "gt_closure" -> (fun e u->{e with gt_closure=SOF.add u e.gt_closure})
713 | "eq_closure" -> (fun e u->{e with eq_closure=SOF.add u e.eq_closure})
714 | "in_gegt_of" -> (fun e u->{e with in_gegt_of =SOF.add u e.in_gegt_of})
715 | "one_s_ge" -> (fun e u->{e with one_s_ge =SOF.add u e.one_s_ge})
716 | "one_s_gt" -> (fun e u->{e with one_s_gt =SOF.add u e.one_s_gt})
717 | "one_s_eq" -> (fun e u->{e with one_s_eq =SOF.add u e.one_s_eq})
718 | s -> raise (Failure ("unsupported tag " ^ s))
722 let module XPP = XmlPushParser in
723 let current_node = ref (0,None) in
724 let current_entry = ref empty_entry in
725 let current_assign = ref (assigner_of "in_gegt_of") in
726 { XPP.default_callbacks with
727 XPP.end_element = Some( fun name ->
730 m := MAL.add !current_node !current_entry !m;
731 current_entry := empty_entry
734 XPP.start_element = Some( fun name attlist ->
738 let id = List.assoc "id" attlist in
739 let uri = List.assoc "uri" attlist in
740 current_node := (int_of_string id,Some (UriManager.uri_of_string uri))
742 let id = int_of_string (List.assoc "id" attlist) in
743 let uri = List.assoc "uri" attlist in
744 current_entry := !current_assign !current_entry
745 (id,Some (UriManager.uri_of_string uri))
747 let id = int_of_string (List.assoc "id" attlist) in
748 let uri = List.assoc "uri" attlist in
749 l := (id,Some (UriManager.uri_of_string uri)) :: !l
750 | s -> current_assign := assigner_of s
755 let ugraph_and_univlist_of_xml filename =
756 let module XPP = XmlPushParser in
757 let result_map = ref MAL.empty in
758 let result_list = ref [] in
759 let cb = cb_factory result_map result_list in
760 let xml_parser = XPP.create_parser cb in
761 let xml_source = `Gzip_file filename in
762 (try XPP.parse xml_parser xml_source
763 with (XPP.Parse_error err) as exn -> raise exn);
764 (!result_map,UriManager.UriSet.empty), !result_list
767 (*****************************************************************************)
768 (** the main, only for testing **)
769 (*****************************************************************************)
773 type arc = Ge | Gt | Eq ;;
775 let randomize_actionlist n m =
776 let ge_percent = 0.7 in
777 let gt_percent = 0.15 in
779 let node1 = Random.int m in
780 let node2 = Random.int m in
782 let r = Random.float 1.0 in
783 if r < ge_percent then
785 else (if r < (ge_percent +. gt_percent) then
795 | n -> (random_step ())::(aux (n-1))
799 let print_action_list l =
800 let string_of_step (op,node1,node2) =
805 "," ^ (string_of_int node1) ^ "," ^ (string_of_int node2)
811 ";" ^ (string_of_step a) ^ (aux tl)
814 let l_body = (String.length body) - 1 in
815 prerr_endline ("[" ^ (String.sub body 1 l_body))
818 let d_print_endline = if debug then print_endline else ignore
819 let d_print_ugraph = if debug then print_ugraph else ignore
822 (if Array.length Sys.argv < 2 then
823 prerr_endline ("Usage " ^ Sys.argv.(0) ^ " max_edges max_nodes"));
825 let max_edges = int_of_string Sys.argv.(1) in
826 let max_nodes = int_of_string Sys.argv.(2) in
827 let action_listR = randomize_actionlist max_edges max_nodes in
829 let action_list = [Ge,1,4;Ge,2,6;Ge,1,1;Eq,6,4;Gt,6,3] in
830 let action_list = action_listR in
832 print_action_list action_list;
833 let prform_step ?(fast=false) (t,u,v) g =
845 let g' = f ~fast (u,None) (v,None) g in
846 (*print_ugraph g' ;*)
849 let fail = ref false in
850 let time1 = Unix.gettimeofday () in
851 let n_safe = ref 0 in
854 d_print_endline "SAFE";
857 n_safe := !n_safe + 1;
859 ) empty_ugraph action_list
861 UniverseInconsistency s -> fail:=true;empty_bag
863 let time2 = Unix.gettimeofday () in
864 d_print_ugraph g_safe;
865 let time3 = Unix.gettimeofday () in
866 let n_test = ref 0 in
869 d_print_endline "FAST";
872 n_test := !n_test + 1;
873 prform_step ~fast:true e g
874 ) empty_ugraph action_list
876 UniverseInconsistency s -> empty_bag
878 let time4 = Unix.gettimeofday () in
879 d_print_ugraph g_test;
880 if are_ugraph_eq g_safe g_test && !n_test = !n_safe then
885 if e = Eq then s+1 else s
891 if e = Gt then s+1 else s
894 let num_ge = max_edges - num_gt - num_eq in
895 let time_fast = (time4 -. time3) in
896 let time_safe = (time2 -. time1) in
897 let gap = ((time_safe -. time_fast) *. 100.0) /. time_safe in
898 let fail = if !fail then 1 else 0 in
901 "OK %d safe %1.4f fast %1.4f %% %1.2f #eq %d #gt %d #ge %d %d"
902 fail time_safe time_fast gap num_eq num_gt num_ge !n_safe);
907 print_endline "FAIL";
920 i, Some (UriManager.uri_of_string (UriManager.string_of_uri uri))
922 let recons_entry entry =
924 SOF.fold (fun univ set -> SOF.add (recons_univ univ) set) set SOF.empty
927 eq_closure = recons_set entry.eq_closure;
928 ge_closure = recons_set entry.ge_closure;
929 gt_closure = recons_set entry.gt_closure;
930 in_gegt_of = recons_set entry.in_gegt_of;
931 one_s_eq = recons_set entry.one_s_eq;
932 one_s_ge = recons_set entry.one_s_ge;
933 one_s_gt = recons_set entry.one_s_gt;
936 let recons_graph (graph,uriset) =
938 (fun universe entry map ->
939 MAL.add (recons_univ universe) (recons_entry entry) map)
942 UriManager.UriSet.fold
944 UriManager.UriSet.add
945 (UriManager.uri_of_string (UriManager.string_of_uri u)) acc)
946 uriset UriManager.UriSet.empty
950 | (_,None) -> raise (UniverseInconsistency "This universe graph has a hole")
953 let assert_univs_have_uri (graph,_) univlist =
955 SOF.iter (fun u -> assert_univ u) s
958 assert_set e.eq_closure;
959 assert_set e.ge_closure;
960 assert_set e.gt_closure;
961 assert_set e.in_gegt_of;
962 assert_set e.one_s_eq;
963 assert_set e.one_s_ge;
964 assert_set e.one_s_gt;
966 MAL.iter (fun k v -> assert_univ k; assert_entry v)graph;
967 List.iter assert_univ univlist
971 | (id1, Some uri1),(id2, Some uri2) ->
972 id1 = id2 && UriManager.eq uri1 uri2
973 | (id1, None),(id2, None) -> id1 = id2
976 let compare (id1, uri1) (id2, uri2) =
977 let cmp = id1 - id2 in
982 | None, Some _ -> ~-1
983 | Some uri1, Some uri2 -> UriManager.compare uri1 uri2