From c9420965235a40d341a0080cfb680f4e847ab169 Mon Sep 17 00:00:00 2001 From: Leandro-rdz Date: Mon, 9 Dec 2024 15:22:10 +0100 Subject: [PATCH] break : fixing solution graph flow and 3rd file open --- .gitignore | 1 + Makefile | 4 +++- src/findpath.ml | 19 ++++++++++--------- src/ftest.ml | 14 +++++++++----- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 171512f..72fba10 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ _build/ outfile +final graphdepart *~ *.exe diff --git a/Makefile b/Makefile index 6437c09..434e5a6 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ src?=0 dst?=5 graph?=graph1.txt graphdot?=outfile +graphfinal?=final all: build @@ -20,11 +21,12 @@ edit: demo: build @echo "\n ⚡ EXECUTING ⚡\n" - ./ftest.exe graphs/${graph} $(src) $(dst) outfile graphdepart + ./ftest.exe graphs/${graph} $(src) $(dst) outfile graphdepart final @echo "\n 🥁 RESULT (content of outfile) 🥁\n" @cat outfile make dot graphdot="graphdepart" make dot graphdot="outfile" + make dot graphdot="final" clean: find -L . -name "*~" -delete rm -f *.exe diff --git a/src/findpath.ml b/src/findpath.ml index 9ee55d7..d6bcfad 100644 --- a/src/findpath.ml +++ b/src/findpath.ml @@ -50,13 +50,14 @@ let path_to_list numbers = let graph = update_graph graph id_list min in construction_gap_solution graph p1 p2 (fl+min) -let construct_flow_solution graph_dep graph = +let construct_flow_solution graph_dep graph_end = let return_graph = clone_nodes graph_dep in - let rec iter_on_arc arc = - let reverse_arc_graph = find_arc graph arc.tgt arc.src in - match reverse_arc_graph with - | None -> () - | Some x -> let return_graph = add_arc return_graph arc.src arc.tgt x.lbl - in - e_iter graph_dep iter_on_arc in - return_graph \ No newline at end of file + let dep_arc = list_arc graph_dep in + let rec iter_on_arc graph =function + |[]-> graph + |arc::rest -> let rev_arc= find_arc graph_end arc.tgt arc.src in + match rev_arc with + |None->iter_on_arc (add_arc graph arc.src arc.tgt 0) rest + |Some x ->iter_on_arc (add_arc graph arc.src arc.tgt x.lbl) rest +in +iter_on_arc return_graph dep_arc \ No newline at end of file diff --git a/src/ftest.ml b/src/ftest.ml index 47f663f..afd2d69 100644 --- a/src/ftest.ml +++ b/src/ftest.ml @@ -4,7 +4,7 @@ open Findpath let () = (* Check the number of command-line arguments *) - if Array.length Sys.argv <> 6 then + if Array.length Sys.argv <> 7 then begin Printf.printf "\n ✻ Usage: %s infile source sink outfile\n\n%s%!" Sys.argv.(0) @@ -22,6 +22,7 @@ let () = let infile = Sys.argv.(1) and outfile = Sys.argv.(4) and outfile2 = Sys.argv.(5) + and final = Sys.argv.(6) (* These command-line arguments are not used for the moment. *) and source = int_of_string Sys.argv.(2) @@ -31,14 +32,17 @@ let () = (* Open file *) let graph_depart = from_file infile in let () =export outfile2 graph_depart in + let graph_depart = gmap graph_depart (fun x -> (int_of_string x)) in (*let () = export outfile graph in *) - let graph = gmap graph_depart (fun x -> (int_of_string x)) in - + let graph =graph_depart 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)= construction_gap_solution graph source sink 0 in + let (fl,fgraph)= construction_gap_solution graph source sink 0 in + let graph = construct_flow_solution graph_depart fgraph in let graph = gmap graph (fun x -> (string_of_int x)) in - let () =export outfile graph in + let fgraph = gmap fgraph (fun x -> (string_of_int x)) in + let () =export outfile fgraph in + let () =export final graph in Printf.printf "Le flot max = %d\n" fl ; () \ No newline at end of file