diff --git a/src/FFAlgorithm.ml b/src/FFAlgorithm.ml index cf8fb57..a1d43f4 100644 --- a/src/FFAlgorithm.ml +++ b/src/FFAlgorithm.ml @@ -15,20 +15,20 @@ let rec create_arcs_from_nodes = function (* Return the minimum value of a path's edge*) -let get_min_label_from_path (graph : float graph) (path : (id * id) list) = - let min = 999999999.0 in +let get_min_label_from_path (graph : (int * int) graph) (path : (id * id) list) = + let min = 999999999 in List.fold_left ( fun acu (id1, id2) -> let label = ( match find_arc graph id1 id2 with |None -> 999999999 - |Some x -> x) in + |Some (cout,capa) -> cout) in if label < acu then label else acu ) min path (* Add a value to every egde of a path *) -let add_value_to_arcs (graph : float graph) (path : (id * id) list) (value : float) = +let add_value_to_arcs (graph : (int * int) graph) (path : (id * id) list) (value : int) = List.fold_left ( fun acu (id1, id2) -> @@ -46,7 +46,7 @@ let rev_arcs (path : (id * id) list) = (* Get the final graph after the FFalgorithm The label of every arc becomes "x" where x is the value of the opposite arc on the residual graph*) -let get_final_graph (initGraph : float graph) (residualGraph : float graph) = +let get_final_graph (initGraph : (int * int) graph) (residualGraph : (int * int) graph) = (* First get the initial and residual graph as string graphs *) let initGraphString = initGraph in @@ -56,23 +56,23 @@ let get_final_graph (initGraph : float graph) (residualGraph : float graph) = (* For every arc in the initial graph we get the label of the opposite arc in the residual graph. If it exists then the arc of the final graph gets the label "x", - "0.0" otherwise*) + "0" otherwise*) e_fold initGraph ( - fun acu id1 id2 x -> + fun acu id1 id2 (cout_x,capa_x) -> let label_rev_arc = match find_arc residualGraphString id2 id1 with - |None -> 0.0 - |Some x -> (match find_arc initGraphString id2 id1 with - |None -> x - |Some y -> Float.sub x y ) in - let label_rev_arc = if (label_rev_arc > 0.0) then (string_of_float label_rev_arc) else "0" in - new_arc acu id1 id2 label_rev_arc + |None -> 0 + |Some (cout_x,capa_x) -> (match find_arc initGraphString id2 id1 with + |None -> cout_x + |Some (cout_y, capa_y) -> Int.sub cout_x cout_y ) in + let label_rev_arc = if (label_rev_arc > 0) then ((string_of_int label_rev_arc),(string_of_int capa_x )) else "cout:0,capa:"^(string_of_int capa_x) in + new_arc acu id1 id2 (label_rev_arc, capa_x) ) finalGraph -let ford_fulk_algorithm (graph : float graph) (origin : id) (sink : id) = - let flow = 0.0 in +let ford_fulk_algorithm (graph : (int * int) graph) (origin : id) (sink : id) = + let flow = 0 in let initGraph = graph in let rec boucle graph origin sink flow = @@ -88,7 +88,7 @@ let ford_fulk_algorithm (graph : float graph) (origin : id) (sink : id) = let min = get_min_label_from_path graph arcs in (* Substract the min to every arc of the path *) - let graph = add_value_to_arcs graph arcs (Float.neg min) in + let graph = add_value_to_arcs graph arcs (Int.neg min) in (* Get the reverse path *) let reverse = rev_arcs arcs in @@ -97,7 +97,7 @@ let ford_fulk_algorithm (graph : float graph) (origin : id) (sink : id) = let graph = add_value_to_arcs graph reverse min in (* Add the min to the flow *) - let flow = Float.add flow min in + let flow = Int.add flow min in boucle graph origin sink flow) in let (maxFlow, residualGraph) = boucle graph origin sink flow in let finalGraph = get_final_graph initGraph residualGraph in diff --git a/src/tool.ml b/src/tool.ml index 318984d..f5c1ed6 100644 --- a/src/tool.ml +++ b/src/tool.ml @@ -12,11 +12,11 @@ let gmap gr f = let new_graph = clone_nodes gr in e_fold gr (fun acu id1 id2 x -> new_arc acu id1 id2 (f x)) new_graph -let add_arc g id1 id2 n = +let add_arc g id1 id2 cout = let f = find_arc g id1 id2 in match f with - |None->new_arc g id1 id2 n - |Some x->new_arc g id1 id2 (Int.add n x) + |None->new_arc g id1 id2 (cout,1) + |Some x->new_arc g id1 id2 ((Int.add cout x),1) let get_max_id graph = n_fold graph (fun acu id -> max id acu) 0 \ No newline at end of file diff --git a/src/tool.mli b/src/tool.mli index a699194..9cd712c 100644 --- a/src/tool.mli +++ b/src/tool.mli @@ -6,6 +6,6 @@ val clone_nodes: 'a graph -> 'b graph (* Apply a function f to every label of the graph's arcs *) val gmap: 'a graph -> ('a -> 'b) -> 'b graph -val add_arc: (int * int) graph -> id -> id -> float -> (int * int) graph +val add_arc: (int * int) graph -> id -> id -> int -> (int * int) graph val get_max_id : 'a graph -> id \ No newline at end of file