CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next...

18
1 CSE473 Winter 1998 01/09/98 LISP Agent Continued • Administrative PS0 out, PS1 assigned next Monday Last time agent design and demo the top-level agent loop LISP concepts Symbols, including T and NIL Conditionals, including IF and WHEN Lexical variables, including LET and LET* Side-effecting and “pure” functions This time high-level architecture: percepts, behaviors, macros code for percepts and behaviors

Transcript of CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next...

Page 1: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

1 CSE473 Winter 1998

01/09/98 LISP Agent Continued

• Administrative– PS0 out, PS1 assigned next Monday

• Last time– agent design and demo– the top-level agent loop– LISP concepts

• Symbols, including T and NIL• Conditionals, including IF and WHEN• Lexical variables, including LET and LET*• Side-effecting and “pure” functions

• This time

– high-level architecture: percepts, behaviors, macros

– code for percepts and behaviors

Page 2: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

2 CSE473 Winter 1998

Architecture Overview

Macro-actions

Matching

Truckworld

Percepts

Agent

Behaviors

Behavior selection and execution

Action execution

Sensing

Primitive actionsand sensing

Macro expansion

Page 3: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

3 CSE473 Winter 1998

Perception

• A percept is a record of everything the agent knows about the world at the present time– obviously depends both on the world and on the agent’s

sensing capabilities

• Truckworld: agent can perceive certain features of– the objects at its current location

– the objects it is holding and in its cargo bays

– its internal status (fuel, heading, speed, status)

• Truckworld sensors return raw sensing reports which must be coalesced into one percept

Page 4: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

4 CSE473 Winter 1998

A Truckworld Sensing Report

(SENSOR TRUCK-SENSOR ( ((POSITION 0) (KIND ROADSIGN) (DIRECTION E) ...) ((POSITION 2) (KIND GARBAGE) (VALUE 10)) ((POSITION 3) (KIND GLASS) (COLOR GREEN)) ((POSITION 4) (KIND FUEL-DRUM-DISPENSER)) ((POSITION 5) (KIND ATM)) ((POSITION 6) (KIND GARBAGE-CAN)) ((POSITION 7) (KIND GLASS-RECYCLER)) ((POSITION 8) (KIND FUEL-DRUM-CONSUMER)) ((POSITION 9) (KIND TRUCK) (TRUCK-ID TRUCK-5)))

an object a sensor reportan attribute and value

Page 5: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

5 CSE473 Winter 1998

Sensor Reports to Percepts

• A percept is a collection of sensor reports from – the truck sensor

– the two cargo bays

– the fuel tank

all packaged into one data structure

• Support routines we need for percepts– create one from a set of sensor reports

– find a fuel-drum-consumer outside

– find an empty space in BAY-1

– return the current fuel level

Page 6: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

6 CSE473 Winter 1998

The Percept Data Structure

(defstruct percept location-contents bay-1-contents bay-2-contents fuel-level)

(defun find-objects (percept kinds location) (case location ((:OUTSIDE) (find-objects-at kinds (percept-location-contents percept))) ((BAY-1) (find-objects-at kinds (percept-bay-1-contents percept))) ((BAY-2) (find-objects-at kinds (percept-bay-2-contents percept))) (OTHERWISE (error "Don't understand location ~a" location))))

Page 7: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

7 CSE473 Winter 1998

Processing Percepts (cont.)

(defun find-objects-at (kinds percept-list) (mapcar 'object-position (remove-if-not #'(lambda (object) (member (object-kind object) kinds)) percept-list)))

’((POSITION 0) (KIND ROADSIGN) (DIRECTION E)) ((POSITION 2) (KIND GARBAGE) (VALUE 10)) ((POSITION 3) (KIND GLASS) (COLOR GREEN)) ((POSITION 4) (KIND FUEL-DRUM-DISPENSER)) ((POSITION 5) (KIND ATM)) ((POSITION 6) (KIND GARBAGE-CAN)) ((POSITION 7) (KIND GLASS-RECYCLER)) ((POSITION 8) (KIND FUEL-DRUM-CONSUMER)) ((POSITION 9) (KIND TRUCK) (TRUCK-ID TRUCK-5))))

’(glass garbage)

