1 % -------------= Simple planner
for situation calculus
=---------------
3 % Executes an iterative deepening search
, by
default limited to a depth
6 % plan
. will search
for a plan of maximum
length
7 % plan
(M
). will search
for a plan of maximum
length up to M
8 % plan
(N
,M
). will search
for a plan of mimimum
length N
and maximum
12 % Checklist
for the definition of a domain
and problem
:
14 % - initial
state initialize fluents
in s0
16 % - possibility axioms poss
( <action
>(...), S
) :- <precond
>
18 % - successor
-state axioms
<fluent
>( ..., result
(A
,S
) ) :-
19 % <some events made it true
>; % or
20 % <it was true all along
>, % and
21 % not(<some events made it false
>).
23 % - goal predicate goal
(S
) :- <goal conditions
>
26 % --------------------------= High Level
=-----------------------------
28 % default number of iterations
(15)
31 % given max number of iterations
32 plan
(MaxDepth
) :- plan
(0, MaxDepth
).
34 % given min
and max number of iterations
35 plan
(MinDepth
, MaxDepth
) :-
36 M is MaxDepth
+1, write('Trying plans of length: '),
37 plan
(Plan
, MinDepth
, M
), nl
, nl
, writePlan
(Plan
).
41 % same as above
, to be called from shell
; include additional output
42 % messages
and halt to quit pl
43 planner
:- planner
(0, 15).
44 planner
(MaxDepth
) :- planner
(0, MaxDepth
).
45 planner
(MinDepth
, MaxDepth
) :-
46 nl
, plan
(MinDepth
, MaxDepth
), nl
, halt
;
47 write('\n\nNo plan has been found!'), nl
, nl
, halt
.
51 % ---------------------------= Low Level
=-----------------------------
53 % start from depth N
, up to M
57 debugoutput
(write('\n\nPlans of length ')),
61 plan
(P
, N
, M
) :- N
< M
, O is N
+1, plan
(P
, O
, M
).
63 seqplan
( [], N
, S
) :- N
= 0, debugoutput
(writeSituation
(S
)), goal
(S
).
64 seqplan
( [A
|L
], N
, S
) :- N
> 0, M is N
-1, result
(A
,S
,S1
), seqplan
(L
, M
, S1
).
66 result
(E
,S
,result
(E
,S
)) :- primitive_action
(E
), poss
(E
,S
).
68 % -----------------------= Support Function
=--------------------------
70 % debugoutput will be printed only
if debug
(on
) is
defined in the KB
75 debugoutput
(A
) :- debug
(on
), A
, !; true
.
78 % prints a situation as a sequence of actions
, starting from s0
79 writeSituation
(s0
) :- write('\n s0').
80 writeSituation
(result
(A
,S
)) :- writeSituation
(S
), writef
(" > %w", [A
]).
82 % prints a plan as a list of actions
, numbered
85 debugoutput
(write('\nA plan has been found:\n\n')),
91 writePlan
([Action
|List
], Counter
) :-
92 writef
('%3R %w\n',[Counter
,Action
]),
97 % hides some
(unimportant
) warnings from the pl interpreter
98 :- style_check
([-discontiguous
, -singleton
]).
102 % ---------------------------------------------------------------------
103 % ---------------------------------------------------------------------