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.

Slides:



Advertisements
Similar presentations
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 14 Functional Programming Languages - The design of the imperative languages is based directly.
Advertisements

Some non-recursive tricks. The Lambda expression. More on Let, Let*, apply and funcall.
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)
Functional Programming COMP2003 A course on functional programming using Common Lisp Dr Eleni Mangina
Higher Order Functions “I hope you’re convinced, by now, that programming languages with first-class functions let you find more opportunities for abstraction,
1 COSC3306: Programming Paradigms Lecture 11: Applicative Programming with Lisp Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003.
Lisp – Introduction יעל נצר מערכות נבונות סמסטר ב' תשס"ו.
Lisp Recitation (cse471/598 Fall 2007 ) Aravind Kalavagattu.
CSE 341, S. Tanimoto Pattern Matching - 1 Pattern Matching in Lisp Lists can be used to represent sentences, relations, tree structures, etc. (this list.
Functional Programming COMP2003 A course on functional programming using Common Lisp Dr Eleni Mangina
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
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.
LISP primitives on sequences FIRST (or CAR) and REST (or CDR) take lists apart. Consider the list (First day of the semester). * (first '(First day of.
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.
Lisp by Namtap Tapchareon Lisp Background  Lisp was developed by John McCarthy in  Lisp is derives from List Processing Language. 
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.
F UNCTIONAL P ROGRAMMING 05 Functions. F UNCTIONS - G LOBAL F UNCTIONS fboundp Tells whether there is a function with a given symbol as its name > (fboundp.
Functional Programming 02 Lists
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.
Multiple Returns and Extra Parameters “LISP is unique in its capability to return more than one value (or no value at all) from a form. This neatly avoids.
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.
Common Lisp! John Paxton Montana State University Summer 2003.
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.
Object Oriented Analysis and Design Class and Object Diagrams.
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.
CSE (c) S. Tanimoto, 2002 AI Techniques 1 Where and When Do Symbols Refer to Values and Functions? Scope and Extent of Bindings Bindings Scope Extent.
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.
Structures “The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castles in the air, from air, creating by.
CSE573 Autumn /02/98 Natural Language Processing Administrative –PS4 support code now in the NT course area Truckworld interface (stop, start,
CSE473 Winter /07/98 A Behavior-Based Reactive Agent Reactive = decision to act made on current sense data alone (as opposed to remembering things.
Basic Introduction to Lisp
Functional Programming “When I code in C, I feel I'm on a knife-edge of ‘state’ — I focus on statements and what they do. I'm worried about the behaviour.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
CSE 341, S. Tanimoto Lisp Explicit Application of Functions and Functional Arguments In Lisp, functions can be passed as arguments to other functions.
CSE573 Autumn /04/98 Natural Language Processing Administrative –Example code available in code\ps4\sample directory Last time –using features.
Functional Programming
Functional Programming Languages
Section 15.4, 15.6 plus other materials
Getting Started with Lisp
J.E. Spragg Mitthögskolan 1997
FP Foundations, Scheme In Text: Chapter 14.
Bindings, Scope, and Extent
Modern Programming Languages Lecture 20 Fakhar Lodhi
CSE S. Tanimoto Explicit Function Application
Lisp: Using Functions as Data
CISC101 Reminders All assignments are now posted.
Defining Functions with DEFUN
Peter Seibel Practical Common Lisp Peter Seibel
Abstraction and Repetition
Lisp: Using Functions as Data
Bindings, Scope, and Extent
Bindings, Scope, and Extent
Common Lisp II.
The general format of case is the following: (case <key form>
LISP primitives on sequences
Procedures with optional parameters which do not require matching arguments Example: consider the exponent function which may take one argument, m, in.
Presentation transcript:

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

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

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)