Implement and call iterate function
This commit is contained in:
parent
2cad93c7ff
commit
83c6b455be
3 changed files with 69 additions and 15 deletions
20
graphs/flow_graph_ana.tx
Normal file
20
graphs/flow_graph_ana.tx
Normal file
|
|
@ -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 0
|
||||
e 4 2 1 0
|
||||
e 3 4 2 0
|
||||
e 2 5 3 4
|
||||
e 1 4 4 0
|
||||
e 1 3 5 0
|
||||
e 1 2 6 4
|
||||
e 0 3 7 0
|
||||
e 0 1 8 4
|
||||
|
||||
% End of graph
|
||||
50
src/ftest.ml
50
src/ftest.ml
|
|
@ -1,5 +1,5 @@
|
|||
open Gfile
|
||||
(* open Tools *)
|
||||
open Tools
|
||||
open Fulkerson
|
||||
|
||||
let () =
|
||||
|
|
@ -20,25 +20,47 @@ let () =
|
|||
(* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *)
|
||||
|
||||
let infile = Sys.argv.(1)
|
||||
(* and outfile = Sys.argv.(4) *)
|
||||
and outfile = Sys.argv.(4)
|
||||
|
||||
(* These command-line arguments are not used for the moment. *)
|
||||
and _source = int_of_string Sys.argv.(2)
|
||||
and _sink = int_of_string Sys.argv.(3)
|
||||
and source = int_of_string Sys.argv.(2)
|
||||
and target = int_of_string Sys.argv.(3)
|
||||
in
|
||||
|
||||
(* Open file *)
|
||||
let graph = from_file infile in
|
||||
(* let g = clone_nodes graph in *)
|
||||
let () = aff (find_path graph 0 4) ;
|
||||
Printf.printf "\n\n" ;
|
||||
in ()
|
||||
(* export outfile graph *)
|
||||
Printf.printf "Source: %d\n" source ;
|
||||
Printf.printf "Target: %d\n" target ;
|
||||
|
||||
|
||||
(* Open file *)
|
||||
let string_graph = from_file infile in
|
||||
let graph = gmap string_graph (fun x -> int_of_string x) in
|
||||
|
||||
let flow_graph = create_flow_graph graph in
|
||||
|
||||
(* iteration 1 *)
|
||||
|
||||
let flow_graph = iterate graph flow_graph source target in
|
||||
|
||||
(* iteration 2 *)
|
||||
|
||||
let flow_graph = iterate graph flow_graph source target in
|
||||
|
||||
(* iteration 3 *)
|
||||
|
||||
let flow_graph = iterate graph flow_graph source target in
|
||||
|
||||
(* save result to file *)
|
||||
|
||||
let string_flow_graph = gmap flow_graph (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
|
||||
|
||||
() *)
|
||||
()
|
||||
|
||||
|
||||
|
||||
(*(* let g = clone_nodes graph in *)
|
||||
let () = aff (dfs graph 0 [] 3) ;
|
||||
Printf.printf "\n\n" ;
|
||||
hash
|
||||
in () *)
|
||||
|
|
@ -38,4 +38,16 @@ let rec aff nodes =
|
|||
| [] -> ()
|
||||
| x::rest -> Printf.printf "%d " x ; aff rest
|
||||
|
||||
|
||||
let iterate graph flow_graph src tgt =
|
||||
let path : int list = find_path graph src tgt in
|
||||
Printf.printf "Path: [%s]\n" (String.concat "; " (List.map string_of_int path)) ;
|
||||
|
||||
let new_flow_optional : int option = find_max_flow_on_path graph flow_graph path in
|
||||
let new_flow : int = Option.value new_flow_optional ~default:0 in
|
||||
Printf.printf "Flow: %d\n" new_flow ;
|
||||
|
||||
update_flow_graph flow_graph (fun arc -> check_if_arc_is_in_path arc path) (fun arc -> check_if_backward_arc_is_in_path arc path) new_flow
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in a new issue