path-to-gif.lp 811 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
% To use with something like:
%  python -m biseau examples/path-to-gif.lp -o out/out.gif

% Graph.
link(a,(b;c)).
link(b,d).
link(d,(e;f)).
link(c,(e;g)).
link(e,h).
start(a). target(h).
nb_link(N):- N={link(_,_)}.

% Initial state.
place(1,N) :- start(N).

% Choose a path.
1 { place(I+1,N): link(T,N) } 1 :- place(I,T) ; not target(T) ; I<Nlink ; nb_link(Nlink).

% Discards paths not terminating at target, and looping paths.
:- not place(_,T) ; target(T).
:- place(I,N) ; place(J,N) ; I!=J.

Lucas Bourneuf's avatar
Lucas Bourneuf committed
23
% Colorize the nodes on the path.
24
color(N,green) :- place(_,N).
Lucas Bourneuf's avatar
Lucas Bourneuf committed
25

26 27 28 29
% Highlight the path: make edges red and directed.
color(A,B,red) :- link(A,B) ; place(_,A) ; place(_,B).
dot_property(A,B,arrowhead,normal) :- link(A,B) ; place(_,A) ; place(_,B).
dot_property(A,B,penwidth,5) :- link(A,B) ; place(_,A) ; place(_,B).