ocaml_project/medium_project/src/tool.ml
2020-11-23 12:38:57 +01:00

19 lines
547 B
OCaml
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(* Yes, we have to repeat open Graph. *)
open Graph
(* assert false is of type ∀α.α, so the type-checker is happy. *)
let clone_nodes gr = n_fold gr new_node empty_graph
(* Clone the nodes first then clone every arc but change their label by applying f*)
let gmap gr f =
let new_graph = clone_nodes gr in
e_fold gr (fun acu id1 id2 x -> new_arc acu id1 id2 (f x)) new_graph
let add_arc g id1 id2 n =
let f = find_arc g id1 id2 in
match f with
|None->new_arc g id1 id2 n
|Some x->new_arc g id1 id2 (Float.add n x)