Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE473 Winter 1998 1 01/07/98 A Behavior-Based Reactive Agent Reactive = decision to act made on current sense data alone (as opposed to remembering things.

Similar presentations


Presentation on theme: "CSE473 Winter 1998 1 01/07/98 A Behavior-Based Reactive Agent Reactive = decision to act made on current sense data alone (as opposed to remembering things."— Presentation transcript:

1 CSE473 Winter 1998 1 01/07/98 A Behavior-Based Reactive Agent Reactive = decision to act made on current sense data alone (as opposed to remembering things and thinking ahead) Behavior-based = agent’s abilities defined in terms of small separately defined units of action, which are then pieced together The assumption: “smart” global behavior can result from reactively making behavior decisions in isolation.

2 CSE473 Winter 1998 2 The Basic Agent Loop (Simplified) (defun run-agent ( ) (initialize) (agent-loop)) (defun agent-loop ( ) (let* ((percept (execute-behavior (find-behavior ’sense) NIL))) (next-behavior (choose-behavior percept))) (when next-behavior (execute-behavior next-behavior percept) (agent-loop))))

3 CSE473 Winter 1998 3 Architecture Overview Macro-actions Matching Truckworld Percepts Agent Behaviors Behavior selection and execution Action execution Sensing Primitive actions and sensing Macro expansion

4 CSE473 Winter 1998 4 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

5 CSE473 Winter 1998 5 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 objecta sensor reportan attribute and value

6 CSE473 Winter 1998 6 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

7 CSE473 Winter 1998 7 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))))

8 CSE473 Winter 1998 8 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)

9 CSE473 Winter 1998 9 Definition of object-kind

10 CSE473 Winter 1998 10 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

11 CSE473 Winter 1998 11 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”

12 CSE473 Winter 1998 12 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*)))

13 CSE473 Winter 1998 13 Definition of add-to-end

14 CSE473 Winter 1998 14 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))

15 CSE473 Winter 1998 15 Defining Behaviors 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

16 CSE473 Winter 1998 16 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

17 CSE473 Winter 1998 17 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)))))

18 CSE473 Winter 1998 18 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))))))

19 CSE473 Winter 1998 19 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)

20 CSE473 Winter 1998 20 Macro-actions (MACROPS) Programming the agent with Truckworld primitives can be tedious and repetitive Common tasks often correspond to a fixed set of actions (no conditionals), but require parameter substitution –pickup the object at position ?P using arm ?A, and put it in bay ?B at position ?P2 This could be done by defining a function –(defun pickup (source-pos arm bay dest-pos)... ) In AI we generally prefer more “declarative” representations

21 CSE473 Winter 1998 21 A MACROP for pickup up and putting in a bay (define-macrop :in-form '(put-into-bay ?p1 ?arm ?bay ?p2) :out-forms '((arm-move ?arm OUTSIDE) (arm-move ?arm ?p1) (arm-grasp ?arm) (arm-move ?arm FOLDED) (arm-move ?arm INSIDE) (arm-move ?arm ?bay) (arm-move ?arm ?p2) (arm-ungrasp ?arm 0) (arm-fold ?arm)))

22 CSE473 Winter 1998 22 Executing MACROPS (defun execute-macrop (form-in) (let ((forms-out (match-macrop form-in *macrops*))) (cond ((null forms-out) (error "Couldn't find a match for ~a~%" form-in)) (T (ti-execute-commands forms-out))))) (defun match-macrop (form-in macrops) (cond ((null macrops) NIL) (T (let ((bindings (match form-in (macrop-in-form (first macrops))))) (cond ((eq bindings :FAIL) (match-macrop form-in (cdr macrops))) (T (mapcar #'(lambda (form) (copy-and-instantiate form bindings)) (macrop-out-forms (first macrops)))))))))

23 CSE473 Winter 1998 23 Basic Pattern matching Match is between one s-expression that does not contain variables with another s-expression that does not. Output is a list of bindings for all the variables in the second form –(match ’(pickup 3) ’(pickup ?x)) –(match ’(pickup 3) ’(pickup 4)) –(match ’(pickup 3) ’(pickup 3)) –(match ’(pickup 3 4) ’(pickup ?x ?y)) –(match ’(pickup 3 4) ’(pickup ?x ?x)) –(match ’(pickup 3 3) ’(pickup ?x ?x))

24 CSE473 Winter 1998 24 Easy Case: Suppose there are no variables (defun match (expr1 expr2) )

25 CSE473 Winter 1998 25 Variables and Bindings: You Get for Free! (defun variable-p (thing)...) (defun binding-p (thing)...) (defun make-binding (var const)...) (defun binding-var (binding)...) (defun binding-bdg (binding)...) (defun binding-list-p (thing)...) (defun make-empty-binding-list ( )...) (defun get-binding (var binding-list)...) (defun add-binding (binding binding-list)...)

26 CSE473 Winter 1998 26 Now the real version of MATCH (defun match (expr1 expr2) ;returns a binding list or :FAIL )

27 CSE473 Winter 1998 27 Summary Agent initializes then loops –sense, select behavior, execute behavior –until no behavior is feasible Sensing is a behavior that is always feasible, and generates a percept A behavior is a feasibility test and an action, both depend only on the percept –the current behavior is selected from among those that are currently feasible An action can have arbitrary code, but calls the Truckworld through macrops –a macrop expands into a sequence of Truckworld primitives using variable substitution


Download ppt "CSE473 Winter 1998 1 01/07/98 A Behavior-Based Reactive Agent Reactive = decision to act made on current sense data alone (as opposed to remembering things."

Similar presentations


Ads by Google