feat: ajout de export

This commit is contained in:
Baptiste 2024-12-02 10:51:05 +01:00
parent 5151d5d716
commit 99c60192a7
2 changed files with 33 additions and 0 deletions

View file

@ -112,3 +112,32 @@ let from_file path =
close_in infile ;
final_graph
(* writes a string graph in dot format *)
let export path (graph : string graph) =
(* Open a write-file. *)
let ff = open_out path in
(* Write in this file. *)
fprintf ff "digraph finite_state_machine {\n";
fprintf ff " fontname=\"Helvetica,Arial,sans-serif\"\n";
fprintf ff " node [fontname=\"Helvetica,Arial,sans-serif\"]\n" ;
fprintf ff " edge [fontname=\"Helvetica,Arial,sans-serif\"]\n" ;
fprintf ff " rankdir=LR;\n" ;
fprintf ff " node [shape = doublecircle]; ";
(* Write all nodes (with fake coordinates) *)
n_iter_sorted graph (fun id -> fprintf ff "%d " id) ;
fprintf ff ";\n" ;
fprintf ff " node [shape = circle];\n";
(* Write all arcs *)
let _ = e_fold graph (fun count arc -> fprintf ff " %d -> %d [label = \"%s\"];\n" arc.src arc.tgt arc.lbl ; count+1) 0 in
fprintf ff "}\n" ;
close_out ff ;
()

View file

@ -13,6 +13,10 @@ val from_file: path -> string graph
val write_file: path -> string graph -> unit
(* Convert a string graph into a dot file and write it in path *)
val export: path -> string graph -> unit
(* The format of files is compatible with the files generated by:
https://algorithms.discrete.ma.tum.de/graph-algorithms/flow-ford-fulkerson/index_en.html
*)