Implement method that checks if arc is in the found path
This commit is contained in:
parent
a917c86bd0
commit
4e069579f3
4 changed files with 29 additions and 14 deletions
|
|
@ -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
|
||||
|
|
|
|||
13
src/ftest.ml
13
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
|
||||
|
||||
() *)
|
||||
|
||||
|
|
|
|||
14
src/tools.ml
14
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue