When writing an answer to the recent question Prolog Constraint Processing : Packing Squares I wanted to visualize the answers that Prolog + clpfd gave me.
To do that I wrote some dirty Prolog code for emitting suitable ImageMagick commands by using Prolog builtin "predicates" format/2 and write/1, like so:
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(_,_,_).
The quick hack worked well, however I feel the code I wrote feels bloated and somewhat dirty... I would like to find a more declarative alternative for doing 2D visualizations like these. I feel like SVG could be a good choice.
Now, SVG is based on XML and several Prolog systems offer libraries for handling XML as a part of their standard libraries.
Are there Prolog libraries for SVG? Or other suitable 2D/(3D) data-visualization frameworks/tools with Prolog bindings?
What reasonable approaches do you see? Thank you in advance!
You should have a look at the work of Helmut Simonis et al, who have done extensive work in this area in the context of Cosytec CHIP and the European DiSCiPL project.
A more recent open-source offshoot of this is the 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 uses XML traces and can produce and display SVG output:

SWI-Prolog has a pack to interface to .dia, one for graphml files, and one for graphviz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With