Fix label change on backward traversing
This commit is contained in:
parent
1f6c4eaec5
commit
7fd4e25758
4 changed files with 25 additions and 8 deletions
|
|
@ -11,7 +11,7 @@ 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 4 4 4
|
||||
e 1 3 5 0
|
||||
e 1 2 6 4
|
||||
e 0 3 7 6
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ let () =
|
|||
let new_flow_1 : int = Option.value new_flow_optional_1 ~default:0 in
|
||||
Printf.printf "Flow 1: %d\n" new_flow_1 ;
|
||||
|
||||
let flow_graph_1 = update_flow_graph flow_graph_0 (fun arc -> check_if_arc_is_in_path arc path_1) new_flow_1 in
|
||||
let flow_graph_1 = update_flow_graph flow_graph_0 (fun arc -> check_if_arc_is_in_path arc path_1) (fun arc -> check_if_backward_arc_is_in_path arc path_1) new_flow_1 in
|
||||
|
||||
(* iteration 2 *)
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ let () =
|
|||
let new_flow_2 : int = Option.value new_flow_optional_2 ~default:0 in
|
||||
Printf.printf "Flow 2: %d\n" new_flow_2 ;
|
||||
|
||||
let flow_graph_2 = update_flow_graph flow_graph_1 (fun arc -> check_if_arc_is_in_path arc path_2) new_flow_2 in
|
||||
let flow_graph_2 = update_flow_graph flow_graph_1 (fun arc -> check_if_arc_is_in_path arc path_2) (fun arc -> check_if_backward_arc_is_in_path arc path_2) new_flow_2 in
|
||||
|
||||
(* iteration 3 *)
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ let () =
|
|||
let new_flow_3 : int = Option.value new_flow_optional_3 ~default:0 in
|
||||
Printf.printf "Flow 3: %d\n" new_flow_3 ;
|
||||
|
||||
let flow_graph_3 = update_flow_graph flow_graph_2 (fun arc -> check_if_arc_is_in_path arc path_3) new_flow_3 in
|
||||
let flow_graph_3 = update_flow_graph flow_graph_2 (fun arc -> check_if_arc_is_in_path arc path_3) (fun arc -> check_if_backward_arc_is_in_path arc path_3) new_flow_3 in
|
||||
|
||||
(* save result to file *)
|
||||
|
||||
|
|
|
|||
21
src/tools.ml
21
src/tools.ml
|
|
@ -13,8 +13,8 @@ let add_arc graph id1 id2 n =
|
|||
|
||||
let create_flow_graph graph = gmap graph (fun _ -> 0)
|
||||
|
||||
let update_flow_graph : int graph -> (int arc -> bool) -> int -> int graph =
|
||||
fun original_graph condition increment ->
|
||||
let update_flow_graph : int graph -> (int arc -> bool) -> (int arc -> bool) -> int -> int graph =
|
||||
fun original_graph condition backward_condition increment ->
|
||||
let new_graph =
|
||||
e_fold
|
||||
original_graph
|
||||
|
|
@ -22,6 +22,8 @@ let update_flow_graph : int graph -> (int arc -> bool) -> int -> int graph =
|
|||
let modified_arc =
|
||||
if condition arc then
|
||||
{ arc with lbl = arc.lbl + increment }
|
||||
else if backward_condition arc then
|
||||
{ arc with lbl = arc.lbl - increment }
|
||||
else
|
||||
arc
|
||||
in
|
||||
|
|
@ -36,7 +38,20 @@ let check_if_arc_is_in_path : int arc -> int list -> bool =
|
|||
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
|
||||
if (node1, node2) = (arc.src, arc.tgt) then
|
||||
true
|
||||
else
|
||||
is_arc_in_path (node2 :: rest)
|
||||
in
|
||||
is_arc_in_path path
|
||||
|
||||
let check_if_backward_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 (node2, node1) = (arc.src, arc.tgt) then
|
||||
true
|
||||
else
|
||||
is_arc_in_path (node2 :: rest)
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@ val add_arc: int graph -> id -> id -> int -> int graph
|
|||
(* try not to lose genericity *)
|
||||
val create_flow_graph: 'a graph -> int graph
|
||||
|
||||
val update_flow_graph : int graph -> (int arc -> bool) -> int -> int graph
|
||||
val update_flow_graph : int graph -> (int arc -> bool) -> (int arc -> bool) -> int -> int graph
|
||||
|
||||
val check_if_arc_is_in_path : int arc -> int list -> bool
|
||||
|
||||
val check_if_backward_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