Visualsing problems with ASP

ASPViz is a simple tool for visualising outcomes (answer sets) of answer set programs in, using the language of answer set programming itself as the graphics input language.

The language itself is simly a set of ASP atoms which should be concluded by your program to produce output, the set of currently supported graphics primitives is specified in the lib/aspvizlib2d.lp in the file below.

The tool is written in the java language and uses the Standard Widget Toolkit (SWT) for graphical display.

Examples

Here are some basic examples showing the capabilities of the tool: The first is a rendering and corresponding program for Martin Brain's ASP Sudoku solver, the second is a rendering of a simple path-finding planning problem and the third is a rendering of the Knigths tour problem.
Output Problem program Visualisation Program
 
subSize(sub).  
position(1 .. sub*sub).

#domain position(X).
#domain position(XA).
#domain position(XB).
#domain position(Y).
#domain position(YA).
#domain position(YB).
#domain value(N).
#domain value(NA).
#domain value(NB).


value(1 .. sub*sub).
state(X,Y,N):- initial(X,Y,N).
1 { state(X,Y,NU) : value(NU) } 1 .
:- state(XA,Y,N), state(XB,Y,N), XA != XB.
:- state(X,YA,N), state(X,YB,N), YA != YB.
sameSubSquare(NA,NB) :- A = (NA - 1) / sub, B = (NB - 1) / sub, A = B.
:- state(XA,YA,N), state(XB,YB,N), 
   sameSubSquare(XA,XB), sameSubSquare(YA,YB), XA != XB, YA != YB.
num(0..9).

scale_canvas(2,2). translate_canvas(20,20). background_color(white).

brush(light).brush_color(light,rgb(5,5,5)). brush_width(light,1).

brush(hard). brush_color(hard,black). brush_width(hard,2).

font(inferred). font_size(inferred,12).
font(initial). font_style(initial,bold). font_size(initial,12).

% vertical lines
draw_line(light,p(X*30,0),p(X*30,9*30)) :- num(X), (X mod 3)!=0.
draw_line(hard,p(X*30,0),p(X*30,9*30)) :- num(X), (X mod 3)==0.
draw_line(light,p(0,Y*30),p(9*30,Y*30)) :- num(Y), (Y mod 3)!=0.
draw_line(hard,p(0,Y*30),p(9*30,Y*30)) :- num(Y), (Y mod 3)==0.
% top and left lines
draw_line(hard,p(0,0),p(0,9*30)).
draw_line(hard,p(0,0),p(9*30,0)).
% draw cells (initial)
draw_text(initial,c,c,p((PX - 1) * 30+15,(PY - 1) *30+15),V) :-  
initial(PX,PY,V),
num(PX;PY;V).
% draw cells (inferred)
draw_text(inferred,c,c,p((PX - 1) * 30 + 15,(PY - 1) *30 + 15),V) :- 
state(PX,PY,V), not initial(PX,PY,V),
num(PX;PY;V).
 
#hide . 
#show p(X,Y).
#show move(X,Y).
#show stay(X).
#show invalid.
#show canmove(D,T).
#show blocked(X).
#show badmoveto(X,Y).
dir(n;s;e;w).

0{move(T,D):time(T)}1:- time(T),dir(D).
:- move(T,D1),move(T,D2),D1!=D2, dir(D1;D2),time(T).
%:- p(T,psn(X,Y)), blocked(psn(X,Y)), pos(X;Y),time(T).
:- move(T,D),p(T,psn(X,Y)),target(psn(X,Y)),pos(X;Y),dir(D),time(T).
:- p(T1,psn(X,Y)), p(T2,psn(X,Y)),T2<T1, not target(psn(X,Y)),pos(X;Y), time(T1;T2).
% movement vectors
d(e,1,0). d(w,-1,0). d(n,0,1). d(s,0,-1).
moved(T):- move(T,D),time(T),dir(D).
%move effect
p(T+1,psn(X+DX,Y+DY)):- p(T,psn(X,Y)),
move(T,D), d(D,DX,DY),time(T),pos(X;Y).

% inertia
p(T+1,psn(X,Y)):-p(T,psn(X,Y)),
not moved(T), time(T),pos(X;Y).

p(0,psn(X,Y)):- initial(psn(X,Y)),pos(X;Y).
correct :- p(T+1,Dest),target(Dest),time(T).
:- not correct.
translate_canvas(20,20).
scale_canvas(1,1).
background_color(white).

layer(fg).
layer(bg).
layer_above(top,bg).

brush(obrush).
brush_color(obrush,white).
sprite(obstacle,"examples/maze/obstacle.png").
sprite_layer(obstacle,bg).

%fill_rect(obrush,white,p(X*40-25,Y*40-25),40,40) :- blocked(psn(X,Y)),pos(X;Y).
draw_sprite(obstacle,p(X*40,Y*40),c,c) :- blocked(psn(X,Y)),pos(X;Y).


sprite(target,"examples/maze/target.png").
sprite_layer(target,bg).
%draw_sprite(target,p(X*40,Y*40),c,c) :- target(psn(X,Y)),pos(X;Y).

sprite(home,"examples/maze/start.png").
draw_sprite(home,p(X*40,Y*40),c,c) :- p(0,psn(X,Y)),pos(X;Y).


% start of per-frame stuff
{frame(T)}:-time(T).
:- frame(T1), frame(T2), T1!=T2,time(T1;T2).
gotframe:- frame(T), time(T).
:- not gotframe. 

font(dfl).
font_color(dfl,white).
font_layer(dfl,top).

draw_text(dfl,c,c,p(X*40-15,Y*40+15),T) :- p(T,psn(X,Y)), pos(X;Y), frame(K),K>=T,time(K;T).

sprite(mouse,"examples/maze/mouse.png").
draw_sprite(mouse,p(X*40,Y*40),c,c) :- p(T,psn(X,Y)),pos(X;Y),time(T),frame(T).
sprite_layer(mouse,fg).

brush(db).
brush_width(db,4).
brush_color(db,green).
brush_layer(db,fg).
draw_line(db,p(X1*40,Y1*40),p(X2*40,Y2*40)) :- p(T,psn(X1,Y1)),p(T+1,psn(X2,Y2)), frame(K),K>T,time(K;T),pos(X1;X2;Y1;Y2).

Download

The source code (including dependencies for linux) is available here:
aspviz-0.2.4.tar.gz 1 Mar. 2010
aspviz-0.2.3.tar.gz (zip) 29 Oct. 2009
aspviz-0.2.2.tar.gz 13 Sep. 2009
aspviz-0.2.1.tar.gz (zip) 12 Dec. 2008
aspviz-0.1.1.tar.gz< 15 Aug. 2008