From 1f6c4eaec5c15270ab0e0fc196286b5c1a1ef26f Mon Sep 17 00:00:00 2001 From: AnaGrskovic Date: Mon, 4 Dec 2023 17:52:26 +0100 Subject: [PATCH] Make function that finds max flow also take backward arches into account --- graphs/flow_graph_ana.txt | 20 ++++++++++++++++++++ graphs/graph_ana.txt | 25 +++++++++++++++++++++++++ src/ftest.ml | 4 ++-- src/tools.ml | 8 +++++--- src/tools.mli | 1 - 5 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 graphs/flow_graph_ana.txt create mode 100644 graphs/graph_ana.txt diff --git a/graphs/flow_graph_ana.txt b/graphs/flow_graph_ana.txt new file mode 100644 index 0000000..68b7f14 --- /dev/null +++ b/graphs/flow_graph_ana.txt @@ -0,0 +1,20 @@ +% 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 4 5 0 10 +e 4 2 1 0 +e 3 4 2 6 +e 2 5 3 4 +e 1 4 4 12 +e 1 3 5 0 +e 1 2 6 4 +e 0 3 7 6 +e 0 1 8 8 + +% End of graph diff --git a/graphs/graph_ana.txt b/graphs/graph_ana.txt new file mode 100644 index 0000000..6cd0632 --- /dev/null +++ b/graphs/graph_ana.txt @@ -0,0 +1,25 @@ +%% Test graph #1 + +%% Nodes + +n 20 300 0 % S This is node #0, with its coordinates (which are not used by the algorithms). +n 200 300 1 % A +n 200 200 2 % B +n 200 400 3 % C +n 380 300 4 % D +n 380 200 5 % T This is node #5. + + +%% Edges (arcs) + +e 0 1 0 10 % An arc from 0 to 2, labeled "8". The second 0 is useless. +e 0 3 1 10 +e 1 2 2 4 +e 1 3 3 2 +e 1 4 4 8 +e 2 5 5 10 +e 3 4 6 9 +e 4 2 7 6 +e 4 5 8 10 + +% End of graph diff --git a/src/ftest.ml b/src/ftest.ml index 77198f3..695a3fd 100644 --- a/src/ftest.ml +++ b/src/ftest.ml @@ -35,7 +35,7 @@ let () = (* iteration 1 *) - let path_1 : int list = [0; 2; 4; 5] in + let path_1 : int list = [0; 1; 4; 5] in Printf.printf "Path 1: [%s]\n" (String.concat "; " (List.map string_of_int path_1)) ; let new_flow_optional_1 : int option = find_max_flow_on_path graph flow_graph_0 path_1 in @@ -57,7 +57,7 @@ let () = (* iteration 3 *) - let path_3 : int list = [0; 1; 4; 5] in + let path_3 : int list = [0; 3; 4; 1; 2; 5] in Printf.printf "Path 3: [%s]\n" (String.concat "; " (List.map string_of_int path_3)) ; let new_flow_optional_3 : int option = find_max_flow_on_path graph flow_graph_2 path_3 in diff --git a/src/tools.ml b/src/tools.ml index faf4459..cf0c2b2 100644 --- a/src/tools.ml +++ b/src/tools.ml @@ -61,17 +61,19 @@ let find_max_flow_on_path : int graph -> int graph -> int list -> int option = | Some rest_difference -> Some (min (arc1.lbl - arc2.lbl) rest_difference) | None -> Some (arc1.lbl - arc2.lbl) end - | (None, None, Some arc1_rev, Some arc2_rev) -> + | (None, None, Some _, Some arc2_rev) -> let rest_difference_opt = find_max_flow_on_path (node2 :: rest) in begin match rest_difference_opt with - | Some rest_difference -> Some (min (arc2_rev.lbl - arc1_rev.lbl) rest_difference) - | None -> Some (arc2_rev.lbl - arc1_rev.lbl) + | Some rest_difference -> Some (min (arc2_rev.lbl) rest_difference) + | None -> Some (arc2_rev.lbl) end | _ -> None in find_max_flow_on_path path + + \ No newline at end of file diff --git a/src/tools.mli b/src/tools.mli index e2bd480..01113c3 100644 --- a/src/tools.mli +++ b/src/tools.mli @@ -16,4 +16,3 @@ val check_if_arc_is_in_path : int arc -> int list -> bool val find_max_flow_on_path : int graph -> int graph -> int list -> int option -