Make function that finds max flow also take backward arches into account
This commit is contained in:
parent
8228b64eed
commit
1f6c4eaec5
5 changed files with 52 additions and 6 deletions
20
graphs/flow_graph_ana.txt
Normal file
20
graphs/flow_graph_ana.txt
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 10
|
||||
e 4 2 1 0
|
||||
e 3 4 2 6
|
||||
e 2 5 3 4
|
||||
e 1 4 4 12
|
||||
e 1 3 5 0
|
||||
e 1 2 6 4
|
||||
e 0 3 7 6
|
||||
e 0 1 8 8
|
||||
|
||||
% End of graph
|
||||
25
graphs/graph_ana.txt
Normal file
25
graphs/graph_ana.txt
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
%% Test graph #1
|
||||
|
||||
%% Nodes
|
||||
|
||||
n 20 300 0 % S This is node #0, with its coordinates (which are not used by the algorithms).
|
||||
n 200 300 1 % A
|
||||
n 200 200 2 % B
|
||||
n 200 400 3 % C
|
||||
n 380 300 4 % D
|
||||
n 380 200 5 % T This is node #5.
|
||||
|
||||
|
||||
%% Edges (arcs)
|
||||
|
||||
e 0 1 0 10 % An arc from 0 to 2, labeled "8". The second 0 is useless.
|
||||
e 0 3 1 10
|
||||
e 1 2 2 4
|
||||
e 1 3 3 2
|
||||
e 1 4 4 8
|
||||
e 2 5 5 10
|
||||
e 3 4 6 9
|
||||
e 4 2 7 6
|
||||
e 4 5 8 10
|
||||
|
||||
% End of graph
|
||||
|
|
@ -35,7 +35,7 @@ let () =
|
|||
|
||||
(* iteration 1 *)
|
||||
|
||||
let path_1 : int list = [0; 2; 4; 5] in
|
||||
let path_1 : int list = [0; 1; 4; 5] in
|
||||
Printf.printf "Path 1: [%s]\n" (String.concat "; " (List.map string_of_int path_1)) ;
|
||||
|
||||
let new_flow_optional_1 : int option = find_max_flow_on_path graph flow_graph_0 path_1 in
|
||||
|
|
@ -57,7 +57,7 @@ let () =
|
|||
|
||||
(* iteration 3 *)
|
||||
|
||||
let path_3 : int list = [0; 1; 4; 5] in
|
||||
let path_3 : int list = [0; 3; 4; 1; 2; 5] in
|
||||
Printf.printf "Path 3: [%s]\n" (String.concat "; " (List.map string_of_int path_3)) ;
|
||||
|
||||
let new_flow_optional_3 : int option = find_max_flow_on_path graph flow_graph_2 path_3 in
|
||||
|
|
|
|||
|
|
@ -61,17 +61,19 @@ let find_max_flow_on_path : int graph -> int graph -> int list -> int option =
|
|||
| Some rest_difference -> Some (min (arc1.lbl - arc2.lbl) rest_difference)
|
||||
| None -> Some (arc1.lbl - arc2.lbl)
|
||||
end
|
||||
| (None, None, Some arc1_rev, Some arc2_rev) ->
|
||||
| (None, None, Some _, Some arc2_rev) ->
|
||||
let rest_difference_opt = find_max_flow_on_path (node2 :: rest) in
|
||||
begin
|
||||
match rest_difference_opt with
|
||||
| Some rest_difference -> Some (min (arc2_rev.lbl - arc1_rev.lbl) rest_difference)
|
||||
| None -> Some (arc2_rev.lbl - arc1_rev.lbl)
|
||||
| Some rest_difference -> Some (min (arc2_rev.lbl) rest_difference)
|
||||
| None -> Some (arc2_rev.lbl)
|
||||
end
|
||||
| _ -> None
|
||||
in
|
||||
find_max_flow_on_path path
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -16,4 +16,3 @@ val check_if_arc_is_in_path : int arc -> int list -> bool
|
|||
val find_max_flow_on_path : int graph -> int graph -> int list -> int option
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue