Fix mistake in update_flow_graph

This commit is contained in:
AnaGrskovic 2023-12-04 16:07:38 +01:00
parent 9f1c416d19
commit a5d44a7fc8
3 changed files with 29 additions and 4 deletions

21
graphs/flow_graph1.txt Normal file
View file

@ -0,0 +1,21 @@
% This is a graph.
n 20 300 0
n 200 300 1
n 200 200 2
n 200 400 3
n 380 300 4
n 380 200 5
e 0 2 0 5
e 0 3 1 5
e 0 1 2 5
e 2 4 3 5
e 3 4 4 5
e 3 2 5 5
e 3 1 6 5
e 1 4 7 5
e 1 5 8 5
e 4 5 9 5
% End of graph

View file

@ -28,10 +28,15 @@ let () =
(* Open file *)
let graph = from_file infile in
let g = clone_nodes graph in
(*let g = clone_nodes graph in*)
let flow_graph_1 = create_flow_graph graph in
let flow_graph_2 = update_flow_graph flow_graph_1 (fun _ -> true) 5 in
let string_flow_graph = gmap flow_graph_2 (fun x -> string_of_int x) in
(* Rewrite the graph that has been read. *)
let () = write_file outfile g in
let () = write_file outfile string_flow_graph in
()

View file

@ -19,7 +19,6 @@ let update_flow_graph : int graph -> (int arc -> bool) -> int -> int 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 }
@ -27,7 +26,7 @@ let update_flow_graph : int graph -> (int arc -> bool) -> int -> int graph =
arc
in
new_arc acc_graph modified_arc)
empty_graph
original_graph
in
new_graph