使用 SVG 进行可视化

Using SVG for visualization

在写最近问题的答案时Prolog Constraint Processing : Packing Squares我想形象化Prolog + clpfd给我的答案。

为此,我编写了一些肮脏的 Prolog 代码,用于使用 Prolog 内置 "predicates" format/2write/1 发出合适的 ImageMagick 命令,如下所示:

drawBoxesWithIM_at_pix(Sizes,Positions,P) :-
    Colors = ["#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff"],
    write(' -strokewidth 2 -stroke white'),
    nth1(N,Positions,Xb+Yb),
    nth1(N,Sizes,    Wb*Hb),
    nth1(N,Colors,   Color),
    format(' -draw "fill ~sb0 roundrectangle ~d,~d ~d,~d ~d,~d"',
           [Color, Xb*P+3,Yb*P+3, (Xb+Wb)*P-3,(Yb+Hb)*P-3, P/2,P/2]),
    false.
drawBoxesWithIM_at_pix(_,_,_).

快速破解效果很好,但是我觉得我写的代码感觉臃肿而且有点脏......我想找到一个更具声明性的替代方法来进行 2D 可视化,比如这些。我觉得SVG可能是个不错的选择。

现在,SVG 基于 XML 并且一些 Prolog 系统提供用于处理 XML 的库作为其标准库的一部分。

是否有用于 SVG 的 Prolog 库?或者其他合适的 2D/(3D) 数据可视化 frameworks/tools 与 Prolog 绑定?

您认为有哪些合理的做法? 提前致谢!

你应该看看 Helmut Simonis et al, who have done extensive work in this area in the context of Cosytec CHIP and the European DiSCiPL 项目的工作。

最近的开源分支是 CP-Viz system (paper, slides). CP-Viz is distributed together with the free ECLiPSe CLP system, and to my knowledge has also been ported to SICStus and the Java-based Choco。 CP-Viz 使用 XML 轨迹并可以生成和显示 SVG 输出:

SWI-Prolog 有一个与 .dia 接口的包,一个用于 graphml 文件,一个用于 graphviz