pri*_*nka 14 ocaml visualization image-graphviz
我正在做自动机的组合.所以在最后,我想绘制组合自动机.所以在ocaml中有没有任何库?或者是否有为任何图形可视化工具编写的ocaml包装器?我已经谷歌搜索了,但没有得到太多的ocaml.关于ocamlgraph的任何评论?我将在组合自动机中获得超过100个州.
lam*_*wer 17
使用ocamlgraph - 它是一个图形库,可以为你生成一个dot/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)
Run Code Online (Sandbox Code Playgroud)
你可以写你的程序; 例如:
(* 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 ...
Run Code Online (Sandbox Code Playgroud)