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.

Slides:



Advertisements
Similar presentations
Lisp. Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks.
Advertisements

1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
1-1 An Introduction to Scheme March Introduction A mid-1970s dialect of LISP, designed to be a cleaner, more modern, and simpler version than.
Lisp – Introduction יעל נצר מערכות נבונות סמסטר ב' תשס"ו.
Prof. Fateman CS 164 Lecture 151 Language definition by interpreter, translator, continued Lecture 15.
CSE 341, S. Tanimoto Pattern Matching - 1 Pattern Matching in Lisp Lists can be used to represent sentences, relations, tree structures, etc. (this list.
ITERATIVE CONSTRUCTS: DOLIST Dolist is an iterative construct (a loop statement) consisting of a variable declaration and a body The body states what happens.
Lisp. Versions of LISP Lisp is an old language with many variants –LISP is an acronym for List Processing language Lisp is alive and well today Most modern.
Plans for Today Chapter 2: Intelligent Agents (until break) Lisp: Some questions that came up in lab Resume intelligent agents after Lisp issues.
CSE S. Tanimoto Explicit Function Application 1 Explicit Application of Functions, Functional Arguments and Explicit Evaluation Implicit and explicit.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
LISP 1.5 and beyond A very quick tour. Data Atoms (symbols) including numbers – All types of numbers including Roman! (well, in the early days) – Syntactically.
CSE473 Winter /09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.
The Case primitive: matches the evaluated key form against the unevaluated keys by using eql The general format of case is the following: (case (... ).....
PRACTICAL COMMON LISP Peter Seibel 1.
Mitthögskolan 10/8/ Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it.
For Monday Read Chapter 3 Homework: –Lisp handout 2.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
Lecture 2-1CS250: Intro to AI/Lisp Intelligent Agents Lecture 3-2 October 14 th, 1999 CS250.
ISBN Chapter 15 Functional Programming Languages.
Functional Programming in Scheme and Lisp. Overview In a functional programming language, functions are first class objects. You can create them, put.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
ITEC 380 Organization of programming languages Lecture 5 – Functional Programming.
Lecture 6-2CS250: Intro to AI/Lisp Programming in Your Favorite Language Lecture 5-2 February 11 th, 1999 CS250.
Macros “How can you get anything done in [other languages], I think, without macros?” - Paul Graham, 2003.
CSE573 Autumn /20/98 Planning/Language Administrative –PS3 due 2/23 –Midterms back today –Next topic: Natural Language Processing reading Chapter.
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
PRACTICAL COMMON LISP Peter Seibel 1.
CSE573 Autumn /06/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory –Last topic: Decision Tree.
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
1 Variable Declarations Global and special variables – (defvar …) – (defparameter …) – (defconstant …) – (setq var2 (list 4 5)) – (setf …) Local variables.
CS220 Programming Principles 프로그래밍의 이해 2002 가을학기 Class 14: Object Oriented Programming 한 태숙.
1 COSC generating functions, templates, and macros Yves Lespérance Adapted from Peter Roosen-Runge.
Basic Introduction to Lisp
Macros and general code walkers in Lisp: how useful! or, how useful? Ernst van Waning
Functional Programming: Lisp MacLennan Chapter 10.
1 Scheme (Section 11.2) CSCI 431 Programming Languages Fall 2003.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
3/14/20161 SOAR CIS 479/579 Bruce R. Maxim UM-Dearborn.
CSE573 Autumn /04/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory Last time –using features.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Ch Ch jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (n-n-n-notes) Summer 2003 Dr. Carter Tiernan.
Functional Programming Languages
6.001 SICP Variations on a Scheme
Nondeterministic Evaluation
Functions BIS1523 – Lecture 17.
The Metacircular Evaluator
J.E. Spragg Mitthögskolan 1997
FP Foundations, Scheme In Text: Chapter 14.
Dynamic Scoping Lazy Evaluation
The Metacircular Evaluator
Modern Programming Languages Lecture 20 Fakhar Lodhi
The Metacircular Evaluator (Continued)
CSE S. Tanimoto Explicit Function Application
6.001 SICP Further Variations on a Scheme
Lisp: Using Functions as Data
topics mutable data structures
6.001 SICP Variations on a Scheme
Abstraction and Repetition
Functional Programming: Lisp
6.001 SICP Interpretation Parts of an interpreter
Lisp: Using Functions as Data
Common Lisp II.
Good programming practices
Presentation transcript:

CSE473 Winter /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.

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

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

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

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

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

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

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

CSE473 Winter Definition of object-kind

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

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

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

CSE473 Winter Definition of add-to-end

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

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

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

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

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

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

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

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

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

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

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

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

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

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