Lab 3 Actions and Simulation in the Ethel system Goal

advertisement
Lab 3
Actions and Simulation in the Ethel system
Goal
The goal of this lab is to obtain understanding of the following aspects of programming in
Lisp and in the basic characteristics of knowledge-based programming in artificial
intelligence:
•
The integration of programs and data
•
The use of procedures, for example Lisp functions, that are attached to objects as their
properties
•
The concepts of 'action' and 'current state' and their use in a computational setting.
Preparation
The scenario for the lab is the 'ethel' scenario that was used in the lecture on September
20. It considers a simple world where there are the following types of entities:
•
persons
•
airplanes
•
cities
plus the process concepts such as action and timepoint. The states of persons and
airplanes change over time, whereas the cities are not supposed to have any time-variable
state. The states of persons and airplanes are primarily their location, but incremented
with some additional component. For example being in Stockholm airport and
boarding passengers can be a different state from being in Stockholm airport and
ready to fly.
The actions in this scenario are the actions by airplanes, such as board passengers or
fly to London, and the actions of persons, such as go from center city to airport.
Read the lab PM's at http://www.ida.liu.se/ext/caisor/tdda23/lispnotes/lisp-04.pdf and
http://www.ida.liu.se/ext/caisor/tdda23/lispnotes/lisp-07.pdf carefully and make sure you
get the concept.
Lab Material
Lisp programs that serve as a skeleton for this scenario are available at:
http://www.ida.liu.se/~TDDA23/mtrl-05/labs/lab03/
with the subdirectories program, database, documentation, and runlogs. It requires the use
of a Lisp system that distinguishes upper case and lower case characters. Such a system
can be started by typing the following at the command line:
/home/TDDA23/startup/emacs-mlisp
The actual files are then loaded into the lisp system by typing:
(load “/home/TDDA23/labs/lab03/program/ethel.cl”)
at the lisp prompt.
The program should be run your home directory where there is a subdirectory called
tdda23-lab3. The additional programs that you write should be put in that directory, and
when data files are written from the program (using the operation (sod 'foo), see below)
then the files will be written in the subdirectory with that name.
Introductory exercises
The lab consists of two steps. The first step is to familiarize yourself with the program;
this step does not need to be reported. The second step is the assignment which is
described below, and for which a report is to be handed in.
For the introductory exercise, the following is suggested.
1.
Open a UNIX shell. Create a directory called tdda23-lab3 by typing mkdir
tdda23-lab3 in the shell directly under your home directory. Type
/home/TDDA23/startup/emacs-mlisp in the directory which has tdda23-lab3 as a
sub directory.
2.
Load the Ethel system by typing
(load “/home/TDDA23/labs/lab03/program/ethel.cl”) in the lisp command line.
3.
Initiate a simulation with the data that are already in the system. Execute
(init-state)
and then check the values of the global variables that characterize the current
state, such as *t (simulated time), *pp (person positions), etc. See
http://www.ida.liu.se/ext/caisor/tdda23/lispnotes/lisp-04.pdf for a list of available
commands.
4.
Add one or a few boarding actions, using e.g.
(add-action '(let-board lh-12))
where the argument to start-boarding shall be one of the planes in the database (as
seen in the value of *ap), and verify that the action(s) are entered into the current
value of *oa (ongoing actions).
5.
Call the function ups without arguments (type just (ups)) a few times to update
the current state using the currently ongoing actions. Check the contents of the state
in-between the updates, and watch in particular how actions are added to, and lost
from the list of ongoing actions, *oa, and how completed actions are added to the
log of past actions, *alog.
6.
Verify that you can write and use your own programs in the system. Create a file
called my-test-file.cl and write the following test-function like this:
(defun get-country (city)
(get city 'incountry))
Save it in the directory tdda23-lab3. Load it using (lod 'my-test-file) and try-use it
by calling (get-country 'stockholm).
7.
Take a look at the data that are stored for a particular object, by doing e.g. (show
'stockholm) or (show 'persons).
8.
Verify that you can modify the database of the system, in the following two ways:
•
Change some of the properties through the Lisp system, using the put or setf
functions. For example, change the country of stockholm so that it is set to
norway instead by using
(setf (get 'stockholm 'incountry) 'norway).
Then save the file where this data belongs, using the following function:
(sod 'cities)
for saving the file cities.cl, and similarly for persons.cl etc. This command
creates a copy of the file and put it in your tdda23-lab3 directory. Try your
get-country function again.
•
Open cities.cl and edit it back so that stockholm is placed in sweden again
and reload it using e.g. (lod 'cities).
Note: (ld 'persons) loads the library version of the file, (lod 'persons) loads your
own version of the same file, but only after you have done (sod 'persons) to
create it.
9.
Write a function get-distance which takes two cities as arguments and returns the
distance between the cities. If you find cities that does not have any distances, add
the distances to the cities in the database according to exercise 8.
Assignment
The task for the lab is to write an additional action definition, besides the one for startboarding that is already in the lab materials. We need the action fly-to which takes a
airplane and a city as arguments. An example could look like this: (fly-to lh-12 london).
As mentioned in the lectures, there are several different ways to obtain abstraction in the
code. In the file
http://www.ida.liu.se/~TDDA23/mtrl-05/labs/lab03/program/data-access.cl there is five
different versions of the function update-state. Choose one of them and add fly-to. Also
don't forget to change the function ups in the same file, so that your chosen definition is
used. Your solution should use the following action-expression:
•
(fly-to plane city)
and the following position-expressions:
•
(enroute city1 city2 dist) where city1 is the city the airplane is travelling from and
city2 is the destination city. dist is the current distance between the airplane and city2.
•
(ready-to-unboard city) where the city is the city where the airplane currently is
located.
Update your chosen version of the function update-state so that it changes position from
ready-to-fly to enroute and later to ready-to-unboard. Use your get-distance function
written earlier to get the distance betseen the two cities and let the position be enroute as
long as it takes for the plane to travel to the destination city. Every tick in the system is 5
minutes and the airplane travels with the velocity of 2000km/h. When the airplane has
reached the destination set the position to ready-to-unboard.
Verify the action through a run where the successive actions are entered by the user. The
entire run is documented by performing the following operations, with some suitable
name foo for the log file:
(stafile 'foo)
(sod 'foo)
This creates a file foo.cl containing the values of the variables that characterize the run.
Hand in
To be turned in: One file containing your action definitions, and one file (at least) with
the log of the sample run.
Download