This commit is contained in:
Leonie Gallois 2020-11-24 15:58:37 +01:00
parent 4e382d8e0b
commit a2c0c4b45d
4 changed files with 25 additions and 36 deletions

View file

@ -49,11 +49,7 @@ 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 =
<<<<<<< HEAD
try Scanf.sscanf line "u %s" (fun user-> (init_node graph user id l_id )
=======
try Scanf.sscanf line "u %s" (fun user -> init_node graph user id l_id ) try Scanf.sscanf line "u %s" (fun user -> init_node graph user id l_id )
>>>>>>> 097a500b7df1b0d2233a4edb99973bee942814f9
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"
@ -61,11 +57,7 @@ let read_user id graph l_id line =
(* Reads a line with a payement. *) (* Reads a line with a payement. *)
let read_payement graph l_id line = let read_payement graph l_id line =
try Scanf.sscanf line "p %s %s %f" try Scanf.sscanf line "p %s %s %f"
<<<<<<< HEAD
(fun user l_user label -> ((paiement graph user (String.split_on_char ',' l_user) label, l_id)
=======
(fun user l_user label -> paiement graph user (String.split_on_char ',' l_user) label l_id) (fun user l_user label -> paiement graph user (String.split_on_char ',' l_user) label l_id)
>>>>>>> 097a500b7df1b0d2233a4edb99973bee942814f9
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"
@ -90,11 +82,7 @@ let from_file path =
(* The first character of a line determines its content : u or p. *) (* 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)
<<<<<<< HEAD
| 'p' -> (n, read_payement graph line l_id)
=======
| 'p' -> (n, read_payement graph l_id line) | 'p' -> (n, read_payement graph l_id line)
>>>>>>> 097a500b7df1b0d2233a4edb99973bee942814f9
(* 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)

View file

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

View file

@ -4,37 +4,38 @@ open Tool
(*fonction qui créé le noeud associé à un utilisateur et rentre la correspondance dans la table des id*) (*fonction qui créé le noeud associé à un utilisateur et rentre la correspondance dans la table des id*)
let init_node g user id l_id= let init_node g user id l_id=
((new_node g id), ((user,id,0)::l_id)) ( (new_node g id), ((user,id,0.0)::l_id) )
(*fonction qui renvoie l'id d'un utilisateur*) (*fonction qui renvoie l'id d'un utilisateur*)
let rec get_id utilisateur l_id= match l_id with let rec get_id utilisateur l_id= match l_id with
|[]-> raise Not_found |[]-> raise Not_found
|(a,id1,val)::b-> if a=utilisateur then id1 else get_id utilisateur b |(a,id1,value)::b-> if a=utilisateur then id1 else get_id utilisateur b
(*fonction qui renvoie le nom correspondant à un id*) (*fonction qui renvoie le nom correspondant à un id*)
let rec get_user id1 l_id= match l_id with let rec get_user id1 l_id= match l_id with
|[]-> raise Not_found |[]-> raise Not_found
|(nom,a,val)::b-> if a=id1 then nom else get_user id1 b |(nom,a,value)::b-> if a=id1 then nom else get_user id1 b
let set_val_du a l_id montant l_utilisateurs= let set_val_du a l_id montant l_utilisateurs=
List.map (fun (nom,id,val)-> if nom=a List.map (fun (nom,id,value)-> if nom=a
then (nom,id,(Float.sub val (Float.div montant (Float.of_int(List.length l_utilisateurs))))) then (nom,id,(Float.sub value (Float.div montant (Float.of_int(List.length l_utilisateurs)))))
else (nom,id,val) else (nom,id,value)
) l_id ) l_id
let set_val_pret utilisateur montant l_id= let set_val_pret utilisateur montant l_id=
List.map (fun (nom,id,val)-> if nom=utilisateur List.map (fun (nom,id,value)-> if nom=utilisateur
then (nom,id,(Float.add val montant)) then (nom,id,(Float.add value montant))
else (nom,id,val) else (nom,id,value)
) l_id ) l_id
(*fonction qui rentre les paiements réalisés*) (*fonction qui rentre les paiements réalisés*)
let rec paiement g utilisateur l_utilisateurs montant l_id= let paiement g utilisateur l_utilisateurs montant l_id=
set_val_pret utilisateur montant l_id let rec paye g utilisateur l_utilisateurs montant l_id=match l_utilisateurs with
match l_utilisateurs with |[]-> (g, l_id)
|[]-> (g, l_id) |a::b-> paye g utilisateur b montant (set_val_du a l_id montant l_utilisateurs) in
|a::b-> paiement g utilisateur b montant (set_val_du a l_id montant l_utilisateurs) let l_id= set_val_pret utilisateur montant l_id in
paye g utilisateur l_utilisateurs montant l_id

View file

@ -1,13 +1,13 @@
open Graph open Graph
val paiement: float graph -> string -> string list -> float -> (string * id) list -> (float graph * (string * id) list) val paiement: float graph -> string -> string list -> float -> (string * id * float) list -> (float graph * (string * id * float) list)
val init_node: float graph -> string -> id -> (string * id) list-> (float graph * (string * id) list) val init_node: float graph -> string -> id -> (string * id * float) list-> (float graph * (string * id * float) list)
val get_id: string -> (string * id) list -> id val get_id: string -> (string * id * float) list -> id
val get_user: id -> (string * id) list -> string val get_user: id -> (string * id * float) list -> string
val set_val_du: val set_val_du: string -> (string * id * float) list -> float -> string list -> (string * id * float) list
val set_val_pret: val set_val_pret: string -> float -> (string * id * float) list -> (string * id * float) list