FordFulkersonLeChameau/src/tools.ml
2022-11-24 09:46:55 +01:00

16 lines
580 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. *)
(* returns a new graph having the same nodes than gr, but no arc. *)
let clone_nodes gr = n_fold gr new_node empty_graph
(*adds an arc or its value if there is an existing one*)
let add_arc g id1 id2 n =
match find_arc g id1 id2 with
| None -> new_arc g id1 id2 n
| Some a -> new_arc g id1 id2 (n + a)
(* maps all arcs of gr by function f *)
let gmap gr f = e_fold gr (fun acc id1 id2 x -> new_arc acc id1 id2 (f x)) (clone_nodes gr)