Commit 4e92af99 authored by Benoit Barbot's avatar Benoit Barbot
Browse files

fix saving precomputation

parent 1cbececd
Pipeline #1691 passed with stages
in 32 seconds
......@@ -61,7 +61,7 @@ sig
module P:WeightStructure
module Bt:ZoneGraphInput.BoundType
val t : P.var
val desc : string
val iterate_functionnal :
?update:(unit -> unit) ->
......@@ -121,6 +121,11 @@ module Make (Bt: ZoneGraphInput.BoundType) (P: WeightStructure) = struct
let t = var_of_int 0
let desc =
Printf.sprintf "[%s; %s]"
(if P.F.is_exact then "exact rational" else "floating point")
P.desc
(* Convert state to F.t *)
let state_of_float state =
let state = (fst state, Array.map (fun (y)-> (F.of_float y)) (snd state)) in
......
......@@ -40,6 +40,8 @@ sig
module Bt:ZoneGraphInput.BoundType
val t : P.var
val desc : string
val iterate_functionnal :
?update:(unit -> unit) ->
('a,Bt.t) ZoneGraph.t -> int -> P.t array * (P.t,Bt.t) ZoneGraph.t
......
......@@ -35,7 +35,7 @@ let string_of_file f =
close_in fo;
!b
let precomputation_exists ?debug filename frequency npoly exact_rational =
let precomputation_exists ?debug filename frequency npoly s_formal exact_rational =
try
let fd = open_in ((Filename.remove_extension filename)^".pcmp") in
let hashmod = Digest.file filename in
......@@ -43,10 +43,12 @@ let precomputation_exists ?debug filename frequency npoly exact_rational =
let freq = (input_value fd: float option) in
let polyn = (input_value fd: int) in
let exact_rat = (input_value fd: bool) in
let s_formal_in = (input_value fd : bool) in
let rg = input_value fd in
if (hashpcmp=hashmod && frequency = freq && npoly=polyn && exact_rational=exact_rat ) then (
let weight = input_value fd in
if (hashpcmp=hashmod && frequency = freq && npoly=polyn && exact_rational=exact_rat && s_formal=s_formal_in ) then (
(debug |>>| (fun _ -> ())) true;
Some rg
Some (weight,rg)
) else (
(debug |>>| (fun _ -> ())) false;
None
......@@ -57,14 +59,16 @@ let precomputation_exists ?debug filename frequency npoly exact_rational =
| End_of_file -> None (* Corrupt file *)
| _ -> None
let save_precomputation file rg frequency npoly exact_rational =
let save_precomputation file weight rg frequency npoly s_formal exact_rational =
let fd = open_out ((Filename.remove_extension file)^".pcmp") in
let hashmod = Digest.file file in
output_value fd (hashmod: Digest.t);
output_value fd (frequency: float option);
output_value fd (npoly: int);
output_value fd (exact_rational:bool);
output_value fd (s_formal : bool);
Marshal.to_channel fd rg [Marshal.Closures];
output_value fd weight;
close_out fd
......
......@@ -51,7 +51,7 @@ let _ =
if b
then printf "Precomputation file found ! [%.2f]@." (check_time ())
else printf "Precomputation file found but file have change discard !@.")
!infile !frequency !npoly !rational_impl in
!infile !frequency !npoly (!frequency=None && !expected_duration <> None) !rational_impl in
(* Use splitted or general bound, general only for isotropic sampling *)
let module Bound = (val if !npoly<0 then (module ZoneGraphInput.GeneralBound:ZoneGraphInput.BoundType )
......@@ -72,7 +72,7 @@ let _ =
(* Polynomials over the clocks*)
let module P = Polynome.Make (R) (struct let var_string= match rgopt,precomp_exists with
Some a,_ -> a.ZoneGraph.var_string
| _,Some b -> b.ZoneGraph.var_string
| _,Some (_,b) -> b.ZoneGraph.var_string
| None,None -> assert false end) in
(* either P or exp-polynomials *)
(* If exact computation or no s parameter given s is symbolic, otherwise it is inlined during computation *)
......@@ -90,24 +90,30 @@ let _ =
(* Compute Weight and distribution as polynomials *)
let weights,rgpoly =
match precomp_exists, rgopt, !npoly>=0 with
| Some rg,_,_ -> rg
| Some content,_,_ ->
if !verbose>0 then (
printf "Reading Distribution%s -> %i@."
FunIt.desc
!npoly
);
content
| _, Some rg, true ->
if !verbose>0 then (
printf "Computing Distribution[%s; %s] -> %i: ["
(if Weight.F.is_exact then "exact rational" else "floating point")
Weight.desc
printf "Computing Distribution%s -> %i: ["
FunIt.desc
!npoly; flush stdout;
print_flush ()
);
let rgp = FunIt.iterate_functionnal ~update:(fun () ->if !verbose >0 then (printf "|"; print_flush ()))
let w,rgp = FunIt.iterate_functionnal ~update:(fun () ->if !verbose >0 then (printf "|"; print_flush ()))
rg !npoly in
if !verbose>0 then printf "] [%.2fs]@." (check_time ());
rgp
w,rgp
| _, Some rg, false -> FunIt.iterate_functionnal rg 0
| None,None,_ -> assert false in
(*Save computation*)
(*ZoneGraphInput.save_precomputation !infile rgpoly !frequency !npoly !rational_impl;*)
ZoneGraphInput.save_precomputation !infile weights rgpoly !frequency !npoly (!frequency=None && !expected_duration <> None) !rational_impl;
if !print_rg then
begin
printf "%a@." (ZoneGraph.print Bound.print) rgpoly;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment