-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprinttoC.ml
76 lines (68 loc) · 2.24 KB
/
printtoC.ml
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
open Def
open Printf
let make_prec_matrix_server_tree_int tree size_of_tree = (*This should be called on a tree result of "tarbre_to_arbre_int", so the input is still correct.*)
let sol = Array.make_matrix size_of_tree size_of_tree 0. in
let i = ref 0 in
let rec aux_tree list_of_subtrees list_of_index=
match list_of_subtrees with
| [] -> ()
| ServerInt( lt, id, prop) :: b ->
begin
List.iter (function x -> sol.(x).(!i)<- 1.) list_of_index;
sol.(!i).(!i)<- prop.load;
incr i;
aux_tree lt ((!i-1)::list_of_index);
aux_tree b list_of_index
end
in
aux_tree [tree] [];
sol
let print_square_matrix matrix oo =
let n = Array.length matrix.(0) in
for i = 0 to n-1 do
for j= 0 to n-1 do
fprintf oo "%f \t" matrix.(i).(j)
done;
fprintf oo "\n"
done
(*Patch that needs to be corrected!*)
let print_square_matrix_int matrix1 matrix2 oo =
let result = matrix1 in
let n = Array.length matrix1.(0) in
for i = 0 to n-1 do
if matrix1.(i).(i) = 0. then
let j = ref (i-1) in
while (!j >= 0 && matrix2.(!j).(i) = 0.) do
decr j;
done;
(* if !j<0 then failwith "bug ici, remplacer i par j";*)
result.(!j).(!j) <- result.(!j).(!j) +. matrix2.(i).(i)
else
result.(i).(i) <- matrix2.(i).(i);
done;
print_square_matrix result oo
let print_set_of_speeds energy oo=
fprintf oo "%f\t" energy.static;
let n = Array.length energy.speeds in
for i= 0 to n-1 do
fprintf oo "%f\t" energy.speeds.(i)
done;
fprintf oo "\n"
let make_prec_matrix_full_tree tree size_of_tree = (*This should be called on a tree result of "tarbre_to_arbre_int", so the input is still correct.*)
let sol = Array.make_matrix size_of_tree size_of_tree 0. in
let i = ref 0 in
let rec aux_tree list_of_subtrees list_of_index=
match list_of_subtrees with
| [] -> ()
| Node( lt, inp) :: b ->
begin
List.iter (function x -> sol.(x).(!i)<- 1.) list_of_index;
sol.(!i).(!i)<- inp;
incr i;
aux_tree lt ((!i-1)::list_of_index);
aux_tree b list_of_index
end
| Server(_,_,_) :: _-> failwith "This should not be here"
in
aux_tree [tree] [];
sol