feat: put solutions in findpath
This commit is contained in:
parent
791deb135e
commit
b83b6af108
3 changed files with 19 additions and 13 deletions
|
|
@ -1,4 +1,5 @@
|
|||
open Graph
|
||||
open Tools
|
||||
|
||||
let child_nodes (gr : 'a graph) (a: id) = List.map (fun x -> x.tgt) (out_arcs gr a)
|
||||
|
||||
|
|
@ -41,3 +42,12 @@ let path_to_list numbers =
|
|||
in
|
||||
build_pairs numbers
|
||||
|
||||
let rec construction_gap_solution graph p1 p2 fl=
|
||||
let id_list =path_to_list (find_path graph p1 p2 (fun arc -> arc.lbl > 0)) in
|
||||
match id_list with
|
||||
|[] -> (fl,graph)
|
||||
|_ -> let min = take_min graph id_list max_int in
|
||||
let graph = update_graph graph id_list min in
|
||||
construction_gap_solution graph p1 p2 (fl+min)
|
||||
|
||||
let construct_flow_solution graph_dep graph =
|
||||
|
|
|
|||
|
|
@ -7,4 +7,8 @@ val child_nodes: 'a graph -> id -> id list
|
|||
val find_path: 'a graph -> id -> id -> ('a arc -> bool) -> id list
|
||||
|
||||
(* for example take [1;0;2;4] into [(1,0);(0,2);(2,4)]*)
|
||||
val path_to_list: int list -> (int * int) list
|
||||
val path_to_list: int list -> (int * int) list
|
||||
|
||||
val construction_gap_solution : int graph -> int -> int-> int ->(int *int graph)
|
||||
|
||||
val construct_flow_solution : int graph -> int graph -> int graph
|
||||
16
src/ftest.ml
16
src/ftest.ml
|
|
@ -1,14 +1,6 @@
|
|||
open Gfile
|
||||
open Tools
|
||||
open Findpath
|
||||
let rec mainloop graph p1 p2 fl=
|
||||
let id_list =path_to_list (find_path graph p1 p2 (fun arc -> arc.lbl > 0)) in
|
||||
match id_list with
|
||||
|[] -> (fl,graph)
|
||||
|_ -> let min = take_min graph id_list max_int in
|
||||
let graph = update_graph graph id_list min in
|
||||
mainloop graph p1 p2 (fl+min)
|
||||
|
||||
let () =
|
||||
|
||||
(* Check the number of command-line arguments *)
|
||||
|
|
@ -37,16 +29,16 @@ let () =
|
|||
in
|
||||
|
||||
(* Open file *)
|
||||
let graph = from_file infile in
|
||||
let () =export outfile2 graph in
|
||||
let graph_depart = from_file infile in
|
||||
let () =export outfile2 graph_depart in
|
||||
(*let () = export outfile graph in *)
|
||||
let graph = gmap graph (fun x -> (int_of_string x)) in
|
||||
let graph = gmap graph_depart (fun x -> (int_of_string x)) in
|
||||
|
||||
(*let id_list =path_to_list (find_path graph 0 5 (fun arc -> arc.lbl > 0)) in
|
||||
let min = take_min graph id_list max_int in
|
||||
let graph = update_graph graph id_list min in*)
|
||||
(*List.iter (fun x -> Printf.printf "%d " x) id_list; Printf.printf "\n\n%d " min*)
|
||||
let (fl,graph)= mainloop graph source sink 0 in
|
||||
let (fl,graph)= construction_gap_solution graph source sink 0 in
|
||||
let graph = gmap graph (fun x -> (string_of_int x)) in
|
||||
let () =export outfile graph in
|
||||
Printf.printf "Le flot max = %d\n" fl ; ()
|
||||
Loading…
Reference in a new issue