Home

Herbal Tutorial v3.1c - Applied Cognitive Science Lab

image

Contents

1. 0 04 0 26 6 4 RUNNING THE HIERARCHICAL MODEL nennen tenete etes etas ettet resins i sen 27 Gentle Introduction to Herbal 2 6 4 1 Interpreting the Soar output eerte tenerent trene trente 28 6 42 Interpreting the ie eene eerte iter iret epe de Fiet 29 6 5 ADDITIONAL EXERCISES ccscccsssccssscessccssscessscesecessecessccssscessecesseccssccesscessecessecessecessecesscesaecessecessecsuscessecessecesseceneeees 29 7 LESSON 5 DEBUGGING A HIERARCHICAL MODEL eere sten setas 30 7 1 DEBUGGING THE HIERARCHICAL MODEL IN SOAR cscccssscessscesseeessccesseecsecessecessecesscessecessecessecesseceasecuecesecenseceseeees 30 7 2 DEBUGGING THE HIERARCHICAL MODEL IN JESS 32 7 3 DEBUGGING THE HIERARCHICAL MODEL IN HERBAL eere nnne 32 ADDITIONAL EXERGISES ne Us Fe e ERG divite ERO Ol D 34 8 LESSON 6 LEARNING baee ee eene eee o ERR EVEN TERES E RR coisas ERRARE RE UR EAE ea 34 8 1 RUNNING SALLY WITH LEARNING ENABLED cette enne nennen 0000 et
2. 7 3 2 ADDITIONAL EXERCISE Si p e ETE Re Eee PR ER RECUERDO 8 4 LESSON 2 CREATING A VERY HUNGRY AND THIRSTY AGENT NAMED 8 4 1 CREATING A NEW HERBAL PROJECT ccssscessecesseeesseesseccssecessecessecessccssscessecessseeseccesscessecessecessecesseeseecenseceseeeseseaseees 8 4 2 BUILDING AGENT SALLY eseeeeeeeeeeeeee eene enne enne nhs eere etras strae stos 00 sete ae ens 9 43 CREATINGAN AGENT ie tae Gd eee cree obere 9 4 4 CREATING A PROBLEM SPACE ccccccsscsssscessecessecessecesscessscessecessecesscessscesssecseecessecesseesscessecessecsesesesseenssceseceseseseeeaees 10 4 5 CREATING 8 4 2 4 0 0 eene ette EADAE tes ttes etes sn 10 4 6 2222000000 vede eese 11 o I CREATING CONDITIONS E 12 4 8 CREATING ACTIONS Ee RR t 13 4 9 ASSOCIATING CONDITIONS AND ACTIONS WITH OPERATORS 0000000001000000000000000050000 entere ennt 15 440 WRAPPING UP THE SALLY AGENT EG dO EEG EN EG 16 AAT DDINGAIDESIGN RATIONALE ene OR
3. M 59 A Gentle Introduction to Herbal 3 11 2 INSTANTIATING THE DTANK PREDEFINED MODEL eene eene 63 11 3 UNDERSTANDING THE PREDEFINED DTANK MODEL eene eene 63 11 4 EXECUTING THE HERBAL TANK IN THE DTANK ENVIRONMENT eene nennen teen een te entres 65 11 5 DEBUGGING DTANK MODELS 4 tree eere e eve ed e eee eee 66 11 65 ADDITIONAL EXERCISES e cete tese e eel aul e de VEL e pd IEEE ES 68 12 ADVANCED FEATURES 68 121 PREFERENCES etre metam arii erinnert et 68 12 2 ELABORA TONS USERS ERGO E GG 70 Er 72 A Gentle Introduction to Herbal 4 1 Introduction Herbal is a high level behavior representation language that is realized through an integrated development environment consisting of a high level language a compiler and a graphical editor that acts as a first step towards creating development tools that support the wide range of users of intelligent agents and cognitive models 1 1 Why Use Herbal The main objective of Herbal is to allow developers to focus on the architectural aspects of the cognitive agent while the detailed aspects of the programming nuances are managed by the Herbal compiler Additionally the distinguishing characteristic of Herbal is to create models that explai
4. f 1 Wander Figure 6 Vacuum Cleaner Problem Space Hierarchy 9 10 Running Tom in the Vacuum Cleaner Environment To run Tom the new vacuum cleaner agent you will need to install the vacuum cleaner environment Instructions for downloading and installing the environment can be found from Mark Cohen s webpage at http www marklisa us markacohen Once you get the environment running you can load your model using the File menu Because the environment supports both Jess and Soar you can run either version of Tom While Tom is running trace statements will appear in the console that will help you view the details of the model while it is executing The exact output depends on if you chose to run the Soar or Jess model A Gentle Introduction to Herbal 49 9 11 Additional Exercises Once you have Tom up and running there is a whole host of things you can try Here are just two you may find interesting l Use the Options Configure Board menu item in Vacuum to create a board that is 2 x 2 and has 2 dirty squares Try running your model four times each time with a different instance of this board configuration hitting reset will generate a new random instance of the board What does the model do Why Create a second agent within the same project that operates in the problem space hierarchy shown in Figure You will find the syntax of the action and perception you need in Table 10 Here are a few h
5. annee 34 832 lt PRESCRIPT AND POSTSCRIPT xx eee NR Ur REPE RENE REECE RE 36 8 3 ADDITIONAL EXERCISES cccccsssccssecessccesscesescessecessecessccssscessecesseccssecessccsecessecessecessecesssessecessecesseceaseceaecesecenseseneeees 37 9 LESSON 7 CREATING A SIMPLE VACUUM CLEANER MODEL IN HERBAL eere eere 37 9 1 INTERACTING WITH AN EXTERNAL ENVIRONMENT cccccccsssssccessssccesssscsessssecessssecessssecsssssecessssecessssecesesecsseseseeaass 37 92 MANAGING MULTIPLE PROJECTS ccccccssccssscessccesseescscessecessecessecessecesseesseccsecessecesseesecesecessecessseessecseceseceseseneeees 38 9 3 CREATING TYPES THAT INTERACT WITH AN ENVIRONMENT 39 94 VIEWING EDITING AND SHARING LIBRARY CODE cccccsssccssscessccesseesecesecessecessecssscessecesseccssecesscessecenseeeseeceseeees 40 9 5 CREATING reset te 42 9 6 CREATING VACUUM CLEANER ACTIONS cccccssscsssscssscessscessesessecessecssscessecessecessecessecsuecessecesseceseecsusecasescaeceseeceneeees 45 97 CREATING VACUUM CLEANER OPERATORS ccccsssscsssecssscessecessesessecssscessecessecessecsssecsssecssecesseceseecsssceaecesseeeeeeceneeees 46 9 8 CREATING VACUUM CLEANER PROBLEM SPACES ccccssscsssscessecessecessecesecessecessecessecessccuscesssecssecessecessecss
6. 4 When you save the file the model will automatically be regenerated To confirm that the commands were added to the model double click on the Sally soar file located in the output soar folder of the HungryThirsty project Herbal supports four different script files prescript soar prescript jess postscript soar and postscript jess The contents of these files are included at the top or bottom of the Soar or Jess model output files Feel free to create edit these files as needed to insert custom code into the source files generated by Herbal 8 3 Additional Exercises TBD 9 Lesson 7 Creating a Simple Vacuum Cleaner Model in Herbal To make the process of learning Herbal more interesting an animated vacuum cleaner agent environment was created and is available on the Herbal website as a separate download This environment is based on the vacuum cleaner world introduced in the popular Artificial Intelligence textbook written by Russell and Norvig 2003 The goal of this lesson is to demonstrate how to create an Herbal model that executes in this environment 9 7 Interacting With an External Environment The model created in this lesson differs from the previous Sally models because it interacts with and executes in an external environment Herbal assumes that agents interact with their environment by way of sensors and effectors Information that is detected by an agent s sensor is A Gentle Introduction to Herbal 38 plac
7. jar 7 Go to the Eclipse application s plugin folder For example go to C Program Files eclipse eclipse plugins On the Mac go to Macintosh HD My Applications Eclipse Eclipse Plugins 8 Copy and paste the downloaded jar file to this folder 9 Close the Eclipse application if it was open and reopen it 10 If an Herbal menu has been added to the main menu in Eclipse the installation was successful You are now ready to begin writing agents in Herbal 3 Lesson 1 The Basics of the Herbal Interface The goal of this lesson is to demonstrate how to execute Herbal and provide an overview of the Herbal Interface A Gentle Introduction to Herbal 7 3 1 Starting Herbal and Initializing the Interface Figure 2 provides a brief overview of the major components of the Herbal interface within the Eclipse environment All development within the Herbal environment should be done starting with the window arrangement shown in Figure 2 To configure Eclipse so that it contains this arrangement perform the following steps 1 Start Eclipse 2 After the Eclipse application finishes loading you may be presented with the Eclipse Welcome Screen Ifthe welcome screen is displayed close it 3 Ifthe Outline view is open on the right hand side of the Eclipse window close it 4 Click on the Open Perspective Button Ej located near the top right corner of the Eclipse window Choose Other and then select the Herbal
8. project folder 3 Select Sally soar and click on the Open button Line 4 13 2 Gentle Introduction to Herbal 20 Repeatedly click on the Step button and watch Sally survive by eating and drinking The output you see in the Soar Debugger should resemble Table 2 Don t worry if you are getting different output because in the next section you will learn how to debug your model in Soar Table 2 Watching Sally Eat and Drink in the Soar Debugger Soar Trace 1 O 01 initialize Survive 2 0 O2 eat Chomp chomp 3 drink Slurp slurp 4 0 04 eat Chomp chomp 5 0 O5 drink Slurp slurp Executing Sally in Jess To run Sally in Jess follow these steps l Open a console window and navigate to the output subfolder of the HungryThirsty project If you are not sure where your project is located on your disk right click ctrl click for the Mac on the HungryThirsty project listed in the Eclipse Navigator View and choose the properties menu item Launch the Jess Shell from this console window consult the Jess documentation if you unsure how to start the Jess Shell Type reset Type watch focus Type watch rules Type batch Sally jess Type run 10 and watch Sally survive by eating and drinking The output you see in the Jess Shell should resemble Table 3 Don t worry if you are getting different output because the next section you will learn how t
9. 4 Select the Types tab inside the Herbal GUI Editor 5 Select the spot data type in the list of existing data types 6 Click on the Rationale button located next to the list of current data types You should see the design rationale that you entered directly into the XML file in step 2 above 7 Chck Finish In Herbal all libraries agents problem spaces operators conditions actions and types are represented in XML and can be found in a project s model folder in the Navigation view As you learn more about Herbal and become more adventurous you may choose to slowly move away from the Herbal GUI Editor and do more of your model development by directly editing the XML Another advantage of storing libraries in separate XML files is that it makes them easy to share For example the next time you or someone you know create an Herbal project that uses vacuum cleaner agents you can copy the vacuum types xml file into the model folder of your new project and the types will automatically become available Herbal can be used to parse XML and compile it into Soar Jess and ACT R output files as well Please refer to Figure 3 for a block diagram of how this is accomplished Models are specified in Herbal using XML libraries that contain either PSCM components for Soar or Jess models or declarative memory elements for ACT R models These XML libraries are parsed and represented in memory using a Document Object Model DOM The in
10. The Model Browser is included by default in the Herbal perspective if you don t see the Model Browser make sure your Eclipse workspace matches Figure 2 by reviewing the steps given in Section 0 However due to the amount of information in this view it is best viewed when maximized within the Eclipse environment To browse your agent s structure follow these steps l 2 Maximize the Model Browser view by double clicking on the Model Browser tab On the left side of the view click Sally On the right side of the view expand the What is this How do I use it and How does it work sections Within each of these sections you will find the design rationale you entered about Sally On the left side of the view expand Sally and then select the Survive problem space Information about the Survive problem space if you had entered it would be shown on the right side of the view Continue to expand and select nodes in the model structure section of the view to see the operators and their conditions and actions Naturally the more diligent you are about entering design rationale for your model elements the more useful the Model Browser will be When you are done viewing your model you can restore the view to its original size and position by double clicking on the Model Browser tab A Gentle Introduction to Herbal 19 4 13 Testing Sally To test Sally out you need to load the agent source code into an e
11. This will move the isHungry condition into the list of conditions that will be used to determine when the ResolveHunger problem space will be created and activated In other words when Sally is hungry RevolveHunger will become active Notice how the isHungry condition can be reused in different contexts of the components in Herbal can be reused freely within a single model or across multiple models Click Finish Repeat steps 1 7 to add the ResolveThirst problem space as a child of the Survive problem space Use the isThirsty condition when you specify the conditions in step 6 Congratulations You just created your first hierarchical model using Herbal 6 3 Viewing the Hierarchical Model in the Model Browser Now that the Sally model has more structure in its behavior it is a good idea to go back to the Model Browser view see Figure 2 to view the model if you don t see the Model Browser make sure your Eclipse workspace matches Figure 2 by reviewing the steps given in Section 0 l 2 Maximize the Model Browser view by double clicking on the Model Browser tab On the left side of the view click the Sally node and expand it You should see the Survive problem space located as a child of Sally Expand the Survive problem space This should display the child problem spaces ResolveHunger and ResolveThirst Expand ResovleHunger and ResolveThirst to see the operators used by these problem spaces You can also
12. fuel number Represents the amount of fuel your tank has left tankHeading number Represents the direction in degrees your tank is facing speedMPS number The speed of your tank in miles per hour speedK PS number The speed of your tank in km per hour throttle number The current setting of your tank s throttle 1 0 to 1 0 armor number The state of your tank s armor dtank types terrain right string The type of terrain located to the right of your tank Possible values include OFF MAP STONE WOODS LOW HILL HIGH HILL GRASS ROAD left string The type of terrain located to the left of your tank Possible values include OFF MAP STONE WOODS LOW HILL HIGH HILL GRASS ROAD up string The type of terrain located above your tank Possible values include OFF MAP STONE WOODS LOW HILL HIGH HILL GRASS ROAD Gentle Introduction to Herbal 63 Type Field Description down string The type of terrain located to below your tank Possible values include OFF MAP STONE WOODS LOW HILL HIGH HILL GRASS ROAD 11 2 Instantiating the dTank Predefined Model At this point in the tutorial you should be fairly familiar with the Herbal environment As a result in this lesson you will be instructed how to instantiate a predefined dTank model that you can later modify on your own This predefined model serves as a starting point for more complicated models To instantiate the predefined dTank model
13. Simulation Frequency Redisplay Frequency Battle Duraton Figure 11 dTank Startup Control Panel Using the Startup Control Panel you can configure a battle Each battle consists of an allied battalion of tanks and an axis battalion of tanks You can add tanks to a battalion by selecting the type of commander to drive your tank and the tank type If you choose a SoarCommander you A Gentle Introduction to Herbal 66 must also select a file that contains the Soar rules generated by Herbal that will be used by your commander To add a Tiger tank driven by a SoarCommander to the allied battalion follow these steps 1 Select SoarCommander from the drop down list of commanders 2 Select Tiger from the drop down list of tank types 3 Click on the button labeled and browse to the tank soar file generated by Herbal for the predefined dTank model You will find this file located in the output subfolder of the tank project If you are not sure where your project is located on your disk right click ctrl click for the Mac on the tank project listed in the Eclipse Navigator view and choose the properties menu item This will show you the project s properties which includes the complete path to the project folder 4 Click on the Add button next to the list of allied tanks To add an opponent to the axis battalion follow these steps 1 Select SmartCommander from the drop down list of commanders 2 Select S
14. 1 4 to create an additional condition name isThirsty Each condition should contain one or more clauses that must all be true for the condition to be true To add clauses to the isHungry and isThirsty conditions follow these steps Select the isHungry condition in the list of existing conditions Click on the Add button located next to the list of current clauses Choose the data type that you want to use in the clause In this case you want to see if an instance of the Person data type exists in working memory with its hungry field equal to true As a result select the Person data type but do not click Next yet If the clause being created happens to successfully match an instance of the Person data type it is helpful to give that instance a name so that it can be used later on in an action For example if we find an instance of the Person data type with a true hungry field we need to set that field to false after Sally eats To give the matching instance a name enter hungryPerson into the Output Variable Name field in the dialog and click Next Select the hungry field and then click on the Restrict button The next window allows you to specify the conditions upon which you will restrict the hungry field In this case you want to restrict the value to be equal to true To accomplish this select from the list of Relational Operators and type true in the Literal field Click Finish and click Finish again Gentle Introduc
15. OOO 17 4 12 BROWSING THE AGENT IN THE MODEL BROWSER VIEW ccccccssssscceescseseesssccecsssecsssssecsssesecessesscssseseesesessseesesseeees 18 4218 TESTING SADLY R ne EE EE I E CE EN EROR bte 19 BABA Executing Sally AB SQUE aue tne e dae i e em RR GR 19 4418222 Executing SallyAn tie E ie olet ticae a ee ERR 20 AAA ADDLITIONAI BXERGISESE aire creates eive ee pedir eie FE Teen 21 5 LESSON3 DEBUGGING SALLY onore ri arra aeneo non Varas nera oea Ea eaa 21 5 1 DEBUGGING SALLY IN SOAR u ccccccsccessecssscessscessesessecessccssscessecessecessecessecsseceseecessecessecsecessecscaecessecessecsuecessecenseseneeses 21 5 2 DEBUGGING SALLY IN JESS c cccccccssscessccssscessscessecessecessecssscessecessecessescsscessscessecessecessecuecessesessecesseceseeessecessecenseceaaees 23 5 3 ADDITIONAL EXERCISES cccccssscessecessecesscessscesecessecessccssscessecesseccssecesscessecessecessecessecesesessecessecesseceascensecessecenseceaseees 23 6 LESSON 4 ADDING HIERARCHY 2 2 20400020 0 404 49 1 48 70 1 404 4 41 8 6 1410 4002 000121 44 40 40 404 23 6 1 PREPARING THE PROBLEEM SPACES vete tesi t e E TEN TA P E E HT GA TU TEE E EE TEE YET ES 24 6 2 BULDING THE HIERARCHY tie c GB C WT OR E OR REGE OO YU EL 25 6 3 VIEWING THE HIERARCHICAL MODEL IN THE MODEL
16. be interacting with sensors and motors As a result this type will not be used for input or output Please do not check the Will this type be used for I O checkbox Click Finish Each data type should contain fields that further qualify the data type For example the Person data type needs to contain two boolean fields one that is true if Sally is hungry and one that is true if Sally is thirsty To add these fields to the Person data type follow these steps l 2 Select the Person data type in the list of existing data types Click on the button located next to the list of current fields Select boolean and click Next Enter hungry for the name of the field and click Finish Repeat steps 1 4 to create an additional boolean field named thirsty 4 7 A Gentle Introduction to Herbal 12 Creating Conditions For Sally to achieve her goal of survival there are two specific conditions that she needs to look out for hunger and thirst These conditions are indicated by the presence of a fact of data type Person with a hungry field of true and or a thirsty field of true To create these conditions follow these steps l 22 10 11 12 13 Select the Conditions tab inside Herbal GUI Editor Click on the New button located next to the list of existing conditions Accept the default value given in the Library field Enter isHungry for the name of the condition and click Finish Repeat steps
17. earlier in the tutorial a problem space consists of a set of operators that are proposed and applied when the conditions for those operators are true There will be times when the conditions for several operators within a single problem space will be true As a result more A Gentle Introduction to Herbal 69 than one operator will be proposed This raises the question of which operator will actually be applied The underlying architecture you are using Jess or Soar will determine how this conflict will be resolved If you want more control over which operator will be chosen in the event of a conflict you can use preferences Preferences make it possible to specify an ordering between proposed operators within a problem space Preferences are specified when you add an operator to a problem space Follow these steps to specify a preference for a specific operator 1 Select the Problem Spaces tab inside the Herbal GUI Editor 2 Select the operator you would like to add a preference to and then click on the Edit button located next to the list of existing operators 3 Click Next 4 Select either best worst or enter a positive integer in the drop down list entitled Preference The meaning of this preference value is described in detail in Table 17 5 Click Finish Preference Value Table 17 Description of Allowed Preference Values Behavior in Soar Behavior in Jess best worst The operator wil
18. expand the operators to view the conditions and actions that make up the operators A Gentle Introduction to Herbal 27 5 Click on the ResolveHunger problem space and on the right side of the view expand the How does it work section Within this section you can see the entry conditions for ResolveHunger Notice that ResolveHunger is created and activated when the isHungry condition is true 6 Continue to expand and select nodes in the model structure section of the view to see the structure of the model Once again the more design rationale that you enter for your model see Section 0 the more useful the Model Browser will be 7 When you are done viewing your model you can restore the view to its original size and position by double clicking on the Model Browser tab 6 4 Running the Hierarchical Model Please run your model using either Soar or Jess by following the steps in Section 0 The output you see should match Table 6 1f you ran your model in Soar or Table 7 1f you ran your model in Jess If it does not match you will need to debug your model see Section 0 but you should finish reading the rest of this section first A Gentle Introduction to Herbal Table 6 Watching the Hierarchical Model Execute in Soar Line Soar Trace 4 1 O 01 linitialize Survive 2 2 O 02 impasse ResolveHungerps 3 3 gt S S2 operator no change 4 4 initialize ResolveHunger 9 54 4
19. goToWall which is true if the radar detects a wall in the chosen direction This condition will be used to reject the chosen direction in this case Please use what you have learned in paragraph 0 to create the conditions isMoving isDir noDir goDown goLeft goRight goUp To create the clause of the condition goBack you will have to use a literal value to bind the field to the from field in a comparison clause Please follow the steps bellow l Make sure you have the goBack condition selected in the list of existing conditions in the edit condition tab of the Herbal GUI Editor Click on the Add button located next to the list of current clauses Select the direction data type in the first page of the wizard Type direction as an output variable name Click Next In the restrict field values page second page of the wizard select from and click Restrict In the Enter Literal Value page select as a Rational operator and type to as a Literal Then click finish Back in the restrict field values page select to Type to as a Local variable name Click Finish To create the clause of the condition goToWall you will have to use a literal value to bind the to field of the direction type to the dir field of the radar type Please follow the steps bellow l Make sure you have the goToWall condition selected in the list of existing conditions in the edit condition tab of the Herbal GUI Ed
20. is just coming 2 The field to of type string which will store the next chosen move that is the direction to where the vacuum cleaner attends to go Notice that only one fact of direction type needs to be instantiated in the model at any time Because this memory of direction has to be available in both the Wander and the Pursue problem spaces then its scope has to be the problem space Because the next chosen move will have to be compared to the previous one we have to give it also the Top scope otherwise we could not compare them in a single condition We will also need another fact to indicate that a move direction has been chosen and that we are ready to enter the Move sub problem space This fact has to have either the scope of the Wander or the Pursue problem space We can call the type of this new fact moving It needs no field Using what you have learned in Section 0 please create the direction type with its two fields from and to and the moving type with no field When this is done your Types tab should look like Figure A Gentle Introduction to Herbal 54 Edit your data types Existing data types The following list contains all your current data types ET VacuumCleaner types direction E VacuumCleaner types moving vacuum types action Et vacuum types position vacuum types radar E vacuum types spot Current fields The following lists all fields for the currently selected model element ET fro
21. nil top S1 5 type state HungryThirsty types Person H1 6 print 7 H1 hungry true thirsty false 8 step 9 2 O 02 impasse ResolveHungerps 10 step Ll 3 gt 5 S2 operator no change 12 step 13 4 initialize ResolveHunger 14 print 52 15 S2 attribute operator choices none impasse no change name 16 ResolveHunger 17 operator O4 parent S1 quiescence t superstate S1 top S1 18 type state 19 print s 20 2 gt S 51 21 O O2 impasse ResolveHungerps 22 gt 5 S2 operator no change 23 step 24 91 4 eat 25 Chomp chomp 26 print H1 27 1 hungry false thirsty true 28 print s gt 5 51 7 2 Debugging the Hierarchical Model in Jess TBD 7 3 Debugging the Hierarchical Model in Herbal Herbal provides its own debugging support for Soar models for version Soar 8 6 only This support requires the Soar Java bridge provided with the Soar 8 6 distribution To use the Herbal debugger follow these steps 1 Copy the following Soar distribution files located in the Soar installation folder into the Eclipse program directory the same directory that contains eclipse exe Gentle Introduction to Herbal 33 For Windows soar library ElementXML dll soar library Java_sml_ClientInterface dll soar library SoarKernelSML dll soar library sml jar For Mac OS lib libElementXML 0 0 0 dylib lib libElementXML 0 dylib lib libElementXML
22. of current clauses Select edit an existing fact from the list of choices for the action and then click Finish In the next window select the type of fact you want to edit In this case select the Person data type but don t click Next yet This action relies on having a named instance available to it for editing The name you provide will be used later when the action is assigned to an operator To provide a name for this instance to be edited type person in the Input Variable Name field and click Next Select the hungry field and click on the Literal button This allows you to specify a literal value for the hungry field Enter true and click Finish and then click Finish again Repeat steps 1 6 for the remaining actions in Table 1 that start with mark The final two actions that need to be created are the printChomp and printSlurp actions These actions exist only to provide visual feedback about Sally s behavior To create the actions follow these steps A Gentle Introduction to Herbal 15 1 Select the printChomp action in the list of existing actions 2 Click on the Add button located next to the list of current clauses 3 Select print from the list of choices for the action and then click Finish 4 In the next window click on the Literal button and enter Chomp Chomp be sure to include quotes around the text and click Finish and then click Finish again 5 Repeat steps 1 4 for printSlurp actio
23. output soar tank soar Table 15 is helpful but there are times when more information is needed Additional debug information can be generated by adding Soar watch commands to the prescript soar file To add more debug information to the log file follow these steps 1 In Herbal look in the Navigator view for a file called prescript soar This file should be located in the model folder of the tank project If you do not find the prescript soar file you can create it by following these steps a Right clicking on the model folder and selecting New gt Other b In the New Dialog Box open the Simple Folder select File and then click Next c Type prescript soar in the File name text field and click Finish 2 Add the following soar command to the prescript soar file watch productions This command will tell Soar to trace all production firings For a list of all of the available watch commands see Chapter 5 of the Soar User s Manual Laird amp B 2005 3 Rerun the tank battle The output in your log file should contain the kind of detail shown in Table 16 The trace shown in Table 16 illustrates the tank s transition from the wander problem space into the attack problem space This transition took place because an enemy was spotted during a scanning operation Gentle Introduction to Herbal 68 Table 16 d Tank Log File With Production Watch Enabled Log File Contents SoarAgent3 gt Firing l
24. perspective 5 Select the Herbal Show GUI Editor menu Item File Edit Navigate Search Project Hex Run Window Help 5 Navigator c _ Ds Herbal GUI Editor x Edit your operato Existing operators The Herbal Perspective Initializes 2 7 HinaryThirsty The Following list conta the views within the Eclipse E Si Hungry Thirsty ops environment for Herbal development Sij HungryThirsty operators drink Yrunory Thirsty operators eat Problems View Lists warnings and errors in the currently loaded project Tasks View Allows the developer to keep a todo list Model Browser A read only view Navigator Displays all of operators operatori Operator d that allows the developer to view the Herbal projects within explanation for how an agent was Figure 2 The Herbal Window A Gentle Introduction to Herbal 8 3 2 Additional Exercises TBD 4 Lesson 2 Creating a Very Hungry and Thirsty Agent Named Sally To get you started with Herbal this section will guide you through the creation of a very hungry and thirsty agent named Sally Sally has a simple life at any given time she may be hungry thirsty or both If Sally is hungry she will eat thus causing her to no longer be hungry Unfortunately eating causes Sally to become thirsty If Sally is thirsty she will drink thus causing her to no longer be thirsty Naturally drin
25. space in an attempt to resolve this impasse The impasse is considered resolved as soon as Sally is no longer hungry Lines 2 4 illustrate the impasse and the creation of the ResolveHunger problem space A Gentle Introduction to Herbal 29 Fortunately for Sally the ResolveHunger problem space is well equipped to handle the situation because it is armed with the eat operator Lines 5 and 6 show the operator in action the eat operator changes the Person working memory element so that it is no longer hungry and at the same time it marks the thirsty field in working memory true Because Sally is not hungry anymore the conditions that caused the ResolveHunger problem space to be created are no longer satisfied and the problem space is destroyed This brings the model back to the Surivive problem space At this point in time Sally is thirsty and this causes a new impasse as shown on line 7 8 The impasse results in the model entering the ResolveThirst problem space line 9 and eventually drinking line 10 11 6 4 2 Interpreting the Jess output trace Although not shown in the trace the Jess model begins in an initialized Survive problem space Because Sally starts life hungry the model immediately encounters an impasse the Survive problem space has recognized the fact that Sally is hungry but it does not know how to solve this dilemma line 1 This impasse causes Sally to leave the Survive problem space and enter the ResolveHunger pro
26. PENNSTATE IST College of Information Sciences and Technology The Pennsylvania State University A Gentle Introduction to Herbal Version 3 1 Mark A Cohen Frank E Ritter Damodar Bhandarkar Olivier Georgeon mcohen lhup edu ritter ist psu edu dnb133 psu edu olg1 psu edu Technical Report No ACS 2007 1 November 7 2008 Revised 3 oct 2011 acs ist psu edu Phone 1 814 865 4455 Applied Cognitive Science Lab The College of Information Science and Technology The Pennsylvania State University University Park PA 16802 A Gentle Introduction to Herbal 1 Table of Contents 1 005 4 lst ueterem ei cete tete te eer ere eter rer e ee 4 1 2 STRUCTURE OF HERBAL 4 2 INSTALEING HERDBYALT 5 3 LESSON 1 THE BASICS OF THE HERBAL INTERFACE eene eere eene 6 3 1 STARTING HERBAL AND INITIALIZING THE INTERFACE 22 60060000
27. Sally agent To complete the agent an initial action along with the eat and drink operators must be added to the Survive problem space so that this problem space can use the operators to achieve its goal of survival Lastly the Survive problem space must be assigned to Sally so that she is aware of this goal To add the initial action and operators to the Survive problem space follow these steps 1 Select the Problem Spaces tab inside the Herbal GUI Editor 2 Select the Survive problem space in the list of existing problem spaces 6 7 A Gentle Introduction to Herbal 17 Click on the Add button located next to the list of current initial actions Select the init action and click on Finish Click on the Add button located next to the list of initial current operators Select the eat operator and click on Finish Repeat steps 5 6 to add the drink operator Finally to add the Survive problem space to the agent named Sally follow these steps l 2 3 4 Select the Agents tab inside the Herbal GUI Editor Select Sally in the list of existing agents Click on the button located next to the list of current problem spaces Select the Survive problem space and click on Finish Congratulations A quick glance at the Problems View should reveal that all warnings have been resolved In other words your agent is complete 4 11 Adding Design Rationale To make it easier to understand and explain the design of
28. You will find this file located in the output subfolder of the HungryThirsty project If you are not sure where your project 15 located on your disk right click ctrl click for the Mac on the HungryThirsty project listed in the Eclipse Navigator view and choose the properties menu item 4 Select Sally soar and click on the Open button A Gentle Introduction to Herbal 22 5 Click on the Step button 6 Type print 81 or the ID of the top state e g S3 into the command text box near the bottom of the Soar debugger This will print the contents of the Survive problem space This should produce the output shown in Table 4 The names of the attributes for the problem space are identified using the symbol Each attribute name is followed by its value You can tell what problem space you are looking at by examining the name attribute in this case you are looking at the Survive problem space Table 4 Printing the Survive Problem Space Survive Problem Space S1 o ET name Survive operator O2 parent S1 superstate nil top S1 type state HungryThirsty types Person H1 7 lf you recall the Sally model uses a working memory element called Person that keeps track of Sally s current hungry and thirsty state This working memory element is located in the HungryThirsty types Person attribute of the Survive problem space see Table 4 If you look at the output shown in Table 4 you will notice that this working memory eleme
29. ally from highest to lowest and the operator with the highest numeric preference will be chosen first See the Jess manual for more details NOTE this behavior is different than what happens in the Soar compilation see column to the left Negative preference values are not allowed in Herbal Value will be ignored by Herbal NOTE this behavior is different than what happens in the Soar compilation see column to the left In Soar a special type of rule called a state elaboration can be created to alter working memory before operators are proposed and applied You can think of elaborations as background processes that wait for a specific event and then alter working memory when that event takes place Elaborations are similar to operators in that they have an if part and a then part The if part contains a series of conditions and the then part contains a series of actions When the conditions are true the actions are executed A Gentle Introduction to Herbal 71 What makes elaborations different than operators is that the working memory elements they create are retracted as soon as the conditions that supported them change In addition elaborations take place before the operators are proposed This allows you to create elaborations that configure working memory in a way that supports your operators It is recommended that you consult the Soar Manual to learn more about elaborations before using the
30. already familiar with the basics of the Soar Debugger covered earlier Table 8 contains the output from the interactive debugging session you are about to perform You will find it useful to refer to Table 8 while you perform the following steps l Launch the Soar Debugger if it is not already open consult the Soar documentation if you are unsure how to launch the debugger Click on the Excise all button to remove all the rules that are currently in Soar if you just opened the debugger this 1s not necessary Select the File Load Source File menu item and browse the Sally soar file If you are not sure where your project is located on your disk right click on the HungryThirsty project listed in the Eclipse Navigator view and choose the properties menu item This will show you the project s properties which includes the complete path to the project folder Select Sally soar and click on the Open button Click on the Step button You should see the output shown on line 2 in Table 8 At this point the model has entered the top most problem space Survive Type print 81 into the command text box near the bottom of the debugger to see the attributes for the Survive problem space lines 4 5 in Table 8 Type print H1 to see the state of the Person working memory element line 7 in Table 8 Type step and you should see an impasse encountered in the Survive problem space line 9 Type step two more times and you shoul
31. an agent Herbal supports the addition of design rationale to model elements For each element in the model rationale about what the element is how it is used and how it works can be provided For the purposes of this tutorial you will add design rationale for Sally Specifying rationale for the rest of the model elements is left as an additional exercise To add design rationale to Sally follow these steps l 2 Select the Agents tab inside the Herbal GUI Editor Select the Sally agent located in the existing agents list Click on the Rationale button In the What is this element field enter the following This agent is designed specifically to show beginner users how to program a simple agent in Herbal 5 7 Gentle Introduction to Herbal 18 In the How do I use this element field type This agent does not need special agent environment and can be executed directly in both the Soar and Jess debugging environments In the How does this element work field enter the following This agent operates in a single problem space called Survive that has the goal of survival Survival is accomplished by eating when hungry and drinking when thirsty Click Finish 4 12 Browsing the Agent in the Model Browser View Herbal provides a Model Browser view see Figure 2 that allows you to view the structure of an agent along with design rationale and other explanatory information about an agent s components
32. apply global remove dtank types turretHeading Firing propose wander turn Firing propose wander scan Firing propose wander move Retracting propose wander move Retracting propose wander scan Retracting propose wander turn SoarAgent3 gt Firing apply wander scan scanning SoarAgent3 gt Firing propose topspace impasse attackps Retracting propose topspace impasse wanderps SoarAgent3 gt Firing lapply global remove dtank types turretHeading SoarAgent3 gt Firing propose initialize attack SoarAgent3 Firing apply initialize attack stopping Firing propose attack fire Firing propose attack aim Retracting propose initialize attack SoarAgent3 gt Firing apply attack fire firing 11 6 Additional Exercises TBD 12 Advanced Features Herbal contains a set of advanced features that you will find useful as you create more complicated models These features often behave differently depending on the architecture you run your model in As a result you should avoid many of these features unless you are planning on running your model in only a single architecture i e only Soar or only Jess In addition it is strongly recommended that the Soar or Jess manual is consulted to get a better understanding of how these features work before using them in Herbal The following sections describe these features in detail Be sure to pay close attention to the areas in which the features vary by architecture 12 1 Preferences As you learned
33. asse ResolveHungerps 2 step 28 11 0 O9 impasse ResolveThirstps 8 2 Prescript and Postscript In the previous section you learned how to turn on learning and instruct the Soar debugger to notify you when a chunk is learned If you are using learning often you may find it tedious to enter these commands each time you load and run a model Fortunately Herbal supports the automatic insertion of Soar or Jess commands at the beginning and end of the generated source code To have Herbal automatically add the required learning commands to the top the generated Soar code for Sally follow these steps 1 Look in the Navigator view for a file called prescript soar This file should be located in the model folder of the HungryThirsty project If you do not find the prescript soar file you can create it by following these steps a Right clicking on the model folder and selecting New gt Other b In the New Dialog Box open the Simple Folder select File and then click Next A Gentle Introduction to Herbal 37 c Type prescript soar in the File name text field and click Finish 2 Double click on the prescript soar file This will open the file in the Eclipse editor The file should be empty 3 Everything you type in this file will automatically be included at the top of the generated Soar code Type earn e on the first line of the file and watch L print on the second line of the file In Soar 9 3 1 type watch L 1
34. blem space all in an attempt to resolve this impasse line 2 and 3 The impasse is considered resolved as soon as Sally is no longer hungry Fortunately for Sally the ResolveHunger problem space is well equipped to handle the situation because it is armed with the eat operator Lines 4 and 5 show the operator in action the eat operator changes the Person working memory element so that it is no longer hungry and at the same time it marks the thirsty field in working memory true Because Sally is not hungry anymore the conditions that caused the ResolveHunger problem space to be created are no longer satisfied and the problem space is destroyed line 6 and 7 This brings the model back to the Survive problem space line 8 At this point in time Sally is thirsty and this causes a new impasse as shown on line 9 The impasse results in the model entering the ResolveThirst problem space line 11 and eventually drinking line 12 and 13 6 5 Additional Exercises TBD 7 Gentle Introduction to Herbal 30 Lesson 5 Debugging a Hierarchical Model As models become more complicated it becomes more important to be able to debug them effectively In this lesson you will learn how to debug a more complex hierarchical model 7 1 Debugging the Hierarchical Model in Soar In this section you will run the new hierarchical Sally model using the Soar debugger to closely follow the execution of the model It is assumed that you are
35. chy according to the Figure 8 A Gentle Introduction to Herbal 59 The Move problem space can be added as a sub problem space of both the Wander and the Pursue problem spaces In each case the condition to enter it is the isMove condition Note that it will not be entered as long as there is still an operator to fire in its parent problem space Therefore it is ok if the moving fact 1s assessed as an initial action of the Wander and Pursue problem spaces 11 Lesson 9 Creating a Simple dTank Model in Herbal While the vacuum cleaner environment is interesting the challenges it presents are quickly overcome A more challenging and rich environment is needed to teach more advanced agent programming dTank acs ist psu edu dtank is such an environment and in this lesson you will learn how to create a dTank agent 11 1 dTank I O dTank provides a competitive battleground where battalions of tanks fight it out for supremacy Tanks can be driven by human interaction or by intelligent agents written in a variety of languages Much like the vacuum cleaner environment dTank defines a set of working memory that allows the agent to interact with its environment All of the nuances of the dTank environment are not specified in this tutorial Instead just enough information is provided to get you started building simple models For a more complete description of dTank see the dTank manual located on the dTank website acs ist psu edu dtank An
36. d to change the direction fact instead of performing the actual move So l The moveRandon action must edit the direction fact and set its to field to the value rendered by the randon function This action will have to be performed in the Top scope The moveToDirt action must edit the direction fact and set its to field to the value given by the dir field of the fact of radar type which will be identified by the input variable called dirtySquare This action will have to be performed in the Top scope Please refer to paragraph 0 for the creation of this action 10 5 Creating operators Now that we have created conditions and actions we have to link them within operators We will need the following additional operators l The abortGoBak operator It will be triggered 1f the goBack condition is true and will fire the abortMove action It will wire the direction variables of this condition and this action We can keep blank the overriding scope property of its conditions and actions The abortGoToWall operator It will be triggered if the goToWall condition is true and will fire the abortMove action It will wire the direction variables of this condition and this action We can keep blank the overriding scope property of its conditions and actions The memoFromDown operator It will be triggered if the goUp condition is true and will fire the memoFromDown action It will wire the direction variables of this condition and th
37. d you will find some help by reading the Soar models The input and output working memory elements supported by the dTank environment are listed in Table 14 A Gentle Introduction to Herbal 60 Table 14 dTank I O Type Field dtank types turretHeading value number dtank types tankHeading value number dtank types throttle value number dtank types action value string dtank types friend x number Description Turns the tank s turret in the specified direction Direction is specified as degrees clockwise from 0 to 360 What the tank operator sees and the direction of its fire is based on the direction that the turret is pointing Turns the tank s body in the specified direction Direction is specified as degrees clockwise from 0 to 360 Starts the tank moving either forward or backward The throttle can be set to a number between 1 0 and 1 0 Zero stops the tank negative numbers move the tank backward and positive numbers move it forward Can have any of the following values fire faster slower rotateTurret rotateTank Fire sends a missile in the direction that the turret is facing Faster and slower either speed the tank up or slow the tank down by 0 1 Finally rotate Turret and rotateTank move the turret or tank body an addition 30 degrees clockwise from its current orientation Represents the x location of a friendly tank Note you only see the tank if your turret is pointing
38. d Jess and each of these architectures has advantages and disadvantages One of the advantages of using Soar 15 that it is capable of modeling learning This lesson will demonstrate how to execute the Sally model so that it learns 8 1 Running Sally With Learning Enabled Soar models must operate within a hierarchy of problem spaces for them to be able to learn Fortunately the model created in Section 0 is hierarchical and as a result can learn when it 1s run within Soar Soar simulates learning by creating a chunk when a model successfully uses problem solving to resolve an impasse If the model encounters the same impasse later on it can immediately resolve it using the learned chunk instead of repeating the problem solving tasks it used to resolve the impasse the first time This allows the model to accomplish tasks more quickly Getting the latest Sally model to learn is as easy as turning on learning inside the Soar debugger Output generated by the Soar Debugger during the execution of a learning Sally model is listed in Table 9 You will find it useful to refer to Table 9 throughout this lesson To watch Sally learn follow these steps 1 Launch the Soar Debugger consult the Soar documentation if you are unsure how to launch the debugger 2 Select the File Load Source File menu item and browse to the Sally soar file You will find this file located in the output subfolder of the HungryThirsty project If you are no
39. d see the creation of the ResolveHunger problem space to resolve the impasse lines 10 13 in Table 8 A Gentle Introduction to Herbal 31 9 Type print s2 to view the attributes for the new ResolveHunger problem space lines 15 17 in Table 8 10 Type print s to see the current problem space hierarchy lines 19 21 in Table 8 Notice that at the top of the hierarchy is S7 Survive Also notice that S7 has a child problem space S2 ResolveHunger that was created by an impasse 11 Type step again to see the eat operator get applied lines 23 24 in Table 8 12 Type print H1 to see the state of the Person working memory element line 26 in Table 8 Notice that Sally is no longer hungry and has become thirsty 13 Type print s to view the problem space hierarchy again line 27 28 in Table 8 Notice that the ResolveHunger problem space has been destroyed and that the hierarchy only contains the top state Survive This happened because the conditions that caused the impasse have been resolved Sally is no longer hungry If you continue to debug the model you should see Sally enter the ResolveThirst problem space and drink A Gentle Introduction to Herbal 32 Table 8 Output From the Interactive Debugging Session of a Hierarchical Model Line Output From the Interactive Debugging Session 1 Step 2 1 O 01 linitialize Survive 3 print 51 4 51 io 1 name Survive operator 02 parent S1 superstate
40. d then click Finish In the next window select action data type and click Next For this particular action we want to move in the direction of a nearby dirty square The actual direction that the vacuum cleaner will move will depend on its current situation As a result we must depend on a condition to provide us with the correct direction Specifically we will use the output variable of the nearbyDirty condition to determine what direction to move to Select the move field and click on the Get button Because we will rely on a matched a radar fact to tell us what direction to move in select on radar and click Next and then select dir and click Next This action relies on having a named instance available to it so it knows what direction to move in The name you provide will be used later when the action is assigned to an 12 A Gentle Introduction to Herbal 46 operator To provide a name for this instance type dirtySquare in the Input Variable Name field and click Finish Click Finish again Follow these steps to create the moveRandom action l 2 10 11 12 13 9 7 Select the Actions tab inside the Herbal GUI Editor Click on the New button located next to the list of existing actions Accept the default value given in the Library field Enter moveRandom for the name of the action and click Finish Select the moveRandom action in the list of existing actions Click on the Add button located nex
41. ddle River NJ Prentice Hall W3C 2004 The Extensible Markup Language
42. dylib lib libJava sml ClientInterface 0 0 0 jnilib lib libJava sml ClientInterface 0 jnilib lib libJava sml ClientInterface jnilib lib libSoarKernelSML 0 0 0 dylib lib libSoarKernelSML 0 dylib lib libSoarKernelSML dylib soar library sml jar Be sure that your Herbal perspective is up to date by selecting Window gt Reset Perspective in Eclipse Activate the Herbal Debug view by clicking on the Debug View tab near the bottom of the Eclipse window Run the Soar Debugger and load the Sally model as described in section 4 In Herbal click on the Connect button Next in Herbal select the Soar agent from the drop down list it will probably be called 1 In Herbal click on the Listen button In the Soar Debugger click on the Step button several times and watch as the Herbal debugger builds a trace of your model in the debug view The Herbal debugger keeps track of debug events on the left hand side of the window Clicking on an event displays the conditions that were true during that event the operators that were proposed the operator A Gentle Introduction to Herbal 34 that was applied shown in all capital letters and the actions that were performed Finally the state of working memory after the actions were executed is shown at the bottom of the debug window 7 4 Additional Exercises TBD 8 Lesson 6 Learning As described earlier Herbal is capable of producing models in both Soar an
43. eat 6 Chomp chomp 7 6 05 impasse ResolveThirstps 8 7 gt 5 S3 operator no change 9 8 O O6 initialize ResolveThirst 10 9 O O7 drink 42 Slurp slurp Table 7 Watching the Hierarchical Model Execute in Jess Line Jess Trace 1 FIRE 1 Survive HungryThirsty models impassel f 1 2 lt Focus Survive 3 gt Focus ResolveHunger 4 FIRE 2 ResolveHunger HungryThirsty operators eat f 2 5 Chomp chomp 6 FIRE 3 ResolveHunger ResolveHunger exit f 4 7 lt Focus ResolveHunger 8 Focus Survive 9 FIRE 4 Survive HungryThirsty models impasse2 f 3 10 lt Focus Survive 11 gt Focus ResolveThirst le FIRE 5 ResolveThirst HungryThirsty operators drink f 2 13 Slurp slurp 28 The hierarchical nature of the model can be seen in the output traces shown in Table 6 and Table 7 Understanding this output is an important part of understanding the new behavior of Sally The next two sections will explain the Soar and Jess output respectively 6 4 1 Interpreting the Soar output trace The first line of output in the Soar trace illustrates the initialization of the Survive problem space The second line is new the model has encountered an impasse In other words the Survive problem space has recognized the fact that Sally is hungry but it does not know how to solve this dilemma and thus has reached an impasse This impasse causes Sally to enter the ResolveHunger problem
44. ecause this action is expecting input variables additional information must be provided As a result you need to click Next 6 The next window allows you to assign wire the output variables captured by the conditions with input variables required by the actions In this case the markNotHungry action is expecting an instance of the Person data type named person Meanwhile the isHungry condition names the instance of the Person data type that matches its clause to hungryPerson As result we need to assign the hungryPerson output variable to the person input variable To do this select the hungryPerson variable in the Condition Output Variables list and the person variable in the Action Input variable list and then click on the Assign button This creates a wire between the input and output variables so that working memory elements matched in the conditions are passed to the input variables in the actions 7 Click on Finish 8 Repeat steps 4 7 to add the markThirsty action However in step 6 because we have already wired the output variable hungryPerson to the input variable person you do not need to make the assignment again so you just click Finish The drink operator functions much like the eat operator At this point you should feel comfortable with adding the appropriate actions printSlurp markNotThirsty and markHungry to the drink operator 4 10 Wrapping Up the Sally Agent We are almost done creating the
45. ecenseeeeeens 47 9 9 WRAPPING UP THE VACUUM CLEANER AGENT c ccessccssscessscessecesseccsscessecessecessecesscessecessesessecessecesscessecesseceseecenaeees 48 9 10 RUNNING TOM IN THE VACUUM CLEANER ENVIRONMENT eene tree three eene tnn 48 O T1 ZADDITIONAT EXERCISES 5e e REN RE RENT 49 10 LESSON 8 MULTI PROBLEM SPACE LEVELS AND SCOPE OF 20 0 02 51 10 1 CREATING A MULTI LEVEL VACUUM 0 80 nen 52 10 2 CREATING a e a EC T eto aae tuse tei studs 53 10 3 CREATING CONDITIONS cccccessccssscessscesseescsecesscessecessecessecessceseccsecessecesscessecessecessecesssesuscessecessecesseceaseesaecensesenseees 54 10 4 CREATING ACTIONS eese EEEE E 56 10 5 CREATING 85 1 2 0 0 1 2000 0000100000000000000000000000005000000 re 57 10 6 CREATING THE PROBLEEM SPACES tette aea teet vcn aeta a e d etes 58 10 7 CREATING THE CLEANING BULL AGENT tete ceret ee ee EE EEIE ON Pe EUER eee US 58 11 LESSON 9 CREATING SIMPLE DTANK MODEL IN HERBAL eene eene eoe en eene eene teneas 59 1154
46. ed in working memory so the agent can react to it In addition agents can perform actions by placing commands in working memory that activate its effectors Each environment must provide documentation on the working memory elements represent sensor readings and the working memory elements that represent agent actions The input and output working memory elements supported by the vacuum cleaner environment are listed in Table 10 Table 10 Vacuum Cleaner Environment Input and Output Working Memory Elements Type Field Description vacuum types action move string Allows the vacuum cleaner to perform an operation within the environment Supported operations are left right up down and suck vacuum types position x number Represents the vacuum cleaner s current horizontal position y number Represents the vacuum cleaner s current vertical position vacuum types spot status string Represents the status of the vacuum cleaners current location Possible values are clean or dirty vacuum types radar dir string Represents the location of the radar reading Possible values are eft right up and down reading string Represents the status of the location specified by dir Possible values are clean dirty or wall 9 2 Managing Multiple Projects The first step towards creating a vacuum cleaner model is to create a new Herbal project Please take the time now to create a new project called VacuumCleaner if you do not r
47. eld binded to a direction input variable It will perform the actual move to the chosen direction This action will have to be performed in the Top scope A startMoving action which will assert a moving fact It will trigger the entrance into the Move sub problem space This action will have to be performed in either the Wander or the Pursue scope A stopMoving action which will delete the moving fact when the move will have been performed This action will be performed in the Move problem space by referring to its parent scope which will be either Wander or Pursue It will use a moving input variable An abortMove action which will set the to field of the direction fact to the value of no It will be used to reject a direction if the conditions goToWall or goBack are true This action will have to be performed in the scope A Gentle Introduction to Herbal 57 A memoFromDown actions which will change the from field of the direction fact to down It will be called when the goToUp condition is true to memorize this move This action will have to be performed in the Top scope Three other actions memoFromLeft memoFromRight memoFromUp which will respectively change the from field of the fact of direction type to Left Right Up when the conditions goToRight goToLeft goToDown will be true In addition compared to the previous model of cleaningTom the moveRandon and moveToDirt actions have to be change
48. emember how to create an Herbal project please revisit Section 0 You should now have two projects listed in the Navigation view HungryThirsty and VacuumCleaner Herbal allows for multiple projects to be open at the same time and switching A Gentle Introduction to Herbal 39 between projects can be done from the Welcome tab in the Herbal GUI Editor To make sure that the VacuumCleaner project is the current project follow these steps 1 Select the Welcome tab inside the Herbal GUI Editor 1f you don t see the Herbal GUI Editor select the Herbal Show GUI Editor menu item 2 In the middle of the Welcome tab should be a link that contains the name of the current project If the VacuumCleaner project is not the current project click on this link to switch to the VacuumCleaner project You can use the Welcome tab at any time to determine what the current project is and to switch between Herbal projects 9 3 Creating Types that Interact With an Environment The next step towards creating a vacuum cleaner model is to build the data types that will allow the model to interact in the environment The required types are listed in Table 10 and can be created from within the Types tab in the Herbal GUI Editor These new types will be created a little differently than those created in Section 0 because they must be placed in a different library and because they interact with the environment Please complete the following steps to c
49. es Figure 1 Structure of Herbal 2 installing Herbal Herbal is developed in the Eclipse Integrated Development Platform and requires that Eclipse version 3 1 2 or version 3 2 be installed on your computer The Eclipse Platform is written in the A Gentle Introduction to Herbal 6 Java language and supports extensive plug in based toolkit construction Full documentation and downloads of Eclipse are available at Attp www eclipse org Before starting the Herbal installation we encourage you to spend some time reviewing the Eclipse tutorial to reduce your cognitive load while learning Herbal Specifically you should read the Getting Started section of the Eclipse Workbench User Guide This can be found by clicking on the Help Help Contents menu item in Eclipse To install Herbal follow the instructions below The installation process is remarkably similar for Macintosh and Microsoft Windows machines 1 To begin with you need the ability to install software and have write permission to the applications you install 2 Go to http acs ist psu edu Herbal index html 3 Click Download on the left frame 4 Onthe Download Page right click on Download Herbal Version xx Release 5 Download it to a local folder 6 Make sure the extension of the file is jar and not zip Internet Explorer 7 may convert the jar file to a zip file If the extension is zip rename it to
50. follow the sequence below 8 Select File New Project 9 On the New Project Window select Herbal Project and click Next 10 For the project name enter tank and choose the default file location to store the project 11 Click Next 12 The next screen allows you to select from a set of predefined models Select dTank and Click Finish 11 3 Understanding the Predefined dTank Model The best way to get to know the predefined dTank model is to browse it using the Model Browser view Double click on the Model Browser tab to maximize this view remember you can double click again to restore it to its original size On the left hand side of the view expand all of the model elements Your model browser should look like Figure 10 A Gentle Introduction to Herbal 64 Problems Tasks E Model Browser zr Model Structure Explanation tank What is this topspace Problemspace Fire getEnemy fire Design Rationale aim getEnemy aim wander turn me v How do I use it turn scan me scan 2 move Design Rationale me move retreat dodge me dodge How does it work Initial Actions stop Entry Conditions enemySpotted and healthy Design Rationale Figure 10 Browsing the dTank Model From the Model Browser view you can see that the model s behavior is represented using three problem spaces attack wander and retreat The attack problem space contains two operators a
51. he behavior of our previous model CleaningTom we can notice that it could be improved in several ways For example it can be improved if when wandering it would at least never go back to the square where it just comes from Let us call such a model CleaningBull To implement its behavior we will need to provide CleaningBull with a memory of where it was just coming from so that we can prevent it to go back there We propose a solution consisting of decomposing the movement into two steps First step choose a direction acceptable with regard to the previous memorized move e Second step memorize this new direction and move to it We can implement this model with the problem space hierarchy shown in Figure 8 If nearbyDirty AndifsquareClean f nearbyAllClean And if squareClean If squareDirty If moving Figure 8 The problem space hierarchy used by CleaningBull the vacuum cleaner In this new hierarchy the choice of the direction will be done in the Pursue and Wander problem spaces and the memorization and actual move will be performed in the Move sub problem space Gentle Introduction to Herbal 53 10 2 Creating types This new model will have to hold the previous move and the choice for the next move in working memory We can store them in a single fact of type direction which will have two fields 1 The field from of type string which will store the direction from where the vacuum cleaner
52. herman from the drop down list of tank types 3 Click on the Add button next to the list of axis tanks To watch the battle click on the Start button Your Soar tank will show up on the right hand side of the map 11 5 Debugging dTank Models The details of a dTank battle are meticulously recorded in a log file during execution This log file is stored in the dTank installation folder and is called dTankResults log By default this file records only the output produced by print statements in your model For example Table 15 contains the top of a log file generated by a SoarCommander A Gentle Introduction to Herbal 67 Table 15 Default dTank Soar Log File Output Log File Contents Starting dTank4 0 version 26 Nov 2006 Starting Battle null Combattants Axis AlliedCommander vs Allied AlliedCommander SoarCommander Allied Tiger NoDisplay 1 C Documents and Settings mcohen My DocumentsNDevelopmentNruntime SmartCommander Axis Sherman No DocumentsNDevelopmentNruntime EclipseApplication tank output soar tank soar Display 1 C Documents and Settings mcohen My EclipseApplication tank output soar tank soar Soar agent file C Documents and Settings umcohen My Documents Development runtime SoarAgent0 turning SoarAgent0 scanning SoarAgent0 moving SoarAgent0 scanning SoarAgent0 turning The default output shown in EclipseApplication tank
53. im and fire and its entry conditions occur when an enemy is spotted and your tank is healthy Figure 10 You can also tell from the Model Browser that upon entering the attack problem space your tank will stop moving Please continue to browse the model using the Model Browser so that you can determine the complete behavior of the tank The Model Browser will provide you with a good understanding of the high level structure of the model However without any design rationale it is hard to grasp the details without using the Herbal GUI Editor If you plan on modifying the model to suit your needs you will want to explore the details A Gentle Introduction to Herbal 65 Take the time now to open the Herbal GUI Editor and explore the inner workings of the dTank model As you discover how the model works be sure to enter design rational for the model elements so that you can capture this information for future reference 11 4 Executing the Herbal Tank in the dTank Environment Before you make any modifications to the dTank model you should run it in the dTank environment to see how well it does against other tanks The dTank environment is available from the dTank website acs ist psu edu dtank The website contains instructions on how to install and execute dTank Please take the time now to download and install dTank When you execute dTank you will see the dTank Startup Control Panel shown in Figure 11 Dimensions 500m x 500m
54. in its direction Gentle Introduction to Herbal 61 Type Field Description y number Represents the y location of a friendly tank Note you only see the tank if your turret 15 pointing in its direction nationality string Represents the nationality of the friendly tank distance number Represents the distance the friendly tank is from your tank heading number Represents the heading in degrees of the friendly tank dtank types enemySpotted flag boolean This flag is set to true when an enemy tank is spotted dtank types inTrouble flag boolean This flag is set to true when your tank is severely damaged dtank types enemy x number Represents the x location of an enemy tank Note you only see the tank if your turret is pointing in its direction y number Represents the y location of an enemy tank Note you only see the tank if your turret is pointing in its direction nationality string Represents the nationality of the enemy tank distance number Represents the distance the enemy tank is from your tank heading number Represents the heading in degrees of the enemy tank dtank types me x number Represents the x location of your tank y number Represents the y location of your tank A Gentle Introduction to Herbal 62 Type Field Description nationality string Represents the nationality of your tank ammunition number Represents the amount of ammunition your tank has left
55. ints a You will need to create a condition squareDirty that is true when the agent is on a dirty square and another squareClean that is true when it is on a clean square b You will need to create an action cleanUp that causes the agent to clean up the current square c You will need to create an operator CleanUp that will clean up the current square if it is dirty This operator will use the condition squareDirty and the action cleanUp created it step a and b d You will need a new problem space called Clean that contains the operator CleanUp created in step e You will need to create a new agent called CleaningTom within the same VacuumCleaner project and add the problem space hierarchy shown in Figure to this agent A Gentle Introduction to Herbal 50 If nearbyDirty andifsquareClean If nearbyAllClean And if squareClean If squareDirty Figure 7 The problem space hierarchy used by CleaningTom the vacuum cleaner Gentle Introduction to Herbal 51 10 Lesson 8 Multi problem space levels and scope of facts In this lesson we will see that each fact belongs to a specific problem space This problem space constitutes the scope of this fact That is when a fact is asserted its scope is defined and cannot be changed In Herbal 3 if the scope is not explicitly overridden when an Operator is triggered within a problem space its scope is set to this current problem space That means
56. is action We can keep blank the overriding scope property of its conditions and actions Gentle Introduction to Herbal 58 4 The memoFromLeft memoFromRight memoFromUp operators similar to the memoFromDown 5 The moveToDir operator It will be triggered if the isDir condition is true and will fire the moveToDir action It will wire the direction variables of this condition and this action We can keep blank the overriding scope property of its conditions and actions 6 The stopMoving operator It will be triggered if the isMoving condition is true and will fire the stopMoving action It will wire the moving variable of this condition to the moving variable of this action This operator will be trigger by the Move problem space and should be executed in its parent scope as it applies to the moving fact which is either asserted in the Wander or in the Pursue problem space The randomMove and smartMove operators will remain unchanged from the cleaningTom model Only their actions have been changed 10 6 Creating the problem spaces Now we can create the problem spaces of our model Pursue Initial action startMoving Operators smartMove Wander Initial action startMoving Operators abortGoBack abortGoToWall randomMove best Move Operators memoFromDown best memoFromLeft best memorFromUp best moveToDir 10 stopMoving worst 10 7 Creating the cleaningBull agent We can now organize our problem space hierar
57. is the case for all squares not just the one above the vacuum As a result you need to create three more clauses for the remaining directions Please repeat steps 6 15 three times specifying down left and right for the value of the dir field When you are done your condition clauses should resemble Figure 4 9 6 Gentle Introduction to Herbal 45 Match radar where dir dovin AND reading wall or reading clean Symatch radar where dir leFt AND reading wall or reading clean Xy match radar where dir right AND freading wall or reading clean Figure 4 Condition Clauses for the nearbyAllClean Condition Creating Vacuum Cleaner Actions In this section two actions will be created in Herbal The first action called moveToDirt will cause the vacuum cleaner to move to a nearby dirty square The second action called moveRandom will cause the vacuum cleaner to move in a random direction Follow these steps to create the moveToDirt action l 2 10 11 Select the Actions tab inside the Herbal GUI Editor Click on the New button located next to the list of existing actions Accept the default value given in the Library field Enter moveToDirt for the name of the action and click Finish Select the moveToDirt action in the list of existing actions Click on the Add button located next to the list of current clauses Select add a new fact from the list of choices for the action an
58. itor Click on the Add button located next to the list of current clauses Select the direction data type in the first page of the wizard Type direction as an output variable name Click Next In the restrict field values page select to Type 20 as a Local variable name Click Finish Click Finish again to terminate the clause definition A Gentle Introduction to Herbal 56 Click again on the Add button located next to the list of current clauses Select the radar data type in the first page of the wizard Click Next In the restrict field values page select dir and click Restrict In the Enter Literal Value page select as a Rational operator and type to as a Literal Then click finish 10 Back in the restrict field values page select reading and click Restrict 11 In the Enter Literal Value page select as a Rational operator and type wall as a Literal Then click finish 12 Click Finish again to terminate the clause definition Note that the two conditions goBack and goToWall could have been merged into a single one but they are kept separated for more clarity 10 4 Creating actions We will also need several new actions l An init action which will assert the direction fact with both its from and to field initialized to no Note that this action will have to be performed in the Top scope A moveToDir action which will add a new output fact of type action with its move fi
59. izes Soar by emptying working memory and re initializing any run time statistics However init soar does not delete the rules in your model As a general rule it is a good idea to click on the Excise all button every time before not after you load the source code for a new model and it is a good idea to click on the init soar button every time you restart a model that is already loaded Or put these statements into your model The Soar debugger provides a lot more functionality than was described here You will learn a few more features in the next lesson In addition you can learn more sophisticated techniques by referring to Chapter 5 of the Soar User s Manual and also the Intro to the Soar Debugger manual Both of these documents are included with the Soar distribution 5 2 Debugging Sally in Jess TBD 5 3 Additional Exercises TBD 6 Lesson 4 Adding Hierarchy to Sally Herbal is based on the Problem Space Computational Model which allows for behavior based on a hierarchy of problem spaces Recall that a problem space is designed to accomplish a specific goal To further divide a problem solving strategy into smaller pieces the goal of a problem space can be broken down into sub goals each sub goal is represented by a child problem space In the upcoming lesson we will change Sally so that her behavior is driven by a hierarchy of problem spaces A Gentle Introduction to Herbal 24 For the purposes of this lesson Sal
60. king causes Sally to become hungry again This cycle continues until Sally s life is ended by way of halting her execution 4 1 Creating New Herbal Project To create a new Herbal project follow the sequence below 1 Select File gt New gt Project 2 On the New Project window select Herbal Project under the Herbal folder and click Next 3 For the project name enter HungryThirsty and choose the default file location to store the project 4 Click Next 5 The next screen allows you to select from a set of predefined models In this example please select Empty because we will be building a model from scratch 6 Click Finish 7 Make sure that your workspace in Eclipse resembles the one shown in Figure 2 If it doesn t review the steps given in Section 0 After your project is created you should see it listed in the Navigator view located in the left pane of the Eclipse window A Gentle Introduction to Herbal 9 4 2 Building Agent Sally In the following sections Sally will be constructed from a collection of problem spaces operators conditions actions and types The order in which Sally is constructed is arbitrary and only loosely constrained by the Herbal environment Keep this in mind when you start developing your own agents in Herbal In addition you should find Figure 2 useful as the upcoming sections frequently reference the components shown in Figure 2 43 Creating an Agent From this point on you wi
61. l be favored over all other operators not given best preference If two operators have best preference Soar will choose randomly between them The operator will rank below all other operators that were not given worst preference If all operators have worst preference Soar will choose randomly between them The operator will be favored over all other operators not given best preference If two operators have best preference Jess will choose using a depth first strategy The operator will rank below other all operators that were not given worst preference If all operators have worst preference Jess will choose using a depth first strategy positive integer negative integer all other values 12 2 Elaborations A Gentle Introduction to Herbal 70 The operator will be chosen based on a probability calculated using the numeric preferences of all other operators For example if operator 1 has a numeric preference of 25 and operator 2 has a numeric preference of 100 operator 2 will be 4 times more likely to be chosen See the Soar manual for more details Negative preference values are not allowed in Herbal Value will be inserted in place of the default preferences used by Herbal indifferent and acceptable This allows the Herbal programmer to override the default preferences used by Herbal This feature is for advanced users only Operators given an integer preference will be ranked numeric
62. le dirtySquare Figure 5 The smartMove and randomMove Operators 9 8 Creating Vacuum Cleaner Problem Spaces To facilitate learning and to provide some organization to the behavior of the vacuum cleaner it will be useful to create some problem spaces for our agent to operate within These problem spaces will produce the higher level behaviors of wandering around the board Wander and pursuing dirty squares Pursue For now each of these higher level behaviors will be implemented with a single operator and will be controlled by a top level space called Top However if the model were made more intelligent in the future these behaviors would become more complex utilizing many operators and residing in a deeper problem space hierarchy Using what you learned in Section 0 and Section 0 please create the problem spaces listed in Table 13 Table 13 Vacuum Cleaner Problem Spaces Problem Space Initial Actions Operators Top None None A Gentle Introduction to Herbal 48 Wander None randomMove Pursue None smartMove 9 9 Wrapping Up the Vacuum Cleaner Agent The last step needed to complete our vacuum cleaner agent is to instantiate an Agent object and assign a problem space hierarchy to it Using what you learned in Section 0 create an agent named Finally using what you learned in Section 0 assign a hierarchy of problems to Tom based on Top ET Pt E V If nearbyDirty If nearbyAllClean
63. ll be working primarily within the Herbal GUI Editor Taking a top down approach we begin by creating the agent itself To create an agent in Herbal perform the following steps 1 Select the Agents tab inside the Herbal GUI Editor 1f you don t see the Herbal GUI Editor select the Herbal Show GUI Editor menu item 2 Click on the New button located next to the list of existing agents 3 Accept the default value given in the Library field Libraries are an advanced feature and will be explained later 4 Enter Sally in the Element Name field and click Finish Agents must have at least one goal and operate within at least one problem space to achieve this goal At this point Sally is not associated with any problem spaces and therefore will not exhibit any behavior Herbal recognizes this and places a warning in the Problems View pane to remind the developer that at some point Sally should be associated with a problem space Take the time now to view this reminder in the Problems View pane if you can t find this pane go back now to the Eclipse tutorial and don t get lost It is good practice to consult the Problems View often as it will keep you informed of the various components of the model that remain incomplete As we build more model components and create relationships between these components these warnings will disappear and the model will be ready for testing Note Eclipse defaults set the Problems View to sh
64. ly will accomplish her goal of surviving by continually achieving two sub goals ResolveHunger and ResolveThirst sub goals will take the form of problems spaces that are children of the top level Survive problem space As the design of Sally becomes more complex it is useful to draw upon design patterns to improve the model design pattern 1s a general solution that can be implemented to solve recurring design problems Gamma Helm Johnson amp Vlissides 1995 In this particular case we will use a design pattern that is commonly used to coordinate the interaction between a parent problem space and its many children The design pattern works as follows 1 The parent problem space in this case the Survive problem space does not contain any operators Instead this problem space acts only as a controller for its child problem spaces in this case ResolveHunger and ResolveThirst 2 When a child problem space is assigned to a parent it is given a set of conditions During model execution if the set of conditions is met the child problem space is created and remains active until the conditions are no longer true At that point the child space 15 destroyed and the parent space regains control 3 Ifthe set of conditions for more than one child problem space is satisfied the underlying architecture Soar or Jess decides which child problem space should be created and activated 6 1 Preparing the Problem Spaces To i
65. m string Add S to string Edit Remove Welcome Agents Problem Spaces Operators Conditions Actions Types Figure 9 CleaningBull s data types 10 3 Creating conditions We will need several new conditions for our new model l An isMoving condition which is true if it exists a fact of type moving This condition will trigger the sub problem space Move It will be also used to remove the fact moving An isDir condition which is true if the to field of the moving fact is not equal to no It will be used to trigger the operator that will perform the actual move noDir condition which is true if the to field of the moving fact is equal to no It will be used to trigger the operator that will propose a new moving direction A condition goDown which is true if the field to of the direction fact is equal to down It will be used to memorize that the vacuum cleaner was going to down and thus was coming from up Three other conditions goLeft goRight Up similar to the goDown condition but which are respectively true when the field to of the direction fact is equal to Left Right and up A condition goBack which is true if the field to of the fact of type direction is equal to its field from This condition will be used to reject a chosen direction that would go back to the square where the vacuum cleaner was just before 7 Gentle Introduction to Herbal 55 A condition
66. m in Herbal Because elaborations are made using the same if then structure that operators use you create elaborations by marking an operator as an elaboration This allows for an added dimension of reuse in which you can use a rule as both an operator and an elaboration within and across problem spaces To specify that an operator should be used as an elaboration follow these steps 1 Select the Problem Spaces tab inside the Herbal GUI Editor 2 Select the operator you would like turn into an elaboration and then Click on the Edit button located next to the list of existing operators 3 Click Next 4 Check the Js this an elaboration checkbox 5 Click Finish 6 Notice that the operator will be displayed with an asterisk at the end of its name This indicates that the operator will be used as an elaboration Currently the elaboration flag is ignored in the Jess compilation As a result in the Jess compilation operators marked as elaborations will function as if they were plain old operators Due to the special properties of elaborations in Soar models that use elaborations will likely demonstrate different behavior between the Soar and Jess compilations For this reason elaborations should be avoided unless you only plan to run your model in Soar A Gentle Introduction to Herbal 72 References Cohen M A Ritter F E amp Haynes S R 2005 Herbal A high level language and development envi
67. memory DOM is displayed in the Herbal development environment and can be edited visually using the Herbal GUI Editor Changes made to the DOM via the visual editor are reflected back into the XML libraries The compiler traverses the DOM and transforms it into models written for both Soar and Jess or A Gentle Introduction to Herbal 42 for ACT R Custom native Soar Jess or ACT R code specified in pre script and post scripts are put on the front and back of the compiled code Soar ct R N 4 XML Jess t v Visualizations Compiler Soar Prescript e PSCM Jess Act R Postscript gt PSCM 2 DM Figure 3 Parsing and Compiling XML to Several Output Types in Herbal 9 5 Creating Vacuum Cleaner Conditions Each vacuum cleaner is equipped with radar that informs it of the status of the nearby squares Radar is represented in working memory using the vacuum types radar type see Table 10 For example Table 12 shows the status of working memory when the vacuum cleaner has a clean square above it a wall below it and a dirty square to its right and to its left Table 12 Example of Radar in Working Memory Working Memory A Gentle Introduction to Herbal 43 vacuum types radar dir up reading clean vacuum types radar dir down reading wall vacuum types radar dir right reading dirty vacuum types radar dir left reading dirty In this section tw
68. mplement the design described above the Survive problem space must be cleared of its operators In addition two new problem spaces must be created and operators must be assigned to them To clear the operators from the Survive problem space follow these steps 1 Select the Problem Spaces tab inside the Herbal GUI Editor 2 Select the Survive problem space located in the existing problem spaces list 3 Select the eat operator located in the current operators list 4 Click on the Remove button located to the right of the current operators list 5 Repeat steps 1 4 for the drink operator Gentle Introduction to Herbal 25 To create two new problem spaces follow these steps 1 Select the Problem Spaces tab inside the Herbal GUI Editor 2 Click on the New button located next to the list of existing problem spaces 3 Accept the default value given in the Library field 4 Enter ResolveHunger in the Element Name field and click Finish 5 Repeat steps 1 4 for the ResolveThirst problem space Recall that in our new design the Survive problem space acts as a controller and its two child problem spaces actually perform all of the interesting work In Herbal all of the actual work is done by operators As a result the two new problem spaces need to have operators assigned to them that eat and drink Fortunately these operators were created in the previous lesson and can be reused here that has to be done is to add these operators to
69. n 49 Associating Conditions and Actions with Operators As mentioned earlier operators can be seen to be similar to if then rules and contain conditions and actions If all of an operator s conditions are true it may be chosen by the architecture resulting in its actions being performed To associate the appropriate conditions to the eat and drink operators follow these steps 1 Select the Operators tab inside the Herbal GUI Editor 2 Select the eat operator located in the existing operators list 3 Click the Add button located next to the list of current conditions 4 Select the isHungry condition and click Finish 5 Repeat steps 1 4 to add the isThirsty condition to the drink operator The final step for completing our operators is to associate the appropriate actions to the eat and drink operators The act of eating in our simple world involves the execution of the following actions e printChomp when Sally eats she makes noise e markNotHungry when Sally eats she is no longer hungry e markThirsty when Sally eats she becomes thirsty To add these actions to the eat operator follow these steps 1 Select the eat operator located in the existing operators list 2 Click the Add button located next to the list of current actions 3 Select the printChomp action and click Finish A Gentle Introduction to Herbal 16 4 Click the Add button located next to the list of current actions 5 Select the markNotHungry action B
70. n themselves Haynes Cohen amp Ritter 2009 To achieve this Herbal formalizes the programming process through the use of an explicit ontology of classes Mark A Cohen Ritter amp Haynes 2005 M A Cohen Ritter amp Haynes 2010 that represent concepts of the Problem Space Computational Model Newell 1990 including models states operators elaborations conditions actions and working memory all as first class model objects Programming in Herbal involves instantiating objects using these ontological classes Thus the programming process is reduced to simply instantiating objects rather than coding the classes and structure implicitly in a large set of heterogeneous Soar productions As a result of using Herbal the power of cognitive architectures like Soar can be taken advantage of more directly and easily Current development of Herbal is focused on supporting ACT R models better using the information contained in the Herbal ontology to generate explanations while the model is running and supporting visual models 1 2 Structure of Herbal Herbal is built on the Problem Space Computational Model For a detailed introduction to the model refer to Gentle Introduction to Soar by Lehman Laird and Rosenbloom 1998 and earlier works Newell 1990 Newell Yost Laird Rosenbloom amp Altmann 1991 Herbal is designed based on the concept of self explanation where the model is built with the capability of ex
71. nd type dirty the Literal field 11 Click Finish and click Finish again A Gentle Introduction to Herbal 44 Complete these steps to create the nearbyAllClean condition l 2 10 11 12 13 14 15 16 Select the Conditions tab inside the Herbal GUI Editor Click on the New button located next to the list of existing conditions Accept the default value given in the Library field Enter nearbyAllClean for the name of the condition and click Finish Select the nearbyAllClean condition in the list of existing conditions Click on the Add button located next to the list of current clauses Select the radar data type and click Next A radar reading indicates that a square is not dirty if its reading field is equal to either clean or wall To specify this condition click on the reading field and then click on the Restrict button Select from the list of Relational Operators and type clean the Literal field Click on the Or button Select from the list of Relational Operators and type wall in the Literal field Click Finish Click on the dir field and then click on the Restrict button Select from the list of Relational Operators and type up in the Literal field Click Finish and click Finish again You have just created a clause for the current action that is true if the square above the vacuum cleaner is either a wall or is clean However we want this condition to be true if this
72. nt is designated as H7 To view the contents of this working memory element type print into the command text box This should produce the output shown in Table 5 Notice that the hungry attribute of the Person working memory element is currently equal to true Sally starts out hungry and that the thirsty element is currently false Sally is not yet thirsty Also note that the IDs may change across Soar versions and runs Table 5 Printing the Person Working Memory Element Person Working Memory H1 hungry true thirsty false 8 Click on the Step button and watch the output generated in the debugger window As expected the eat operator is applied and the text Chomp Chomp is printed in the Gentle Introduction to Herbal 23 window the printChomp action was responsible for this This operator will cause Sally to no longer be hungry and to become thirsty To verify this type print H1 again This time you should see that the hungry attribute has been changed to false by the eat operator specifically the markNotHungry action changed the attribute and that the thirsty attribute has been changed to true this was done by the markThirsty action 9 If you continue to hit the Step button and type print H1 you should be able to watch the Person working memory element change as the eat and drink operators are applied 10 If you wish to restart the model at any time click on the init soar button This button initial
73. nvironment and execute it Herbal currently supports two different environments Soar and Jess Before you execute the code it is a good idea to view the code that was generated by Herbal In fact alternating between the Herbal GUI Editor and the generated code is a good way to learn Soar and Jess syntax To view the source code generated by Herbal for the Sally agent follow these steps 1 In the Navigator view locate and expand the HungryThirsty project 2 Expand the output folder 3 Expand the jess and soar folders 4 jess and soar folders will each contain a file containing the source code for Sally These files will be named Sally soar and Sally jess 5 Double click on either of these two files to view the source code After examining the source code you are ready to execute Sally 4 13 1 Executing Sally in Soar To run Sally in Soar follow these steps 1 Launch the Soar Debugger consult the Soar documentation if you are unsure how to launch the debugger 2 Select the File Load Source File menu item and browse to the Sally soar file You will find this file located the output subfolder of the HungryThirsty project If you are not sure where your project 15 located on your disk right click ctrl click for the Mac on the HungryThirsty project listed in the Eclipse Navigator view and choose the properties menu item This will show you the project s properties which includes the complete path to the
74. o conditions will be created one to detect when there is at least one dirty square near the vacuum cleaner and another that detects when there are no dirty square nearby These conditions will be called nearbyDirty and nearbyAllClean respectively Complete these steps to create the nearbyDirty condition l 2 9 Select the Conditions tab inside the Herbal GUI Editor Click on the New button located next to the list of existing conditions Accept the default value given in the Library field Enter nearbyDirty for the name of the condition and click Finish Select the nearbyDirty condition in the list of existing conditions Click on the Add button located next to the list of current clauses Because you want to see if an instance of the radar data type exists in working memory with its reading field equal to dirty select the radar data type but do not click Next yet If this clause happens to successfully match an instance of the radar data type it is necessary to give that instance a name so that it can be used later on in an action For example if we find an instance of the radar data type that is reporting a dirty square we may want to move the vacuum cleaner in the direction of that dirty square To give the matching instance a name enter dirtySquare into the Output Variable Name field and click Next Select the reading field and then click on the Restrict button 10 Select from the list of Relational Operators a
75. o debug your model in Jess Gentle Introduction to Herbal 21 Table 3 Watching Sally Eat and Drink in the Jess Shell Line Jess Trace FIRE 1 Survive HungryThirsty operators eat f 2 Chomp chomp FIRE 2 Survive HungryThirsty operators drink f 2 Slurp slurp FIRE 3 Survive HungryThirsty operators eat f 2 Chomp chomp FIRE 4 Survive HungryThirsty operators drink f 2 Slurp slurp 4 14 Additional Exercises TBD 5 Lesson 3 Debugging Sally Both Soar and Jess provide features that make it possible to observe Sally in action at a much more detailed level By debugging Sally at this level you can obtain a deeper understanding of how the model and the architectures work and fix any problems with the model If the output of your running model did not match Table 2 for Soar or Table 3 for Jess you may find this lesson especially useful 5 7 Debugging Sally in Soar In this section you will re run Sally using the Soar debugger to closely follow the execution of the model Follow these steps to learn how to debug Sally 1 Launch the Soar Debugger if it is not already open consult the Soar documentation if you are unsure how to launch the debugger 2 Click on the Excise all button to remove all the rules that are currently in Soar if you just opened the debugger this 15 not necessary 3 Select the File Load Source File menu item and browse the Sally soar file
76. ow problems for all projects To change this so that it only shows problems for the current project perform the following steps A Gentle Introduction to Herbal 10 Select the Problems tab on the bottom of the Eclipse IDE Click the View Menu button it is a downward facing triangle Select Configure Contents A SEES Select the box All Error in the left pane and On any element in the same project in the Scope pane 5 Click Okay 44 Creating a Problem Space To keep this initial example simple Sally s world will consist of a single goal survival Trealized using a single problem space To create a problem space for Sally to operate within perform the following steps 1 Select the Problem Spaces tab inside the Herbal GUI Editor 1f you don t see the Herbal GUI Editor select the Herbal Show GUI Editor menu item 2 Click on the New button located next to the list of existing problem spaces 3 Accept the default value given in the Library field 4 Enter Survive in the Element Name field and click Finish 45 Creating Operators To stay alive Sally must eat when she is hungry and drink when she is thirsty Actions such as these are performed using operators To create an eat and drink operator perform the following steps 1 Select the Operators tab inside the Herbal GUI Editor 2 Click on the New button located next to the list of existing operators 3 Accept the default value given in the Libra
77. plaining itself Haynes Cohen amp Ritter 2009 In Herbal the topmost entity the A Gentle Introduction to Herbal 5 agent operates within a problem space which is driven by a global goal The goal defines the reason for the agent s existence Each problem space is a collection of several sub problem spaces which are also goal driven and in turn define smaller and more local goals in the service of the topmost problem space Problem spaces also form a collection of procedural knowledge realized as operators An operator associates conditions to actions Conditions are in essence patterns that match facts in working memory Some of these facts may be the result of sensor readings Actions result in the creation of new facts in working memory that may result in the agent performing tasks When an operator is created it defines the conditions in the environment that trigger necessary actions At the most basic level working memory is defined by instantiations of working memory elements based on types Types are similar to data types in traditional programming languages and provide structures for storing facts from the environment A schematic view of the Herbal structure is given in Figure 1 Agent Collection of Y Problem Spaces Colection of Uses Operators to solve sub goals Y Operator Associates Condition to Action Condition gt Action Retreive d types Typ
78. reate these types 1 Select the Types tab inside the Herbal GUI Editor 2 Click on the New button located next to the list of existing data types 3 The I O types names are defined by the vacuum environment as given in Table 10 To conform to these names we have to create them in a different library To do that change the default value given in the Library field to vacuum types If vacuum types is not a choice in the drop down list you will have to type it directly into the Library field be careful not to capitalize the v of vacuum 4 Enter action in the Element Name field 5 Because this type is used to interact within the vacuum cleaner environment please be sure to check the Will this type be used for I O checkbox 6 Click Finish A Gentle Introduction to Herbal 40 7 Select the action data type in the list of existing data types 8 Click on the Add button located next to the list of current fields 9 Select string and click Next 10 Enter move for the name of the field and click Finish 11 Repeat steps 1 11 for the remaining types listed in Table 10 9 4 Viewing Editing and Sharing Library Code Each library in Herbal is represented in its own XML file W3C 2004 While it is not required that Herbal modelers know XML it can be useful for advanced users As a result this section will demonstrate how to view and edit a library s XML code In the previous section you created a new type library called vacu
79. ronment for developing cognitive models in Soar In 4th Behavior Representation in Modeling and Simulation 133 140 University City CA Cohen M A Ritter F E amp Haynes S R 2010 Applying software engineering to agent development AI Magazine 31 2 25 44 Gamma E Helm R Johnson R amp Vlissides J 1995 Design patterns elements of reusable object oriented software Reading MA Addison Wesley Haynes S R Cohen M amp Ritter F E 2009 Designs for explaining intelligent agents International Journal of Human Computer Studies 67 1 99 110 Intro to the Soar Debugger in Java 2005 ThreePenny Software LLC Laird J E amp B C C 2005 The Soar user s manual version 8 6 University of Michigan Lehman J F Laird J E amp Rosenbloom P S 1998 A gentle introduction to Soar An architecture for human cognition In D Scarborough amp S Sternberg Eds Invitation to Cognitive Science Vol 4 New York MIT Press Newell A 1990 Unified Theories of Cognition Cambridge MA Harvard University Press Newell A Yost G R Laird J E Rosenbloom P S amp Altmann E 1991 Formulating the problem space computational model In R F Rashid Ed Carnegie Mellon Computer Science A 25 Year commemorative pp 255 293 Reading MA ACM Press Addison Wesley Russell S amp Norvig P 2003 Artificial Intelligence A Modern Approach 2nd ed Upper Sa
80. ry field 4 Enter eat in the Element Name field and click Finish 5 Repeat steps 1 4 to create an additional operator called drink Operators are similar to if then rules but are more complex as noted in the Psychological Soar Tutorial Laird s tutorial Newell s book etc and contain conditions and actions When the conditions in the operator are true the operator may be chosen by the architecture resulting in the A Gentle Introduction to Herbal 11 execution of actions Because the operators just created eat and drink do not contain conditions or actions yet additional warnings will appear in the Problems view In the upcoming sections these warnings will be resolved as conditions and actions are created and eventually associated with these operators 4 6 Creating Types For Sally to operate in her very simplified world a representation of Sally s world must be created In Herbal the world is represented by a set of data types In this simplified world only a single type is needed to represent Sally s current state of hunger and or thirst To create this data type follow these steps l 2 6 Select the Types tab inside the Herbal GUI Editor Click on the New button located next to the list of existing data types Accept the default value given in the Library field Enter Person in the Element Name field Because this agent does not operate within a simulated environment Sally will not
81. solve her hunger and her thirst without having to create the ResolveHunger or ResolveThirst problem spaces see lines 25 28 in Table 9 You may be wondering why Sally stopped printing Chomp chomp and Slurp slurp after learning Recall that the eat and drink operators perform three actions Two of these actions modify working memory to record the fact that Sally has just eaten or drank and one of these actions prints a message The learning process in Soar only includes actions that alter working memory As a result when the chunks are learned only two of the three actions are included in the chunk the actions that print are included in the learned knowledge rules and are thus not printed Gentle Introduction to Herbal 36 Table 9 Debug Output for a Learning Sally Line Output From the Interactive Debugging Session 1 learn e 2 watch L print 3 step 4 1 0 01 linitialize Survive 5 step 6 2 O O2 impasse ResolveHungerps 7 step 8 3 gt S S2 operator no change 9 step 10 4 l initialize ResolveHunger 11 step 12 ys 4 eat 13 Chomp chomp 14 Building chunk 1 d5 opnochange 1 15 step 16 6 05 l impasse ResolveThirstps 17 step 18 7 gt 5 S3 operator no change 19 step 20 8 O O6 initialize ResolveThirst 21 step 22 9 Ot OT drink 23 Slurp 24 Building chunk 2 d9 opnochange 1 25 step 26 10 0 O8 limp
82. t sure where your project is located on your disk right click ctrl click for the Mac on the Gentle Introduction to Herbal 35 HungryThirsty project listed in the Eclipse Navigator view and choose the properties menu item This will show you the project s properties which includes the complete path to the project folder 3 Select Sally soar and click on the Open button 4 Turn learning on by typing earn e in the command text box near the bottom of the Soar debugger see line 1 in Table 9 5 Instruct the Soar debugger to print chunks as they are created by typing watch L print in the command text box near the bottom of the Soar debugger see line 2 in Table 9 6 Click on the Step button until Sally successfully resolves the first impasse that is encountered ResolveHunger This impasse is resolved by applying the eat operator Immediately after the eat operator is applied and Chomp chomp is printed the debugger will notify you of the creation of a chunk see line 14 in Table 9 7 Click on the Step button until Sally successfully resolves the second impasse that is encountered ResolveThirst This impasse is resolved by applying the drink operator Immediately after the drink operator is applied and Slurp slurp is printed the debugger will notify you of the creation of a chunk see line 24 in Table 9 8 Continue to click on the Step button From this point on Sally will know what to do to re
83. t to the list of current clauses Select add a new fact from the list of choices for the action and then click Finish In the next window select action data type and click Next For this particular action we want to move in a random direction This can be accomplished using the random function Select the move field and click on the Function button Select the rand function and click on the Literal button Type left be sure to include the quotation marks in the Literal field and click on Finish Repeat steps 10 and 11 entering right up and down for the literal values Click Finish and Finish again Creating Vacuum Cleaner Operators Operators can be created to give our vacuum cleaner some tools in which to exhibit behavior In this section you will create two operators randomMove and smartMove The randomMove operator should cause the vacuum cleaner to move in a random direction when there is no nearby dirty square The smartMove operator should cause the vacuum cleaner to move to a nearby dirty square when such a square exists A Gentle Introduction to Herbal 47 Figure 5 illustrates these operators Using what you learned in Section 0 please create the operators shown in Figure 5 Leave the scope of conditions and actions at their default value Operator randomMove Condition Action nmi Operator smartMove Condition Action nearbyDirty moveTobDirt output variable dirtySquare input variab
84. that its conditions will refer to facts whose scope is this problem space and its actions will modify remove or assert new facts in the scope of this problem space However this default scope can be overridden at two levels At the level of the association of the operator to the problem space when an operator is associated to a problems pace the scope of its conditions and the scope of its actions can be overridden At the level of the association of conditions and actions to an operator When a condition or an action is associated to an operator its scope can be overridden This second overriding takes prevalence over the first one This overriding can take three values Top Parent or Local That means that each problem space has the possibility to access facts either in the Top problem space or in its direct parent or in itself Note that in Herbal 3 when an operator is associated to a problem space the first overriding is set to Top by default In addition we should notice that in Herbal 3 the scope of the conditions to enter a sub problem space cannot be overridden Their scope is always the current problem space which is the parent of the new sub problem space That will be illustrated by the example of the multi level vacuum cleaner presented below A Gentle Introduction to Herbal 52 10 1 Creating a multi level Vacuum model In this new lesson we want to improve our vacuum cleaner model When observing t
85. the new problem spaces To assign operators to the ResolveHunger and ResolveThirst problem spaces follow these steps 1 Select the Problem Spaces tab inside the Herbal GUI Editor 2 Select the ResolveHunger problem space in the list of current problem spaces 3 Click the Add button to the left of the current operators list 4 Select the eat operator and click Finish 5 Repeat steps 1 4 to add the drink operator to the ResolveThirst problem space 6 2 Building the Hierarchy Now that the problem spaces are configured correctly they can be assigned to an agent and arranged into a hierarchy The Survive problem space is already assigned to Sally as the top most problem space All that is left to do is assign ResolveHunger and ResolveThirst as children of the Survive problem space In addition the conditions that will be used to activate these child problem spaces need to be specified To add the child problem spaces and specify the appropriate conditions follow these steps 1 Click on the Agents tab in the Herbal GUI Editor 2 Select Sally in the list of current agents A Gentle Introduction to Herbal 26 Select Survive in the list of current problem spaces Click on the button located to the right of the current problem spaces list This allows you to added children to the Survive problem space Select ResolveHunger and click Next Select isHungry in the list of available conditions and click on the button labeled gt gt
86. tion to Herbal 13 14 Repeat steps 7 13 for the isThirsty condition naming the matching instance thirstyPerson 4 88 Creating Actions Creating actions for Sally is perhaps the most involved step in the model creation process The actions Sally will need are shown below in Table 1 Action Name init markHungry markNotHungry markThirsty markNotThirsty printSlurp printChomp Description Table 1 Actions used by Sally Initialize Sally s hungry and thirsty status by creating an instance of the Person data type and setting its hungry field to true and its thirsty field to false Se Se Se Se CS type CS type CS type CS type Prints Prints ne hungry field of a named instance of t o true he hungry field of named instance of t o false he thirsty field of a named instance of o he thirsty field of a named instance of o false Slurp to the console homp to the console To create the actions shown in Table 1 follow these steps 1 Select the Actions tab inside the Herbal GUI Editor 2 Click on the New button located next to the list of existing actions 3 Accept the default value given in the Library field 4 Enter init for the name of the action and click Finish 5 Repeat steps 1 4 to create the remaining actions shown in Table 1 he Person he Person data the Person data the Person data The steps ac
87. tually performed by an action are determined by the action clauses To give our actions some substance we need to add clauses to all seven of the actions shown in Table 1 Starting with the init action follow these steps 1 Select the init action in the list of existing actions 2 Click on the Add button located next to the list of current clauses 6 7 A Gentle Introduction to Herbal 14 The purpose of the init action is to create an initial fact in working memory representing Sally s initial state As a result select Add a new fact from the list of choices for the action and then click Finish In the next window select the type of fact you want to create In this case select the Person data type and click Next We want Sally to start life hungry and not thirsty so we need to set the two fields of the Person data type appropriately Select the hungry field and click on the Literal button This allows you to specify a literal value for the hungry field Enter true and click Finish Repeat step 5 for the thirsty field setting it to false Click on Finish The actions in Table 1 starting with mark are responsible for altering the field values of a named Person fact In other words these actions edit existing named facts To complete the actions follow these steps l 2 3 4 7 Select markHungry action in the list of existing actions Click on the Add button located next to the list
88. um types Consequently Herbal has created a new XML file called vacuum types xml located in the model folder of the VacuumCleaner project To view the contents of this file just double click on it in the Navigation view Even if you are not familiar with XML it is still relatively easy to figure out how the vacuum types xml file is organized Take the time to browse the contents of this file looking for the spot type that was created in Section 0 You should be able to find a section of text that resembles Table 11 Table 11 The Spot Type Represented in XML XML type name spot isIO true gt lt rationale gt lt what gt lt what gt lt how gt lt how gt lt why gt lt why gt lt rationale gt lt field name status type string gt lt type gt m Ee e The code shown in Table 11 is used internally by Herbal to represent the vacuum types spot type In fact users comfortable with XML can create entire models by editing the XML directly instead of using the Herbal GUI Editor To demonstrate how models can be edited using XML complete the following steps A Gentle Introduction to Herbal 41 1 Locate the what section of the XML that represents the vacuum types spot type see line 3 in Table 11 2 Add design rationale by changing line 3 in Table 11 as follows what This type represents the condition of the current square clean or dirty lt what gt 3 Save the file

Download Pdf Manuals

image

Related Search

Related Contents

Samsung SP-50L6HX User Manual  Manuel d`utilisation - Neocoretech Support Website  FLEX INVERTER    Installation and Maintenance Manual for Electric Motors    E:\Publications\User Manuals\P A C\IR Interface\151910_01.vp  Kreiselpumpe Typ FV / NV / ZV / SV / ZHV  etude sur les droits des personnes handicapees au  Macro5627ハードウェア取扱説明書  

Copyright © All rights reserved.
Failed to retrieve file