University of Washington
Department of Computer Science and Engineering
CSE573–Artificial Intelligence I
Autumn 1997
Problem Set #2
Assigned October 22, 1997
Due November 3, 1997
State Space Search, and a Truckworld Agent
This problem set is simplicity itself: write a function
which takes a goal as input, generates a solution plan that solves the goal, and executes that plan in the Truckworld. You can define a goal however you want, though there will be some suggestions below. What’s more, we will be operating in a very simple Truckworld environment, consisting of only three locations and only a few objects:
Here is more detail about the world:
Another nice thing about this world is that the objects always appear at prespecified locations and positions:
Consider the problem in several steps:
1. Formulating the problem
The tricky part of the first step is to decide what formulation you will use to represent the problem. It will probably help to know what form the goals might take. You need not use the following representation exactly, but your solution must solve all of the following goals:
(defvar *goal-1* '((GLASS A) (GLASS UNBROKEN)))
(defvar *goal-2* '((GARBAGE RECYCLED)))
(defvar *goal-3* '((GLASS BROKEN)))
(defvar *goal-4* '((ROCK RECYCLED)))
(defvar *goal-5* '((GLASS RECYCLED)))
(defvar *goal-6* '((GLASS C) (GLASS UNBROKEN)))
(defvar *goal-7* '((ROCK RECYCLED) (GLASS RECYCLED)))
(defvar *goal-8* '((GARBAGE B) (GLASS B) (GLASS UNBROKEN)))
(defvar *goal-9* '((ROCK RECYCLED) (GLASS C) (GARBAGE IN-BOX)))
(defvar *goal-10* '((ROCK RECYCLED) (GLASS A)
(GLASS UNBROKEN) (FUEL FULL)))
(defvar *goal-11* '((ROCK RECYCLED) (GLASS C) (GLASS UNBROKEN)
(GARBAGE IN-BOX) (FUEL FULL)))
Another big part of an effective solution will be to limit how long plans get. As you will see, even a simple pickup action in Truckworld consists of several primitives; more complex actions like refueling the truck consist of many primitives. If your search space comprises the set of all sequences of Truckworld primitives, you will have
serious problems solving even the smallest problems. (See "macro-operators" below.)
You will also have to come up with a heuristic ranking function for the search. (Hint: concentrate on detecting repeated states and eliminating "nonsense" move sequences, e.g. picking up an object then immediately putting it down.)
2. Generating the solution
Use two methods to perform the search: iterative deepening search, and heuristic search based on your own ranking function. To do the former, you will have to extend the algorithm in
search.lsp to do iterative deepening search.
3. Macro-Operators
As mentioned above, you will probably want to search using abstract (macro) operators, then expand the solution into primitive Truckworld actions. The file
macrop-function.lspcontains some code that will help you do so. It implements a function
which takes an expression representing a macro-operator, and expands it into a list of primitives. An example might be:
(expand-macrop ’(pickup glass))
=>( (arm-move arm-1 outside)
(arm-move arm-1 8)
(arm-grasp arm-1)
(arm-move arm-1 folded)
(arm-move arm-1 inside)
(arm-move arm-1 bay-1)
(arm-move arm-1 0)
(arm-ungrasp arm-1 0)
(arm-move arm-1 folded)
)
This expansion takes advantage of several assumptions and design decisions, for example
You can write as many macro-operators as you want, and make as many assumptions as you want about what resources to use for what tasks (e.g. you can use one arm for picking up objects and the other arm for refueling). You will also have to take good advantage of the information about the three-node world provided above.
4. Implementing the solution
Your search will supply you with a list of macro-actions that will move the world into a goal state. Now all that is left is to execute that solution in the Truckworld. The code in
truckworld-interface.lsp provides some handy functions to do so: