[comp.lang.prolog] planning,meta-interpreters ....

feldman@eldir.cs.cornell.edu (Ronen Feldman) (06/08/90)

I faced the following problem.
I have a planner that achives goals in the block world. The code
follows, when I issue the goal "holding(a)" I get an infinite loop
here is the output :
unstack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(e,d)stack(....

The problem is that the order of the clauses for empty_arm is
empty_arm :- stack(X,Y),write(stack(X,Y)).
empty_arm :- putdown(X),write(putdown(X)).

unstack which calls empty_arm checks then (via bretract) that X is
clear but after stacking Y on X it is no longer clear.
So the infinite loop is in unstack(X,Y) between empty_arm and 
bretract(clear(X)). Note that the bassert and bretract are needed to
cope correctly with the backtracking.

Besides changing the order of the clauses in empty_arm. Does any one
has another solution (like writing some kind of meta-interpreter)?

The nmain problem is that the depth does'nt increase so depth limit
won't help here.

Any comments will be appreciated.

Ronen Feldman (feldman@cs.cornell.edu)

preds([pickup/1,unstack/2,putdown/1,stack/2,holding/1,clear/1,empty_arm/0,
       ontable/1,on/2]).
facts([fact/1]).

fname('planner.dom').

pickup(X) :- 
	clear(X),empty_arm,fact(ontable(X)),
	bassert(fact(holding(X))),bretract(fact(ontable(X))),
	bretract(fact(clear(X))),bretract(fact(empty_arm)).

unstack(X,Y) :- 
	fact(on(X,Y)),clear(X),empty_arm,
	bassert(fact(clear(Y))),bassert(fact(holding(X))),
	bretract(fact(on(X,Y))),bretract(fact(clear(X))),
	bretract(fact(empty_arm)).

putdown(X) :- 
	fact(holding(X)),
	bassert(fact(empty_arm)),bassert(fact(ontable(X))),bassert(fact(clear(X))),
	bretract(fact(holding(X))).

stack(X,Y) :-
	holding(X),clear(Y),	
	bassert(fact(on(X,Y))),bassert(fact(empty_arm)),bassert(fact(clear(X))),
	bretract(fact(holding(X))),bretract(fact(clear(Y))).

holding(X) :- fact(holding(X)).
holding(X) :- pickup(X),write(pickup(X)).
holding(x) :- unstack(X,Y),write(unstack(X,Y)).

clear(X) :- fact(clear(X)).
clear(Y) :- unstack(X,Y),write(unstack(X,Y)).
clear(X) :- putdown(X),write(putdown(X)).


clear(X) :- stack(X,Y),write(stack(X,Y)).

empty_arm :- fact(empty_arm).
empty_arm :- stack(X,Y),write(stack(X,Y)).
empty_arm :- putdown(X),write(putdown(X)).



ontable(X) :- fact(ontable(X)).
ontable(X) :- putdown(X),write(putdown(X,Y)).

on(X,Y) :- fact(on(X,Y)).
on(X,Y) :- stack(X,Y),write(stack(X,Y)).

bassert(X) :- assert(X).
bassert(X) :- retract(X),fail.

bretract(X) :- not(X),!,fail.
bretract(X) :- retract(X).
bretract(X) :- assert(X),fail.



fact(empty_arm).
fact(on(b,a)).
fact(on(c,b)).
fact(on(d,c)).
fact(on(e,d)).
fact(ontable(a)).
fact(clear(e)).