feat : wrtie the function in tools

This commit is contained in:
Leandro-rdz 2024-12-02 11:06:56 +01:00
parent 99c60192a7
commit 76c59abf84

View file

@ -1,7 +1,13 @@
(* Yes, we have to repeat open Graph. *)
open Graph
(* assert false is of type ∀α.α, so the type-checker is happy. *)
let clone_nodes _gr = assert false
let gmap _gr _f = assert false
(* Replace _gr and _f by gr and f when you start writing the real function. *)
(* returns a new graph having the same nodes than gr, but no arc *)
let clone_nodes gr = n_fold gr new_node empty_graph
(* maps all arcs of gr by function f *)
let gmap gr f = e_fold gr (fun gr arc -> new_arc gr {arc with lbl = f arc.lbl}) (clone_nodes gr)
(* adds n to the value of the arc between id1 and id2. If the arc does not exist, it is created *)
let add_arc g id1 id2 n=
match find_arc g id1 id2 with
| Some _ -> g
| None -> let arc = {src = id1; tgt = id2; lbl = n} in new_arc g arc