Implement function that finds the lowest flow in path
This commit is contained in:
parent
4e069579f3
commit
2442e5786b
4 changed files with 46 additions and 15 deletions
|
|
@ -7,15 +7,15 @@ n 200 400 3
|
|||
n 380 300 4
|
||||
n 380 200 5
|
||||
|
||||
e 0 2 0 4
|
||||
e 0 3 1 0
|
||||
e 0 1 2 0
|
||||
e 2 4 3 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
|
||||
e 4 5 0 8
|
||||
e 1 5 1 0
|
||||
e 1 4 2 0
|
||||
e 3 1 3 0
|
||||
e 3 2 4 0
|
||||
e 3 4 5 0
|
||||
e 2 4 6 8
|
||||
e 0 1 7 0
|
||||
e 0 3 8 0
|
||||
e 0 2 9 8
|
||||
|
||||
% End of graph
|
||||
|
|
|
|||
18
src/ftest.ml
18
src/ftest.ml
|
|
@ -1,6 +1,6 @@
|
|||
open Gfile
|
||||
open Tools
|
||||
open Fulkerson
|
||||
(*open Fulkerson*)
|
||||
|
||||
let () =
|
||||
|
||||
|
|
@ -28,26 +28,34 @@ let () =
|
|||
in
|
||||
|
||||
(* Open file *)
|
||||
let graph = from_file infile in
|
||||
let string_graph = from_file infile in
|
||||
let graph = gmap string_graph (fun x -> int_of_string x) in
|
||||
|
||||
let flow_graph_1 = create_flow_graph graph in
|
||||
|
||||
let path : int list = [0; 2; 4; 5] in
|
||||
Printf.printf "Path: [%s]\n" (String.concat "; " (List.map string_of_int path)) ;
|
||||
|
||||
let flow_graph_2 = update_flow_graph flow_graph_1 (fun arc -> check_if_arc_is_in_path arc path) 1 in
|
||||
let new_flow_optional : int option = find_smallest_label_on_path graph path in
|
||||
let new_flow : int = Option.value new_flow_optional ~default:0 in
|
||||
Printf.printf "Flow : %d\n" new_flow ;
|
||||
|
||||
let flow_graph_2 = update_flow_graph flow_graph_1 (fun arc -> check_if_arc_is_in_path arc path) new_flow 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 string_flow_graph in
|
||||
|
||||
()
|
||||
|
||||
|
||||
|
||||
(* let g = clone_nodes graph in *)
|
||||
(*(* let g = clone_nodes graph in *)
|
||||
let () = aff (dfs graph 0 [] 3) ;
|
||||
Printf.printf "\n\n" ;
|
||||
hash
|
||||
in ()
|
||||
in () *)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
19
src/tools.ml
19
src/tools.ml
|
|
@ -43,6 +43,25 @@ let check_if_arc_is_in_path : int arc -> int list -> bool =
|
|||
in
|
||||
is_arc_in_path path
|
||||
|
||||
let find_smallest_label_on_path : int graph -> int list -> int option =
|
||||
fun graph path ->
|
||||
let rec find_smallest_label path =
|
||||
match path with
|
||||
| [] | [_] -> None (* A path must have at least two nodes to have arcs *)
|
||||
| node1 :: node2 :: rest ->
|
||||
let arc_opt = find_arc graph node1 node2 in
|
||||
match arc_opt with
|
||||
| Some arc ->
|
||||
let rest_label_opt = find_smallest_label (node2 :: rest) in
|
||||
begin
|
||||
match rest_label_opt with
|
||||
| Some rest_label -> Some (min arc.lbl rest_label)
|
||||
| None -> Some arc.lbl
|
||||
end
|
||||
| None -> None
|
||||
in
|
||||
find_smallest_label path
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -13,3 +13,7 @@ val update_flow_graph : int graph -> (int arc -> bool) -> int -> int graph
|
|||
|
||||
val check_if_arc_is_in_path : int arc -> int list -> bool
|
||||
|
||||
val find_smallest_label_on_path : int graph -> int list -> int option
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue