From 4e069579f3e4ac846c6a9e926509f1cf87feedd9 Mon Sep 17 00:00:00 2001 From: AnaGrskovic Date: Mon, 4 Dec 2023 16:39:47 +0100 Subject: [PATCH] Implement method that checks if arc is in the found path --- graphs/flow_graph1.txt | 14 +++++++------- src/ftest.ml | 13 ++++++------- src/tools.ml | 14 ++++++++++++++ src/tools.mli | 2 ++ 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/graphs/flow_graph1.txt b/graphs/flow_graph1.txt index dc2e634..cae1dd4 100644 --- a/graphs/flow_graph1.txt +++ b/graphs/flow_graph1.txt @@ -8,14 +8,14 @@ n 380 300 4 n 380 200 5 e 0 2 0 4 -e 0 3 1 4 -e 0 1 2 4 +e 0 3 1 0 +e 0 1 2 0 e 2 4 3 4 -e 3 4 4 4 -e 3 2 5 4 -e 3 1 6 4 -e 1 4 7 4 -e 1 5 8 4 +e 3 4 4 0 +e 3 2 5 0 +e 3 1 6 0 +e 1 4 7 0 +e 1 5 8 0 e 4 5 9 4 % End of graph diff --git a/src/ftest.ml b/src/ftest.ml index 1e807bf..5d7a660 100644 --- a/src/ftest.ml +++ b/src/ftest.ml @@ -29,10 +29,12 @@ let () = (* Open file *) let graph = from_file infile 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) 4 in + + let path : int list = [0; 2; 4; 5] in + + let flow_graph_2 = update_flow_graph flow_graph_1 (fun arc -> check_if_arc_is_in_path arc path) 1 in let string_flow_graph = gmap flow_graph_2 (fun x -> string_of_int x) in @@ -40,16 +42,13 @@ let () = let () = write_file outfile string_flow_graph in + (* let g = clone_nodes graph in *) let () = aff (dfs graph 0 [] 3) ; Printf.printf "\n\n" ; hash - in () + in () - (* Rewrite the graph that has been read. *) - (* let () = write_file outfile g in - - () *) diff --git a/src/tools.ml b/src/tools.ml index 48a766a..ceabd34 100644 --- a/src/tools.ml +++ b/src/tools.ml @@ -29,6 +29,20 @@ let update_flow_graph : int graph -> (int arc -> bool) -> int -> int graph = original_graph in new_graph + +let check_if_arc_is_in_path : int arc -> int list -> bool = + fun arc path -> + let rec is_arc_in_path path = + match path with + | [] | [_] -> false (* A path must have at least two nodes to have an arc *) + | node1 :: node2 :: rest -> + if (node1, node2) = (arc.src, arc.tgt) || (node1, node2) = (arc.tgt, arc.src) then + true + else + is_arc_in_path (node2 :: rest) + in + is_arc_in_path path + \ No newline at end of file diff --git a/src/tools.mli b/src/tools.mli index de80fdb..f3f1647 100644 --- a/src/tools.mli +++ b/src/tools.mli @@ -11,3 +11,5 @@ val create_flow_graph: 'a graph -> int graph val update_flow_graph : int graph -> (int arc -> bool) -> int -> int graph +val check_if_arc_is_in_path : int arc -> int list -> bool +