1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
% show instances of selected predicates only
#show.
% output stack representation
#show order/4.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% program part for generating states providing relative block positions, using %
% - parameter k for block number %
% - parameter t for step number at instantiation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#program state(k,t).
% a block's scope includes the table (labeled 0) and blocks with smaller numbers
scope(k,0,t).
scope(k,I,t) :- scope(I,0,t), I < k.
% order(1,k,I,t) provides the closest block I in scope above k, if any at time t
#count{ I : order(1,k,I,t) : scope(k,I,t), 0 < I } 1.
% order(-1,k,I,t) provides the closest block/table I in scope below k at time t
1 #count{ I : order(-1,k,I,t) : scope(k,I,t) } 1.
% trace order/4 to derive transitive closure of objects in scope above/below k
trans(D,k,I,t) :- order(D,k,I,t).
trans(D,k,I,t) :- trans(D,k,J,t), order(D,J,I,t).
trans(D,k,J,t) :- trans(D,k,I,t), order(-D,J,I,t), scope(k,J,t).
% state constraint that the table is transitively below block k (redundant)
:- not trans(-1,k,0,t).
% state constraint propagating immediate above/below relationships
:- order(-1,k,I,t), order(1,k,J,t), not order(-1,J,I,t), not order(1,I,J,t).
% state constraint aligning immediate and transitive above/below relationships
:- order(-D,k,J,t), order(D,J,I,t), not trans(D,k,I,t), 0 < I. % D=-1 redundant
% state constraint directing transitive above/below relationships on convergence
:- order(D,k,I,t), order(D,J,I,t), not trans(-D,k,J,t), scope(k,J,t), 0 < I.
% rules below are volatile with life span 1
% #program volatile(k,t).
#external scope(k,0,t+1).
% goal state conditions
:- goal_above(k,I), not trans(-1,k,I,t), not scope(k,0,t+1).
:- goal_below(k,I), not trans(1,k,I,t), not scope(k,0,t+1).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% program part for generating moves having a block as object and target, using %
% - parameter k for block number %
% - parameter t for step number at instantiation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#program move(k,t).
% external atoms indicating involvement of blocks with greater numbers in move
#external change(-1,k,I,t) : scope(I,0,t), I <= k.
#external change( 1,k,I,t) : scope(I,0,t-1), I <= k.
% #external change((-1;1),k,t).
#external change(-1,k,t).
#external change( 1,k,t).
% output object and target block of move
#show object(k,t) : object(k,t).
#show target(k,t) : target(k,t).
% propagate role as move object (via D=1) or target (via D=-1) to smaller block
change(1,k-1,I,t) :- order(1,k,I,t), scope(I,0,t-1), not order(1,k,I,t-1).
change(D,k-1,I,t) :- order(D,k,I,t-(D+|D|)/2), scope(k,0,t-1), 0 < I,
not order(D,k,I,t+(D-|D|)/2).
change(D,k-1,I,t) :- change(D,k,I,t), I < k. % , scope(I,0,t-(D+|D|)/2).
% combine possibilities how move affects block as object (D=1) or target (D=-1)
affect(-D,k,t) :- order(D,k,I,t+(D-|D|)/2), scope(I,0,t-1) : D == 1;
not order(D,k,I,t-(D+|D|)/2).
affect( D,k,t) :- change(D,k,k,t). % , scope(k,0,t-(D+|D|)/2).
% propagate existence of some move object or target to smaller blocks and table
change(D,k-1,t) :- affect(D,k,t).
change(D,k-1,t) :- change(D,k,t).
% derive moved object and corresponding target
object(k,t) :- affect(1,k,t).
target(k,t) :- affect(-1,k,t), not change(-1,k,t).
% moved object must be unique
:- object(k,t), change(1,k,t).
% moved object must be free
:- object(k,t), order(1,k,_,t-1).
:- object(I,t), order(-1,k,I,t-1).
% moved object must not go under (unmoved) pre-existing block
:- object(k,t), order(1,k,I,t), scope(I,0,t-1).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% program part for deriving target table from move without target block, using %
% - parameter t for step number at instantiation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#program table(t).
% external atoms indicating involvement of blocks with greater numbers in move
% #external change((-1;1),0,t).
#external change(-1,0,t).
#external change( 1,0,t).
% output target table of move
#show target(0,t) : target(0,t).
% derive table as target of move
target(0,t) :- change(1,0,t), not change(-1,0,t).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% program part for establishing consistent initial position for a block, using %
% - parameter k for block number %
% - parameter t for step number at instantiation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#program init(k,t).
% no appearance under unmoved pre-existing block
:- order(1,k,I,t), scope(I,0,t-1), not object(I,t).
% initial state conditions
:- init_above(k,I), not trans(-1,k,I,t).
:- init_below(k,I), not trans(1,k,I,t).
|