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 (*****************************************************************************)
147 Not_found -> empty_entry
149 (* FIXME: May be faster if we make it by hand *)
150 let merge_closures f nodes m =
151 SOF.fold (fun x i -> SOF.union (f (repr x m)) i ) nodes SOF.empty
153 (*****************************************************************************)
155 (*****************************************************************************)
156 let time_spent = ref 0.0;;
157 let partial = ref 0.0 ;;
159 let reset_spent_time () = time_spent := 0.0;;
160 let get_spent_time () = !time_spent ;;
161 let begin_spending () =
162 (*assert (!partial = 0.0);*)
163 partial := Unix.gettimeofday ()
166 let end_spending () =
167 assert (!partial > 0.0);
168 let interval = (Unix.gettimeofday ()) -. !partial in
170 time_spent := !time_spent +. interval
174 (*****************************************************************************)
175 (** _fats implementation **)
176 (*****************************************************************************)
178 let rec closure_of_fast ru m =
179 let eq_c = closure_eq_fast ru m in
180 let ge_c = closure_ge_fast ru m in
181 let gt_c = closure_gt_fast ru m in
186 in_gegt_of = ru.in_gegt_of;
187 one_s_eq = ru.one_s_eq;
188 one_s_ge = ru.one_s_ge;
189 one_s_gt = ru.one_s_gt
192 and closure_eq_fast ru m =
194 let j = ru.one_s_eq in
195 let _Uj = merge_closures (fun x -> x.eq_closure) j m in
196 let one_step_eq = ru.one_s_eq in
197 (SOF.union one_step_eq _Uj)
201 and closure_ge_fast ru m =
203 let j = SOF.union ru.one_s_ge (SOF.union ru.one_s_gt ru.one_s_eq) in
204 let _Uj = merge_closures (fun x -> x.ge_closure) j m in
210 and closure_gt_fast ru m =
212 let j = ru.one_s_gt in
213 let k = ru.one_s_ge in
214 let l = ru.one_s_eq in
215 let _Uj = merge_closures (fun x -> x.ge_closure) j m in
216 let _Uk = merge_closures (fun x -> x.gt_closure) k m in
217 let _Ul = merge_closures (fun x -> x.gt_closure) l m in
218 let one_step_gt = ru.one_s_gt in
219 (SOF.union (SOF.union (SOF.union _Ul one_step_gt) _Uk) _Uj)
223 and print_rec_status u ru =
224 print_endline ("Aggiusto " ^ (string_of_universe u) ^
225 "e ottengo questa chiusura\n " ^ (string_of_node ru))
227 and adjust_fast u m =
229 let gt_c = closure_gt_fast ru m in
230 let ge_c = closure_ge_fast ru m in
231 let eq_c = closure_eq_fast ru m in
232 let changed_eq = not (are_set_eq eq_c ru.eq_closure) in
234 (not (are_set_eq gt_c ru.gt_closure)) ||
235 (not (are_set_eq ge_c ru.ge_closure))
237 if ((not changed_gegt) && (not changed_eq)) then
245 in_gegt_of = ru.in_gegt_of;
246 one_s_eq = ru.one_s_eq;
247 one_s_ge = ru.one_s_ge;
248 one_s_gt = ru.one_s_gt}
250 let m = MAL.add u ru' m in
252 SOF.fold (fun x m -> adjust_fast x m)
253 (SOF.union ru'.eq_closure ru'.in_gegt_of) m
258 m (*adjust_fast u m*)
261 and add_gt_arc_fast u v m =
263 let ru' = {ru with one_s_gt = SOF.add v ru.one_s_gt} in
264 let m' = MAL.add u ru' m in
265 let rv = repr v m' in
266 let rv' = {rv with in_gegt_of = SOF.add u rv.in_gegt_of} in
267 let m'' = MAL.add v rv' m' in
270 and add_ge_arc_fast u v m =
272 let ru' = { ru with one_s_ge = SOF.add v ru.one_s_ge} in
273 let m' = MAL.add u ru' m in
274 let rv = repr v m' in
275 let rv' = {rv with in_gegt_of = SOF.add u rv.in_gegt_of} in
276 let m'' = MAL.add v rv' m' in
279 and add_eq_arc_fast u v m =
282 let ru' = {ru with one_s_eq = SOF.add v ru.one_s_eq} in
283 (*TESI: let ru' = {ru' with in_gegt_of = SOF.add v ru.in_gegt_of} in *)
284 let m' = MAL.add u ru' m in
285 let rv' = {rv with one_s_eq = SOF.add u rv.one_s_eq} in
286 (*TESI: let rv' = {rv' with in_gegt_of = SOF.add u rv.in_gegt_of} in *)
287 let m'' = MAL.add v rv' m' in
288 adjust_fast v (*(adjust_fast u*) m'' (* ) *)
292 (*****************************************************************************)
293 (** safe implementation **)
294 (*****************************************************************************)
299 let j = ru.one_s_eq in
300 let _Uj = merge_closures (fun x -> x.eq_closure) j m in
301 let one_step_eq = ru.one_s_eq in
302 (SOF.union one_step_eq _Uj)
305 let j = SOF.union ru.one_s_ge (SOF.union ru.one_s_gt ru.one_s_eq) in
306 let _Uj = merge_closures (fun x -> x.ge_closure) j m in
311 let j = ru.one_s_gt in
312 let k = ru.one_s_ge in
313 let l = ru.one_s_eq in
314 let _Uj = merge_closures (fun x -> x.ge_closure) j m in
315 let _Uk = merge_closures (fun x -> x.gt_closure) k m in
316 let _Ul = merge_closures (fun x -> x.gt_closure) l m in
317 let one_step_gt = ru.one_s_gt in
318 (SOF.union (SOF.union (SOF.union _Ul one_step_gt) _Uk) _Uj)
324 in_gegt_of = ru.in_gegt_of;
325 one_s_eq = ru.one_s_eq;
326 one_s_ge = ru.one_s_ge;
327 one_s_gt = ru.one_s_gt
330 let rec simple_adjust m =
332 MAL.mapi (fun x _ -> closure_of x m) m
334 if not (are_ugraph_eq m m') then(
339 let add_eq_arc u v m =
342 let ru' = {ru with one_s_eq = SOF.add v ru.one_s_eq} in
343 let m' = MAL.add u ru' m in
344 let rv' = {rv with one_s_eq = SOF.add u rv.one_s_eq} in
345 let m'' = MAL.add v rv' m' in
348 let add_ge_arc u v m =
350 let ru' = { ru with one_s_ge = SOF.add v ru.one_s_ge} in
351 let m' = MAL.add u ru' m in
354 let add_gt_arc u v m =
356 let ru' = {ru with one_s_gt = SOF.add v ru.one_s_gt} in
357 let m' = MAL.add u ru' m in
361 (*****************************************************************************)
362 (** Outhern interface, that chooses between _fast and safe **)
363 (*****************************************************************************)
366 given the 2 nodes plus the current bag, adds the arc, recomputes the
367 closures and returns the new map
369 let add_eq fast u v b =
371 add_eq_arc_fast u v b
376 given the 2 nodes plus the current bag, adds the arc, recomputes the
377 closures and returns the new map
379 let add_ge fast u v b =
381 add_ge_arc_fast u v b
385 given the 2 nodes plus the current bag, adds the arc, recomputes the
386 closures and returns the new map
388 let add_gt fast u v b =
390 add_gt_arc_fast u v b
395 (*****************************************************************************)
396 (** Other real code **)
397 (*****************************************************************************)
399 exception UniverseInconsistency of string
401 let error arc node1 closure_type node2 closure =
402 let s = "\n ===== Universe Inconsistency detected =====\n\n" ^
404 "\t" ^ (string_of_arc arc) ^ "\n" ^
406 "\t" ^ (string_of_universe node1) ^ "\n" ^
407 " is in the " ^ closure_type ^ " closure\n" ^
408 "\t{" ^ (string_of_universe_set closure) ^ "}\n" ^
410 "\t" ^ (string_of_universe node2) ^ "\n\n" ^
411 " ===== Universe Inconsistency detected =====\n" in
413 raise (UniverseInconsistency s)
416 let fill_empty_nodes_with_uri (g, already_contained) l uri =
417 let fill_empty_universe u =
419 (i,None) -> (i,Some uri)
420 | (i,Some _) as u -> u
422 let fill_empty_set s =
423 SOF.fold (fun e s -> SOF.add (fill_empty_universe e) s) s SOF.empty
425 let fill_empty_entry e = {
426 eq_closure = (fill_empty_set e.eq_closure) ;
427 ge_closure = (fill_empty_set e.ge_closure) ;
428 gt_closure = (fill_empty_set e.gt_closure) ;
429 in_gegt_of = (fill_empty_set e.in_gegt_of) ;
430 one_s_eq = (fill_empty_set e.one_s_eq) ;
431 one_s_ge = (fill_empty_set e.one_s_ge) ;
432 one_s_gt = (fill_empty_set e.one_s_gt) ;
437 MAL.add (fill_empty_universe k) (fill_empty_entry v) m) m MAL.empty
439 let l' = List.map fill_empty_universe l in
440 (m', already_contained),l'
443 (*****************************************************************************)
444 (** World interface **)
445 (*****************************************************************************)
447 type universe_graph = bag * UriManager.UriSet.t
448 (* the graph , the cache of already merged ugraphs *)
450 let empty_ugraph = empty_bag, UriManager.UriSet.empty
452 let current_index_anon = ref (-1)
453 let current_index_named = ref (-1)
455 let restart_numbering () = current_index_named := (-1)
457 let fresh ?uri ?id () =
461 current_index_anon := !current_index_anon + 1;
463 | None, Some _ -> assert false
465 current_index_named := !current_index_named + 1;
467 | Some _, Some id -> id
471 let name_universe u uri =
473 | (i, None) -> (i, Some uri)
476 let print_ugraph (g, _) =
477 prerr_endline (string_of_bag g)
479 let add_eq ?(fast=(!fast_implementation)) u v b =
480 (* should we check to no add twice the same?? *)
483 if SOF.mem v ru.gt_closure then
484 error ("EQ",u,v) v "GT" u ru.gt_closure
488 if SOF.mem u rv.gt_closure then
489 error ("EQ",u,v) u "GT" v rv.gt_closure
494 let add_ge ?(fast=(!fast_implementation)) u v b =
495 (* should we check to no add twice the same?? *)
498 if SOF.mem u rv.gt_closure then
499 error ("GE",u,v) u "GT" v rv.gt_closure
503 let add_gt ?(fast=(!fast_implementation)) u v b =
504 (* should we check to no add twice the same?? *)
506 FIXME : check the thesis... no need to check GT and EQ closure since the
507 GE is a superset of both
513 error ("GT",u,v) u "==" v SOF.empty
516 (*if SOF.mem u rv.gt_closure then
517 error ("GT",u,v) u "GT" v rv.gt_closure
520 if SOF.mem u rv.ge_closure then
521 error ("GT",u,v) u "GE" v rv.ge_closure
524 if SOF.mem u rv.eq_closure then
525 error ("GT",u,v) u "EQ" v rv.eq_closure
531 (*****************************************************************************)
532 (** START: Decomment this for performance comparisons **)
533 (*****************************************************************************)
535 let add_eq ?(fast=(!fast_implementation)) u v (b,already_contained) =
536 (*prerr_endline "add_eq";*)
538 let rc = add_eq ~fast u v b in
542 let add_ge ?(fast=(!fast_implementation)) u v (b,already_contained) =
543 (* prerr_endline "add_ge"; *)
545 let rc = add_ge ~fast u v b in
549 let add_gt ?(fast=(!fast_implementation)) u v (b,already_contained) =
550 (* prerr_endline "add_gt"; *)
552 let rc = add_gt ~fast u v b in
556 (*****************************************************************************)
557 (** END: Decomment this for performance comparisons **)
558 (*****************************************************************************)
560 let merge_ugraphs ~base_ugraph ~increment:(increment, uri_of_increment) =
562 let merge_brutal (u,_) v =
563 if u = empty_bag then
564 ((*prerr_endline "HIT2";*)v)
565 else if fst v = empty_bag then
566 ((*prerr_endline "HIT3";*) u, snd v)
568 ((*prerr_endline "MISS";*)
575 let m = add_gt k u x in m)
576 (SOF.union v.one_s_gt v.gt_closure)
579 let m = add_ge k u x in m)
580 (SOF.union v.one_s_ge v.ge_closure)
583 let m = add_eq k u x in m)
584 (SOF.union v.one_s_eq v.eq_closure) x)))
587 let _, already_contained = base_ugraph in
588 if UriManager.UriSet.mem uri_of_increment already_contained then
589 ((*prerr_endline "HIT1";*)
592 fst (merge_brutal increment base_ugraph),
593 UriManager.UriSet.add uri_of_increment already_contained
595 (*****************************************************************************)
596 (** Xml sesialization and parsing **)
597 (*****************************************************************************)
599 let xml_of_universe name u =
603 None,"id",(string_of_int i) ;
604 None,"uri",(UriManager.string_of_uri u)]
606 raise (Failure "we can serialize only universes with uri")
610 List.map (xml_of_universe "node") (SOF.elements s)
612 List.fold_left (fun s x -> [< s ; x >] ) [<>] l
614 let xml_of_entry_content e =
615 let stream_of_field f name =
616 let eq_c = xml_of_set f in
618 Xml.xml_nempty name [] eq_c
623 (stream_of_field e.eq_closure "eq_closure");
624 (stream_of_field e.gt_closure "gt_closure");
625 (stream_of_field e.ge_closure "ge_closure");
626 (stream_of_field e.in_gegt_of "in_gegt_of");
627 (stream_of_field e.one_s_eq "one_s_eq");
628 (stream_of_field e.one_s_gt "one_s_gt");
629 (stream_of_field e.one_s_ge "one_s_ge")
632 let xml_of_entry u e =
638 raise (Failure "we can serialize only universes (entry) with uri")
640 let ent = Xml.xml_nempty "entry" [
641 None,"id",(string_of_int i) ;
642 None,"uri",(UriManager.string_of_uri u'')] in
643 let content = xml_of_entry_content e in
646 let write_xml_of_ugraph filename (m,_) l =
649 Xml.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
650 Xml.xml_nempty "ugraph" []
651 ([< (MAL.fold ( fun k v s -> [< s ; (xml_of_entry k v) >]) m [<>]) ;
653 (fun s u -> [< s ; xml_of_universe "owned_node" u >]) [<>] l) >])>]
655 Xml.pp ~gzip:true tokens (Some filename)
660 let rec clean_ugraph (m,already_contained) f =
662 MAL.fold (fun k v x -> if (f k) then MAL.add k v x else x ) m MAL.empty in
663 let m'' = MAL.fold (fun k v x ->
665 eq_closure = SOF.filter f v.eq_closure;
666 ge_closure = SOF.filter f v.ge_closure;
667 gt_closure = SOF.filter f v.gt_closure;
668 in_gegt_of = SOF.filter f v.in_gegt_of;
669 one_s_eq = SOF.filter f v.one_s_eq;
670 one_s_ge = SOF.filter f v.one_s_ge;
671 one_s_gt = SOF.filter f v.one_s_gt
673 MAL.add k v' x ) m' MAL.empty in
675 MAL.fold (fun k v l -> if v = empty_entry && not(f k) then
677 k::l end else l) m'' []
681 (m'', already_contained) (fun u -> (f u) && not (List.mem u e_l))
684 (fun k v x -> if v <> empty_entry then MAL.add k v x else x)
688 let clean_ugraph g l =
689 clean_ugraph g (fun u -> List.mem u l)
693 "ge_closure" -> (fun e u->{e with ge_closure=SOF.add u e.ge_closure})
694 | "gt_closure" -> (fun e u->{e with gt_closure=SOF.add u e.gt_closure})
695 | "eq_closure" -> (fun e u->{e with eq_closure=SOF.add u e.eq_closure})
696 | "in_gegt_of" -> (fun e u->{e with in_gegt_of =SOF.add u e.in_gegt_of})
697 | "one_s_ge" -> (fun e u->{e with one_s_ge =SOF.add u e.one_s_ge})
698 | "one_s_gt" -> (fun e u->{e with one_s_gt =SOF.add u e.one_s_gt})
699 | "one_s_eq" -> (fun e u->{e with one_s_eq =SOF.add u e.one_s_eq})
700 | s -> raise (Failure ("unsupported tag " ^ s))
704 let module XPP = XmlPushParser in
705 let current_node = ref (0,None) in
706 let current_entry = ref empty_entry in
707 let current_assign = ref (assigner_of "in_gegt_of") in
708 { XPP.default_callbacks with
709 XPP.end_element = Some( fun name ->
712 m := MAL.add !current_node !current_entry !m;
713 current_entry := empty_entry
716 XPP.start_element = Some( fun name attlist ->
720 let id = List.assoc "id" attlist in
721 let uri = List.assoc "uri" attlist in
722 current_node := (int_of_string id,Some (UriManager.uri_of_string uri))
724 let id = int_of_string (List.assoc "id" attlist) in
725 let uri = List.assoc "uri" attlist in
726 current_entry := !current_assign !current_entry
727 (id,Some (UriManager.uri_of_string uri))
729 let id = int_of_string (List.assoc "id" attlist) in
730 let uri = List.assoc "uri" attlist in
731 l := (id,Some (UriManager.uri_of_string uri)) :: !l
732 | s -> current_assign := assigner_of s
737 let ugraph_and_univlist_of_xml filename =
738 let module XPP = XmlPushParser in
739 let result_map = ref MAL.empty in
740 let result_list = ref [] in
741 let cb = cb_factory result_map result_list in
742 let xml_parser = XPP.create_parser cb in
743 let xml_source = `Gzip_file filename in
744 (try XPP.parse xml_parser xml_source
745 with (XPP.Parse_error err) as exn -> raise exn);
746 (!result_map,UriManager.UriSet.empty), !result_list
749 (*****************************************************************************)
750 (** the main, only for testing **)
751 (*****************************************************************************)
755 type arc = Ge | Gt | Eq ;;
757 let randomize_actionlist n m =
758 let ge_percent = 0.7 in
759 let gt_percent = 0.15 in
761 let node1 = Random.int m in
762 let node2 = Random.int m in
764 let r = Random.float 1.0 in
765 if r < ge_percent then
767 else (if r < (ge_percent +. gt_percent) then
777 | n -> (random_step ())::(aux (n-1))
781 let print_action_list l =
782 let string_of_step (op,node1,node2) =
787 "," ^ (string_of_int node1) ^ "," ^ (string_of_int node2)
793 ";" ^ (string_of_step a) ^ (aux tl)
796 let l_body = (String.length body) - 1 in
797 prerr_endline ("[" ^ (String.sub body 1 l_body))
800 let d_print_endline = if debug then print_endline else ignore
801 let d_print_ugraph = if debug then print_ugraph else ignore
804 (if Array.length Sys.argv < 2 then
805 prerr_endline ("Usage " ^ Sys.argv.(0) ^ " max_edges max_nodes"));
807 let max_edges = int_of_string Sys.argv.(1) in
808 let max_nodes = int_of_string Sys.argv.(2) in
809 let action_listR = randomize_actionlist max_edges max_nodes in
811 let action_list = [Ge,1,4;Ge,2,6;Ge,1,1;Eq,6,4;Gt,6,3] in
812 let action_list = action_listR in
814 print_action_list action_list;
815 let prform_step ?(fast=false) (t,u,v) g =
827 let g' = f ~fast (u,None) (v,None) g in
828 (*print_ugraph g' ;*)
831 let fail = ref false in
832 let time1 = Unix.gettimeofday () in
833 let n_safe = ref 0 in
836 d_print_endline "SAFE";
839 n_safe := !n_safe + 1;
841 ) empty_ugraph action_list
843 UniverseInconsistency s -> fail:=true;empty_bag
845 let time2 = Unix.gettimeofday () in
846 d_print_ugraph g_safe;
847 let time3 = Unix.gettimeofday () in
848 let n_test = ref 0 in
851 d_print_endline "FAST";
854 n_test := !n_test + 1;
855 prform_step ~fast:true e g
856 ) empty_ugraph action_list
858 UniverseInconsistency s -> empty_bag
860 let time4 = Unix.gettimeofday () in
861 d_print_ugraph g_test;
862 if are_ugraph_eq g_safe g_test && !n_test = !n_safe then
867 if e = Eq then s+1 else s
873 if e = Gt then s+1 else s
876 let num_ge = max_edges - num_gt - num_eq in
877 let time_fast = (time4 -. time3) in
878 let time_safe = (time2 -. time1) in
879 let gap = ((time_safe -. time_fast) *. 100.0) /. time_safe in
880 let fail = if !fail then 1 else 0 in
883 "OK %d safe %1.4f fast %1.4f %% %1.2f #eq %d #gt %d #ge %d %d"
884 fail time_safe time_fast gap num_eq num_gt num_ge !n_safe);
889 print_endline "FAIL";
902 i, Some (UriManager.uri_of_string (UriManager.string_of_uri uri))
904 let recons_entry entry =
906 SOF.fold (fun univ set -> SOF.add (recons_univ univ) set) set SOF.empty
909 eq_closure = recons_set entry.eq_closure;
910 ge_closure = recons_set entry.ge_closure;
911 gt_closure = recons_set entry.gt_closure;
912 in_gegt_of = recons_set entry.in_gegt_of;
913 one_s_eq = recons_set entry.one_s_eq;
914 one_s_ge = recons_set entry.one_s_ge;
915 one_s_gt = recons_set entry.one_s_gt;
918 let recons_graph (graph,uriset) =
920 (fun universe entry map ->
921 MAL.add (recons_univ universe) (recons_entry entry) map)
924 UriManager.UriSet.fold
926 UriManager.UriSet.add
927 (UriManager.uri_of_string (UriManager.string_of_uri u)) acc)
928 uriset UriManager.UriSet.empty
932 | (_,None) -> raise (UniverseInconsistency "This universe graph has a hole")
935 let assert_univs_have_uri (graph,_) univlist =
937 SOF.iter (fun u -> assert_univ u) s
940 assert_set e.eq_closure;
941 assert_set e.ge_closure;
942 assert_set e.gt_closure;
943 assert_set e.in_gegt_of;
944 assert_set e.one_s_eq;
945 assert_set e.one_s_ge;
946 assert_set e.one_s_gt;
948 MAL.iter (fun k v -> assert_univ k; assert_entry v)graph;
949 List.iter assert_univ univlist
953 | (id1, Some uri1),(id2, Some uri2) ->
954 id1 = id2 && UriManager.eq uri1 uri2
955 | (id1, None),(id2, None) -> id1 = id2
958 let compare (id1, uri1) (id2, uri2) =
959 let cmp = id1 - id2 in
964 | None, Some _ -> ~-1
965 | Some uri1, Some uri2 -> UriManager.compare uri1 uri2