如何在ocaml中可视化/绘制自动机?

如何在ocaml中可视化/绘制自动机?,ocaml,visualization,image-graphviz,Ocaml,Visualization,Image Graphviz,我正在做自动机的合成。最后,我还想画合成自动机。那么ocaml中是否有用于此的库?或者有没有为任何图形可视化工具编写的ocaml包装器?我已经在谷歌上搜索过了,但是没有得到多少关于ocaml的信息。对ocamlgraph有什么评论吗?我将在复合自动机中获得100多个状态。我只需将自动机作为文本写入文件(采用适合graphviz的格式),然后对该文件运行graphviz。使用——它是一个图形库,可以为您生成点/graphviz文件,但也可以做许多其他处理自动机可能感兴趣的事情。 该库可以进行定点、

我正在做自动机的合成。最后,我还想画合成自动机。那么ocaml中是否有用于此的库?或者有没有为任何图形可视化工具编写的ocaml包装器?我已经在谷歌上搜索过了,但是没有得到多少关于ocaml的信息。对ocamlgraph有什么评论吗?我将在复合自动机中获得100多个状态。

我只需将自动机作为文本写入文件(采用适合graphviz的格式),然后对该文件运行graphviz。

使用——它是一个图形库,可以为您生成点/graphviz文件,但也可以做许多其他处理自动机可能感兴趣的事情。 该库可以进行定点、生成树、图形搜索、查找强连接组件等

下面是一个完整的有向图示例,带有标记边+用于执行深度优先搜索的模块+用于创建点表示的模块:

(* representation of a node -- must be hashable *)
module Node = struct
   type t = int
   let compare = Pervasives.compare
   let hash = Hashtbl.hash
   let equal = (=)
end

(* representation of an edge -- must be comparable *)
module Edge = struct
   type t = string
   let compare = Pervasives.compare
   let equal = (=)
   let default = ""
end

(* a functional/persistent graph *)
module G = Graph.Persistent.Digraph.ConcreteBidirectionalLabeled(Node)(Edge)

(* more modules available, e.g. graph traversal with depth-first-search *)
module D = Graph.Traverse.Dfs(G)

(* module for creating dot-files *)
module Dot = Graph.Graphviz.Dot(struct
   include G (* use the graph module from above *)
   let edge_attributes (a, e, b) = [`Label e; `Color 4711]
   let default_edge_attributes _ = []
   let get_subgraph _ = None
   let vertex_attributes _ = [`Shape `Box]
   let vertex_name v = string_of_int v
   let default_vertex_attributes _ = []
  let graph_attributes _ = []
end)
这样你就可以编写你的程序了;e、 g.类似这样的情况:

(* work with the graph ... *)
let _ =
   let g = G.empty in
   let g = G.add_edge_e ...
   ...
   let file = open_out_bin "mygraph.dot" in
   let () = Dot.output_graph file g in
   ...
   if D.has_cycle g then ... else ...

我也想过。但是还有更好的选择吗?OCaml中的
图形
模块和/或
CamlPDF
包可以工作。虽然,我不会联合签署这个解决方案;你必须想出一种布局技巧。我也推荐graphviz。好的,谢谢。你能给我一些更详细的信息吗?节点的类型是
int
,那么模块
Dot
中的函数
vertex\u name
让vertex\u name v=int v的string\u