CPSC 322 - Solution to Homework Assignment 4 - November 29, 2004

CPSC 322 - Solution to Homework Assignment 4


/* This is the STRIPS planner in the spike and rooms domain */

/* 
This is an implementation of the simple STRIPS planner
shown on page 302 of the Computational Intelligence text.
The domain is a very simple blocks world problem, and 
the representations of state and actions, while described
in chapter 8 of the text, are adapted from a more 
complicated sample program and knowledge base found at
http://www.cs.ubc.ca/spider/poole/ci/code/cilog/cilog_code/cilog_code.html
(click on delrob_strips.pl).

launch it with the query:
cilog: ask goals(G) & achieve_all(G,init,Plan).

Note that the add list is denoted here by "achieves" instead of "add",
and that the add and delete lists aren't exactly lists.
*/

/* move_spike action */
preconditions(move_spike(R1,R2),[in_room(spike,R1),adjacent(R1,R2)]).
achieves(move_spike(R1,R2),in_room(spike,R2)).
deletes(move_spike(R1,R2),in_room(spike,R1)).

/* push_box action */
preconditions(push_box(B,R1,R2),[in_room(spike,R1),in_room(B,R1),adjacent(R1,R2),B\=spike]).
achieves(push_box(B,R1,R2),in_room(spike,R2)).
achieves(push_box(B,R1,R2),in_room(B,R2)).
deletes(push_box(B,R1,R2),in_room(spike,R1)).
deletes(push_box(B,R1,R2),in_room(B,R1)).


/* initial situation */

holds(in_room(spike,room4),init).
holds(in_room(box1,room2),init).
holds(in_room(box2,room3),init).

clause(adjacent(room1,room2),[]).
clause(adjacent(room2,room3),[]).
clause(adjacent(room3,room4),[]).

clause(adjacent(room2,room1),[]).
clause(adjacent(room3,room2),[]).
clause(adjacent(room4,room3),[]).

goals([in_room(box1,room3)]).

achieves(init,X) <- holds(X,init).



/* the more complex STRIPS planner */

remove(X,[X|Y],Y).

achieve_all([],W0,W0).

achieve_all(Goals,W0,W2) <- 
     remove(G,Goals,Rem_Gs) &
     achieve(G,W0,W1) &
     achieve_all(Rem_Gs,W1,W2).

achieve(G,W,W) <- true_in(G,W).

achieve(A \= B,W,W) <- A \= B.

achieve(G,W0,W1) <- 
     clause(G,B) &
     achieve_all(B,W0,W1).

achieve(G,W0,do(Action,W1)) <-
     achieves(Action,G) &
     preconditions(Action,Pre) &
     achieve_all(Pre,W0,W1).

true_in(G,init) <-
   holds(G,init).
true_in(G,do(A,_)) <-
   achieves(A,G).
true_in(G,do(A,S)) <-
   true_in(G,S) &
   ~ deletes(A,G).

Last revised: November 30, 2004