10.02.2013 Views

A User's Guide to gringo, clasp, clingo, and iclingo

A User's Guide to gringo, clasp, clingo, and iclingo

A User's Guide to gringo, clasp, clingo, and iclingo

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

23 %<br />

24 goal(on(b1,b0)).<br />

25 goal(on(b2,b1)).<br />

26 goal(on(b0,table)).<br />

Note that the facts in Line 13–15 <strong>and</strong> 24–26 specify the initial <strong>and</strong> the goal state depicted<br />

in Line 9-11 <strong>and</strong> 19–22, respectively. We here use (uninterpreted) function on/2<br />

<strong>to</strong> illustrate another important feature available in <strong>gringo</strong>, <strong>clingo</strong>, <strong>and</strong> i<strong>clingo</strong>,<br />

namely, the possibility of instantiating variables <strong>to</strong> compound terms.<br />

4.3.2 Problem Encoding<br />

Our Blocks-World Planning encoding for i<strong>clingo</strong> makes use of declaratives #base,<br />

#cumulative, <strong>and</strong> #volatile, separating the encoding in<strong>to</strong> a static, a cumulative,<br />

<strong>and</strong> a volatile (query) part. Each of them can be further refined in<strong>to</strong> Generate, Define,<br />

Test, <strong>and</strong> Display constituents, as indicated in the comments below:<br />

1 #base.<br />

2 % Define<br />

3 location(table).<br />

4 location(X) :- block(X).<br />

5 holds(F,0) :- init(F).<br />

6 %<br />

7 #cumulative t.<br />

8 % Generate<br />

9 1 { move(X,Y,t) : block(X) : location(Y) : X != Y } 1.<br />

10 % Test<br />

11 :- move(X,Y,t),<br />

12 1 { holds(on(A,X),t-1),<br />

13 holds(on(B,Y),t-1) : B != X : Y != table }.<br />

14 % Define<br />

15 holds(on(X,Y),t) :- move(X,Y,t).<br />

16 holds(on(X,Z),t) :- holds(on(X,Z),t-1),<br />

17 { move(X,Y,t) : Y != Z } 0.<br />

18 %<br />

19 #volatile t.<br />

20 % Test<br />

21 :- goal(F), not holds(F,t).<br />

22 %<br />

23 #base.<br />

24 % Display<br />

25 #hide.<br />

26 #show move/3.<br />

In the initial #base part (Line 1–5), we define blocks <strong>and</strong> constant table as instances<br />

of predicate location/1. Moreover, we use instances of init/1 <strong>to</strong> initialize predicate<br />

holds/2 for step 0, thus, defining the conditions before the first incremental step.<br />

Note that variable F is instantiated <strong>to</strong> compound terms over function on/2.<br />

The #cumulative statement in Line 7 declares constant t as a placeholder for<br />

step numbers in the cumulative encoding part below. Here, the Generate rule in Line 9<br />

states that exactly one block X must be moved <strong>to</strong> a location Y (different from X) at each<br />

step t. The integrity constraint in Line 11–13 is used <strong>to</strong> test whether moving block X<br />

38

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!