1

I have the following blocks world program and I want to create a serializable plan for the following scenario:

Initially:
loc(m)=table, loc(l)=m, loc(a)=l, loc(b)=a, loc(c)=b,
loc(o)=table, loc(n)=o, loc(d)=n, loc(e)=d, loc(j)=e,
loc(k)=j, loc(f)=table, loc(g)=f, loc(h)=g, loc(i)=h

In maxstep:
loc(e)=j, loc(a)= e, loc(n)=a, loc(i)=d, loc(h)=i,
loc(m)=h, loc(o)= m, loc(k)=g, loc(c)=k, loc(b)=c,
loc(l)=b.

The scenario says that initially block m is on the table, block l is on block m and so forth. The blocks world scenario would look something like the following:

[initial state][1]

Following is my code:

location(B) :- block(B).

location(table).

% two blocks can't be on the same block at the same time
:- 2{on(BB,B,T)}, block(B), T = 0..m.

on(B,L,T+1) :- move(B,L,T).

:- not {move(BB,LL,T)} grippers, T = 0..m-1.

:- move(B,L,T), on(B1,B,T).

:- move(B,B1,T), move(B1,L,T).

1{on(B,LL,0):location(LL)}1 :- block(B).

:- not 1{on(B,LL,T)}1, block(B), T=1..m.

{move(B,L,T)} :- block(B), location(L), T = 0..m-1.

{on(B,L,T+1)} :- on(B,L,T), T < m.

#show move/3.

I looked up the definition of a serializable plan and it says that actions that are scheduled for the same time period can be instead executed consecutively, in any order without affecting the result.

How can I modify my code so that I can input the number of maxstep and get the minimum number of actions? Also, the grippers could be thought of as arms that moves the blocks. [1]: https://i.stack.imgur.com/cfN3W.png

1 Answers1

-1

Use <incmode>. You should be able to gather all that is needed from this example: https://github.com/potassco/clingo/blob/master/examples/clingo/iclingo/example.lp

Parts you need to add:

#include <incmode>.

For activating the mode.

#const istop  = "SAT". % Stop when there is a model
#const imin   = 1.     % Start with maxstep=1
%#const imax   = 11.   % Max maxstep you would consider

#program base.         
...                    % Common parts of the program

#program step(k).      
...                    % This program is grounded once for each 
                       % step, with k replaced by the step as and int.
                       
#program check(k).
...                    % This is also grounded once for each step. Use 
                       % it to specify a constraint to weed out 
                       % unsatisfactory models. You can check for query(k),
                       % like in the example so that the constraint only
                       % fires in the instance with k=maxstep.

What happens in incmode? It's basically like defining a constant for maxstep and then running clingo from the commandline with maxstep always increasing, until you get a model:

clingo -c m=1 ... --> UNSAT
clingo -c m=2 ... --> UNSAT
clingo -c m=3 ... --> UNSAT
clingo -c m=4 ... --> SAT

In the example linked above you will also find Python and Lua implementations for incmode. You will not need to include those but if you study them, it should become clear how it works.

firefrorefiddle
  • 3,795
  • 20
  • 31