Implement recursive ford fulkerson function
This commit is contained in:
parent
a565cdcaeb
commit
df2b8106fa
2 changed files with 12 additions and 12 deletions
|
|
@ -36,9 +36,7 @@ let () =
|
|||
|
||||
let flow_graph = create_flow_graph graph in
|
||||
|
||||
let flow_graph = iterate_ford_fulkerson graph flow_graph source target in
|
||||
let flow_graph = iterate_ford_fulkerson graph flow_graph source target in
|
||||
let flow_graph = iterate_ford_fulkerson graph flow_graph source target in
|
||||
let flow_graph = run_ford_fulkerson graph flow_graph source target in
|
||||
|
||||
let string_flow_graph = gmap flow_graph (fun x -> string_of_int x) in
|
||||
|
||||
|
|
|
|||
|
|
@ -38,15 +38,17 @@ let rec aff nodes =
|
|||
| [] -> ()
|
||||
| x::rest -> Printf.printf "%d " x ; aff rest
|
||||
|
||||
let iterate_ford_fulkerson graph flow_graph src tgt =
|
||||
let rec run_ford_fulkerson 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
|
||||
|
||||
match path with
|
||||
| [] -> flow_graph
|
||||
| _ ->
|
||||
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;
|
||||
let updated_flow_graph = 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 in
|
||||
run_ford_fulkerson graph updated_flow_graph src tgt
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue