diff --git a/README.md b/README.md index a2e1417..3e2d9ab 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,12 @@ A [`Makefile`](Makefile) provides some useful commands: In case of trouble with the VSCode extension (e.g. the project does not build, there are strange mistakes), a common workaround is to (1) close vscode, (2) `make clean`, (3) `make build` and (4) reopen vscode (`make edit`). +## Graphviz : + +```bash +dot path/to/graphviz.txt -T > out.png +``` + +```bash +open out.png +``` \ No newline at end of file diff --git a/src/ftest.ml b/src/ftest.ml index 80489df..7e4a7c4 100644 --- a/src/ftest.ml +++ b/src/ftest.ml @@ -31,5 +31,6 @@ let () = (* Rewrite the graph that has been read. *) let () = write_file outfile graph in + (* let () = export outfile graph in *) () diff --git a/src/gfile.ml b/src/gfile.ml index d6a53ac..91be5be 100644 --- a/src/gfile.ml +++ b/src/gfile.ml @@ -111,4 +111,16 @@ let from_file path = close_in infile ; final_graph - + +let export (p: path) (g: string graph) : unit = + let ff = open_out p in + let string_arc = e_fold g (fun acc arc -> acc^(Printf.sprintf " %d -> %d [label = \"%s\"];\n" arc.src arc.tgt arc.lbl)) "" in + fprintf ff + "digraph finite_state_machine {\n + fontname=\"Helvetica,Arial,sans-serif\" + node [fontname=\"Helvetica,Arial,sans-serif\"] + edge [fontname=\"Helvetica,Arial,sans-serif\"] + rankdir=LR; + node [shape = circle]; + %s + }" string_arc diff --git a/src/gfile.mli b/src/gfile.mli index 465e693..aa76571 100644 --- a/src/gfile.mli +++ b/src/gfile.mli @@ -12,6 +12,8 @@ val from_file: path -> string graph * If necessary, use gmap (to be written by you) to prepare the input graph. *) val write_file: path -> string graph -> unit +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