作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做自动机的组合。所以最后,我还想画出组合的自动机。那么在 ocaml 中是否有任何库?或者是否有为任何图形可视化工具编写的 ocaml 包装器?我已经用谷歌搜索了它,但对 ocaml 没有太多了解。对 ocamlgraph 有什么意见吗?我将在组合自动机中获得 100 多个状态。
最佳答案
使用ocamlgraph -- 它是一个图形库,可以为您生成一个点/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)
(* 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 - 如何在 ocaml 中可视化/绘制自动机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8999557/
为了了解 Redux 的动机,我阅读了官方链接 https://redux.js.org/introduction/motivation还有这个 stackoverflow 问题 Explain Re
您好,这个 firebase 函数曾经可以工作,但知道它现在工作时间更长了,我收到此错误消息 Function returned undefined, expected Promise or valu
我是一名优秀的程序员,十分优秀!