Compare commits
2 commits
097a500b7d
...
4e382d8e0b
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e382d8e0b | |||
| c97e4edc84 |
3 changed files with 36 additions and 9 deletions
|
|
@ -49,7 +49,11 @@ let read_comment graph line l_id=
|
|||
|
||||
(* Reads a line with a user. *)
|
||||
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 )
|
||||
>>>>>>> 097a500b7df1b0d2233a4edb99973bee942814f9
|
||||
with e ->
|
||||
Printf.printf "Cannot read node in line - %s:\n%s\n%!" (Printexc.to_string e) line ;
|
||||
failwith "from_file"
|
||||
|
|
@ -57,7 +61,11 @@ let read_user id graph l_id line =
|
|||
(* Reads a line with a payement. *)
|
||||
let read_payement graph l_id line =
|
||||
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)
|
||||
>>>>>>> 097a500b7df1b0d2233a4edb99973bee942814f9
|
||||
with e ->
|
||||
Printf.printf "Cannot read arc in line - %s:\n%s\n%!" (Printexc.to_string e) line ;
|
||||
failwith "from_file"
|
||||
|
|
@ -82,7 +90,11 @@ let from_file path =
|
|||
(* The first character of a line determines its content : u or p. *)
|
||||
else match line.[0] with
|
||||
| '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)
|
||||
>>>>>>> 097a500b7df1b0d2233a4edb99973bee942814f9
|
||||
|
||||
(* It should be a comment, otherwise we complain. *)
|
||||
| _ -> (n, read_comment graph line l_id)
|
||||
|
|
|
|||
|
|
@ -4,26 +4,37 @@ open Tool
|
|||
|
||||
(*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=
|
||||
((new_node g id), ((user,id)::l_id))
|
||||
((new_node g id), ((user,id,0)::l_id))
|
||||
|
||||
|
||||
(*fonction qui renvoie l'id d'un utilisateur*)
|
||||
let rec get_id utilisateur l_id= match l_id with
|
||||
|[]-> raise Not_found
|
||||
|(a,id1)::b-> if a=utilisateur then id1 else get_id utilisateur b
|
||||
|(a,id1,val)::b-> if a=utilisateur then id1 else get_id utilisateur b
|
||||
|
||||
(*fonction qui renvoie le nom correspondant à un id*)
|
||||
let rec get_user id1 l_id= match l_id with
|
||||
|[]-> raise Not_found
|
||||
|(nom,a)::b-> if a=id1 then nom else get_user id1 b
|
||||
|(nom,a,val)::b-> if a=id1 then nom else get_user id1 b
|
||||
|
||||
let set_val_du a l_id montant l_utilisateurs=
|
||||
List.map (fun (nom,id,val)-> if nom=a
|
||||
then (nom,id,(Float.sub val (Float.div montant (Float.of_int(List.length l_utilisateurs)))))
|
||||
else (nom,id,val)
|
||||
) l_id
|
||||
|
||||
let set_val_pret utilisateur montant l_id=
|
||||
List.map (fun (nom,id,val)-> if nom=utilisateur
|
||||
then (nom,id,(Float.add val montant))
|
||||
else (nom,id,val)
|
||||
) l_id
|
||||
|
||||
(*fonction qui rentre les paiements réalisés*)
|
||||
let rec paiement g utilisateur l_utilisateurs montant l_id= match l_utilisateurs with
|
||||
let rec paiement g utilisateur l_utilisateurs montant l_id=
|
||||
set_val_pret utilisateur montant l_id
|
||||
match l_utilisateurs with
|
||||
|[]-> (g, l_id)
|
||||
|a::b-> if not(a=utilisateur)
|
||||
then paiement (add_arc g (get_id utilisateur l_id) (get_id a l_id) (Float.div montant (Float.of_int(List.length l_utilisateurs)))) utilisateur b montant l_id
|
||||
else paiement g utilisateur b montant l_id
|
||||
|
||||
|a::b-> paiement g utilisateur b montant (set_val_du a l_id montant l_utilisateurs)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,4 +6,8 @@ val init_node: float graph -> string -> id -> (string * id) list-> (float graph
|
|||
|
||||
val get_id: string -> (string * id) list -> id
|
||||
|
||||
val get_user: id -> (string * id) list -> string
|
||||
val get_user: id -> (string * id) list -> string
|
||||
|
||||
val set_val_du:
|
||||
|
||||
val set_val_pret:
|
||||
Loading…
Reference in a new issue