From 99c60192a79507eec696ebc05fb246e271a4498b Mon Sep 17 00:00:00 2001 From: Baptiste Date: Mon, 2 Dec 2024 10:51:05 +0100 Subject: [PATCH] feat: ajout de export --- src/gfile.ml | 29 +++++++++++++++++++++++++++++ src/gfile.mli | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/src/gfile.ml b/src/gfile.ml index d6a53ac..d791cab 100644 --- a/src/gfile.ml +++ b/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 ; + () \ No newline at end of file diff --git a/src/gfile.mli b/src/gfile.mli index 465e693..1dc5905 100644 --- a/src/gfile.mli +++ b/src/gfile.mli @@ -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 *)