Page 8: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

8 CSE473 Winter 1998

Definition of object-kind

Page 9: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

9 CSE473 Winter 1998

Summary of percept

• A single data structure that captures all sense data• Supports operations like

– find me all objects with this kind at this location

– find me an empty position at this location

– tell me what the fuel level is

• Will be created by the sense behavior• Will be examined

– in deciding what behavior to do next

– in deciding what a chosen behavior should do

Page 10: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

10 CSE473 Winter 1998

Behaviors

• A behavior is a mapping from a percept to a (macro)action.– a macro-action is a fixed sequence of Truckworld

primitives, like • pick up the object at position 3 outside using ARM-1

• pour the fuel drum currently being held by ARM-1

• Behaviors must be selected and executed– selection by name

– selection by “contention”

Page 11: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

11 CSE473 Winter 1998

Behavior Structure Definition

(defstruct (behavior (:print-function print-behavior)) name test action)

(defun print-behavior (self stream indent) (declare (ignore indent)) (format stream "{B ~a}" (behavior-name self)))

(defvar *behaviors*)

(defun define-behavior (&key name test action) (setf *behaviors* (add-to-end (make-behavior :name name :test test :action action) *behaviors*)))

Page 12: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

12 CSE473 Winter 1998

Definition of add-to-end

Page 13: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

13 CSE473 Winter 1998

Choosing and Executing Behavior

(defun find-behavior (name) (find name *behaviors* :key 'behavior-name))

(defun choose-behavior (percept) (first (remove-if-not #'(lambda (b) (funcall (behavior-test b) percept)) *behaviors*)))

(defun execute-behavior (b percept) (funcall (behavior-action b) percept))

Page 14: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

14 CSE473 Winter 1998

Defining Behaviors

• We now know that a behavior is a test and an action, both functions of a percept.

• What are reasonable behaviors for the collection world?

• Must depend only on the current percept

• Goal is to have them as “low level” as possible while still having them “functional”– recycle all garbage and glass in the world

– recycle the piece of glass at position 3, using ARM-1 and the recycler at position 4

– pick up the object at position 3 using ARM-2

– move ARM-2 to position 3

Page 15: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

15 CSE473 Winter 1998

Behavior definitions to accomplish our goals

• Recycle all glass, garbage, and empty fuel drums– recycle objects when you have them and there is an

appropriate recycler at hand

– move from place to place

– refuel when necessary

Page 16: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

16 CSE473 Winter 1998

Behavior for picking up a recyclable

(define-behavior :name 'pickup-recyclable :test #'(lambda (percept) (and

(find-empty-position percept 'BAY-1)(find-object percept '(glass garbage) :OUTSIDE)))

:action #'(lambda (percept) (let ((bay-position

(find-empty-position percept 'BAY-1)) (obj-position

(find-object percept '(glass garbage) :OUTSIDE))) (execute-macrop

`(pickup-from-outside ARM-1 ,obj-position)) (execute-macrop

`(put-in-bay ARM-1 BAY-1 ,bay-position)))))

Page 17: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

17 CSE473 Winter 1998

Behavior for recycling an object

(define-behavior :name 'recycle-object :test #'(lambda (percept) (some #'(lambda (kind)

(and (find-object percept kind 'BAY-1) (find-object percept (recycler-for kind) :OUTSIDE)))

(kinds-to-recycle))) :action #'(lambda (percept) (do ((kinds (kinds-to-recycle) (cdr kinds))

(done NIL)) (done)

(let ((obj-position (find-object percept (car kinds) 'BAY-1))

(recycler-position (find-object percept

(recycler-for (car kinds)) :OUTSIDE)))

(when (and obj-position recycler-position) (execute-macrop `(pickup-from-bay ARM-1 BAY-1 ,obj-position)) (execute-macrop `(put-inside ARM-1 ,recycler-position)) (setf done T))))))

Page 18: CSE473 Winter 1998 1 01/09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.

18 CSE473 Winter 1998

Summary of behaviors

• A behavior is a test and an action– both of functions (only) of the current percept

• Behaviors are defined and placed on a global ordered list

• Retrieval is either by name, or the first whose test is true given the current percept

• Behaviors take action by executing macro-actions (macrops)