File: depgraph.ml

package info (click to toggle)
hol-light 20170109-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 36,568 kB
  • ctags: 8,549
  • sloc: ml: 540,018; cpp: 439; lisp: 286; java: 279; makefile: 262; sh: 229; yacc: 108; perl: 78; ansic: 57; sed: 39
file content (115 lines) | stat: -rw-r--r-- 2,304 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
module Label = struct

  type t = string

  let compare = String.compare

  let hash s =
    let n = String.length s in
    let p = 9 in
    if n >= p then
      try
        int_of_string (String.sub s p (n-p))
      with | Failure _ -> n
    else
      n

  let equal a b = a = b

end


module Dep = struct

  include Graph.Imperative.Digraph.ConcreteBidirectional(Label)

  let graph_attributes _ = []

  let default_vertex_attributes _ = []

  let vertex_name v = V.label v

  let vertex_attributes _ = []

  let get_subgraph _ = None

  let default_edge_attributes _ = []

  let edge_attributes _ = []

  let add_thm dep thm = add_vertex dep (V.create thm)

  let add_dep dep thm1 thm2 =
    let v1 = V.create thm1 in
    let v2 = V.create thm2 in
    if ((mem_vertex dep v1) && (mem_vertex dep v2)) then
      add_edge dep v1 v2

  let min_max_moy_in_deg dep =
    let max = ref 0 in
    let lab_max = ref "" in
    let min = ref 1073741823 in
    let lab_min = ref "" in
    let nb = ref 0 in
    let sum = ref 0 in
    let calc v =
      let deg = in_degree dep v in
      if deg < !min then (
        min := deg;
        lab_min := V.label v
      );
      if deg > !max then (
        max := deg;
        lab_max := V.label v
      );
      incr nb;
      sum := !sum + deg in
    iter_vertex calc dep;
    let moy = (float_of_int !sum) /. (float_of_int !nb) in
    (!min, !lab_min, !max, !lab_max, moy)

  let min_max_moy_out_deg dep =
    let max = ref 0 in
    let lab_max = ref "" in
    let min = ref 1073741823 in
    let lab_min = ref "" in
    let nb = ref 0 in
    let sum = ref 0 in
    let calc v =
      let deg = out_degree dep v in
      if deg < !min then (
        min := deg;
        lab_min := V.label v
      );
      if deg > !max then (
        max := deg;
        lab_max := V.label v
      );
      incr nb;
      sum := !sum + deg in
    iter_vertex calc dep;
    let moy = (float_of_int !sum) /. (float_of_int !nb) in
    (!min, !lab_min, !max, !lab_max, moy)

end


module Dep_top = struct

  include Graph.Topological.Make(Dep)

  let iter_top f dep = iter (fun v -> f (Dep.V.label v)) dep

end


module Dep_dot = struct

  include Graph.Graphviz.Dot(Dep)

  let output_dot name dep =
    let file = open_out name in
    output_graph file dep;
    close_out file

end