This commit is contained in:
Kevin Cavailles 2020-11-24 15:00:43 +01:00
джерело 96f15c7045
коміт 097a500b7d
5 змінених файлів з 11 додано та 13 видалено

@ -18,4 +18,4 @@ demo: build
clean: clean:
-rm -rf _build/ -rm -rf _build/
-rm ftest.native -rm MSftest.native

@ -31,7 +31,7 @@ let () =
(* Open file *) (* Open file *)
let (graph, l_id) = from_file infile in let (graph, l_id) = from_file infile in
let initGraph = g_to_float graph in let initGraph = graph in
(* Rewrite the graph that has been read. *) (* Rewrite the graph that has been read. *)

@ -38,8 +38,6 @@ let write_file path graph l_id=
fprintf ff "\n%% End of reimbursements\n" ; fprintf ff "\n%% End of reimbursements\n" ;
close_out ff ; close_out ff ;
() ()
@ -51,15 +49,15 @@ let read_comment graph line l_id=
(* Reads a line with a user. *) (* Reads a line with a user. *)
let read_user id graph l_id line = let read_user id graph l_id line =
try Scanf.sscanf line "u %s" (fun user l_id-> ((init_node graph user id), l_id) ) try Scanf.sscanf line "u %s" (fun user -> init_node graph user id l_id )
with e -> with e ->
Printf.printf "Cannot read node in line - %s:\n%s\n%!" (Printexc.to_string e) line ; Printf.printf "Cannot read node in line - %s:\n%s\n%!" (Printexc.to_string e) line ;
failwith "from_file" failwith "from_file"
(* Reads a line with a payement. *) (* Reads a line with a payement. *)
let read_payement graph line l_id= let read_payement graph l_id line =
try Scanf.sscanf line "p %s %s %f" try Scanf.sscanf line "p %s %s %f"
(fun u l_u label -> ((paiement graph u (String.split_on_char ',' l_u) label), l_id)) (fun user l_user label -> paiement graph user (String.split_on_char ',' l_user) label l_id)
with e -> with e ->
Printf.printf "Cannot read arc in line - %s:\n%s\n%!" (Printexc.to_string e) line ; Printf.printf "Cannot read arc in line - %s:\n%s\n%!" (Printexc.to_string e) line ;
failwith "from_file" failwith "from_file"
@ -81,10 +79,10 @@ let from_file path =
(* Ignore empty lines *) (* Ignore empty lines *)
if line = "" then (n, (graph, l_id)) if line = "" then (n, (graph, l_id))
(* The first character of a line determines its content : n or e. *) (* The first character of a line determines its content : u or p. *)
else match line.[0] with else match line.[0] with
| 'u' -> (n+1, (read_user n graph l_id line)) | 'u' -> (n+1, read_user n graph l_id line)
| 'p' -> (n, read_payement graph line l_id) | 'p' -> (n, read_payement graph l_id line)
(* It should be a comment, otherwise we complain. *) (* It should be a comment, otherwise we complain. *)
| _ -> (n, read_comment graph line l_id) | _ -> (n, read_comment graph line l_id)

@ -2,7 +2,7 @@ open Graph
type path = string type path = string
val from_file: path -> (string graph * (string * id) list) val from_file: path -> (float graph * (string * id) list)
val write_file: path -> string graph -> (string * id) list -> unit val write_file: path -> string graph -> (string * id) list -> unit