From f93e3543234c71d3b29303402964a69909dfef23 Mon Sep 17 00:00:00 2001 From: Leandro-rdz Date: Mon, 2 Dec 2024 16:38:30 +0100 Subject: [PATCH] fix the way we update graph --- src/tools.ml | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/tools.ml b/src/tools.ml index 054d2ec..d8e0d9e 100644 --- a/src/tools.ml +++ b/src/tools.ml @@ -12,23 +12,15 @@ let add_arc g id1 id2 n= | Some arc -> let new_lbl = arc.lbl + n in new_arc g {arc with lbl = new_lbl} | None -> let arc = {src = id1; tgt = id2; lbl = n} in new_arc g arc - -(* Tools to do : - - Update graph : take a list and a value -> add this value to all arc in the list - we must do a find_arc and if it doesn't find we try to do the arc in the other side with the value in negative - -Find path : find a patch and return a list of arc and a value : the max of increase *) - - (* update_graph g l n : add n to all arcs in l. If an arc does not exist,it means that the arcs is in the otherside and the value is negative - raise Not_found if the arc does not exist in the graph *) + (* update_graph g l n : update the gap graph *) let update_graph graph list value = let rec aux graph list value = match list with | [] -> graph | (id1, id2)::rest -> let graph = match find_arc graph id1 id2 with - | Some _ -> add_arc graph id1 id2 value - | None -> (match find_arc graph id2 id1 with - | Some _ -> add_arc graph id2 id1 (-value) - | None -> raise Not_found) + | None -> raise Not_found + | Some _ -> let graph = add_arc graph id1 id2 (-value) in + add_arc graph id2 id1 value in aux graph rest value in aux graph list value