3

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!

Community
  • 1
  • 1
repeat
  • 18,496
  • 4
  • 54
  • 166
  • 1
    +1, good visualisations for CLP(FD) tasks and search processes definitely warrant some attention. Make sure to check out Neumerkel et al., [*Visualizing Solutions with Viewers*](http://www.complang.tuwien.ac.at/ulrich/papers/PDF/wlpe97.pdf) for some ideas. – mat Apr 07 '15 at 11:22

2 Answers2

2

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:

CP-Viz Architecture

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
jschimpf
  • 4,904
  • 11
  • 24
2

SWI-Prolog has a pack to interface to .dia, one for graphml files, and one for graphviz

Anniepoo
  • 2,152
  • 17
  • 17