Information Technology Reference
In-Depth Information
Figure 9.8.
A general but bounded planner
bplan.pl
% This looks for plans, short ones first, using the plan predicate.
% bplan(L) holds if L is a plan.
bplan(L) :- tryplan([],L).
% tryplan(X,L): L is a plan and has X as its final elements.
tryplan(L,L) :- plan(L).
tryplan(X,L) :- tryplan([_|X],L).
Figure 9.9.
A trace of the bplan predicate
?- bplan(L).
Call: (9) bplan(_G210)
Call: (10) tryplan([], _G210)
Call: (11) plan([])
%% plan fails. Details omitted.
Redo: (10) tryplan([], _G210)
Call: (11) tryplan([_G301], _G210)
Call: (12) plan([_G301])
%% plan fails. Details omitted.
Redo: (11) tryplan([_G301], _G210)
Call: (12) tryplan([_G304, _G301], _G210)
Call: (13) plan([_G304, _G301])
%% plan fails. Details omitted.
Redo: (12) tryplan([_G304, _G301], _G210)
Call: (13) tryplan([_G307, _G304, _G301], _G210)
Call: (14) plan([_G307, _G304, _G301])
%% plan fails. Details omitted.
Redo: (13) tryplan([_G307, _G304, _G301], _G210)
Call: (14) tryplan([_G310, _G307, _G304, _G301], _G210)
Call: (15) plan([_G310, _G307, _G304, _G301])
%% This is where plan is finally successful.
Exit: (15) plan([go(loc3), push(loc1), climb_on, grab])
Exit: (14) tryplan([go(loc3), ...], [go(loc3), ...])
Exit: (13) tryplan([push(loc1), climb_on, grab], [go(loc3), ...])
Exit: (12) tryplan([climb_on, grab], [go(loc3), ...])
Exit: (11) tryplan([grab], [go(loc3), ...])
Exit: (10) tryplan([], [go(loc3), ...])
Exit: (9) bplan([go(loc3), push(loc1), climb_on, grab])
L = [go(loc3), push(loc1), climb_on, grab]
because the number of elements in x is always known during the back-chaining and
so can be used with the existing plan predicate as is.
Search WWH ::




Custom Search