add Graphviz support
- add export function to gfile.ml and .mli - add commands of Graphviz to README.md - add a commented implementation to ftest.ml
This commit is contained in:
parent
2676b59b13
commit
636d887247
4 changed files with 25 additions and 1 deletions
|
|
@ -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
|
||||
```
|
||||
|
|
@ -31,5 +31,6 @@ let () =
|
|||
(* Rewrite the graph that has been read. *)
|
||||
let () = write_file outfile graph in
|
||||
|
||||
(* let () = export outfile graph in *)
|
||||
()
|
||||
|
||||
|
|
|
|||
14
src/gfile.ml
14
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue