feat: ajout de export
This commit is contained in:
parent
5151d5d716
commit
99c60192a7
2 changed files with 33 additions and 0 deletions
29
src/gfile.ml
29
src/gfile.ml
|
|
@ -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 ;
|
||||
()
|
||||
|
|
@ -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
|
||||
*)
|
||||
|
|
|
|||
Loading…
Reference in a new issue