From 9f1c416d199122ab567f7e346782e0b5629d872a Mon Sep 17 00:00:00 2001 From: AnaGrskovic Date: Mon, 4 Dec 2023 13:56:55 +0100 Subject: [PATCH] Implement a function that updates flow graph --- src/tools.ml | 34 +++++++++++++++++++--------------- src/tools.mli | 5 +---- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/tools.ml b/src/tools.ml index 575d906..e0ac489 100644 --- a/src/tools.ml +++ b/src/tools.ml @@ -12,20 +12,24 @@ let add_arc graph id1 id2 n = | Some arc -> new_arc graph {src=arc.src; tgt=arc.tgt; lbl=arc.lbl+n} let create_flow_graph graph = gmap graph (fun _ -> 0) - -(*let update_arc_flow graph src_id dest_id flow = - match (find_arc graph src_id dest_id) with - | Some arc -> arc.lbl <- arc.lbl + flow - | None -> ()*) - -let update_arc_flow graph src_id dest_id flow = gmap graph (fun arc -> if arc.src = src_id && arc.tgt = dest_id then (arc.lbl + flow)) - -(*let update_flow_graph graph node_ids new_flow = - let mylength_acu_better l = - let rec loop acu l = match l with - | Empty -> acu - | Cell(_, tail) -> loop (acu + 1) tail + +let update_flow_graph : int graph -> (int arc -> bool) -> int -> int graph = + fun original_graph condition increment -> + let new_graph = + e_fold + original_graph + (fun acc_graph arc -> + (* Perform some transformation or condition on the arc and accumulate the result in the new graph *) + let modified_arc = + if condition arc then + { arc with lbl = arc.lbl + increment } + else + arc + in + new_arc acc_graph modified_arc) + empty_graph in - loop 0 l ;;*) + new_graph + -(*let find_max_possible_flow graph node_ids = e_fold graph (fun acu arc -> if List.mem arc.src myList) 0*) \ No newline at end of file + \ No newline at end of file diff --git a/src/tools.mli b/src/tools.mli index cad274e..de80fdb 100644 --- a/src/tools.mli +++ b/src/tools.mli @@ -9,8 +9,5 @@ val add_arc: int graph -> id -> id -> int -> int graph (* try not to lose genericity *) val create_flow_graph: 'a graph -> int graph -val update_arc_flow: int graph -> int -> int -> int -> int graph +val update_flow_graph : int graph -> (int arc -> bool) -> int -> int graph -(*val update_flow_graph: int graph -> int list -> int -> int graph*) - -(*val find_max_possible_flow: int graph -> int list -> int*) \ No newline at end of file