break : fixing solution graph flow and 3rd file open

This commit is contained in:
Leandro-rdz 2024-12-09 15:22:10 +01:00
parent a0a1c78910
commit c942096523
4 changed files with 23 additions and 15 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
_build/
outfile
final
graphdepart
*~
*.exe

View file

@ -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

View file

@ -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
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

View file

@ -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 ; ()