Home
SOAR Tutorial Part 1
Contents
1. interaction Window Agent blue 03 16 01 Soar Tutorial 39 40 7 Debugging Soar Programs In trying to write the operators in the previous section you may have made some mistakes In this section you will learn techniques for finding and fixing bugs in Soar programs The techniques are separated based on the cause of the error e When the rules for an eater are read into Soar Soar checks to make sure that the rules are legal and displays messages when it finds errors These types of errors are called syntax errors Visual Soar will also check for syntax errors in rules recommend using Visual Soar to check for errors first e f your rules load into Soar without any error messages there can still be mistakes in the underlying logic of the rules These are semantic errors This section starts with a subsection on Syntax Errors Subsections follow this on different techniques for monitoring and examining your program while it is running The last subsection is a walk through of using these techniques to debug a program 7 1 Syntax Errors There are many different types of syntactic errors that you can have in your programs In this section you will get a chance to try to correct the most common types of errors by correcting a file with at least eight different types of errors Missing comment character Missing Missing Extra Missing Missing state Missing Disconnected rhs action variable
2. Since both of these rules test the current operator their actions are persistent The first rule creates an augmentation of the state with attribute Llast direction This augmentation will always contain the direction of the last operator applied by copying the direction from the move operator The next rule removes the last direction attribute if it does not equal the direction on the current operator by using a reject preference These rules will fire during the operator application phase Why can t you use an i supported rule Conceptually you need the 1ast direction augmentation to persist after the operator is no longer selected because it is going to be tested to select and apply the next operator More pragmatically Soar will automatically make the augmentation o supported because it is created as part of an operator application This section and the previous one demonstrate two different ways to create persistent structures in working memory If the structure can persist throughout the life of the eater you can use a rule that tests that the state exists and then creates the structure in working memory in the action Whenever the structure must change during the life of the eater you must use a pair of rules that are part of the application of an operator one to add the structure when appropriate and one to remove the structure when it is no longer appropriate 03 16 01 Soar Tutorial 58 9 3 Advanced Move Operator Proposal
3. as your programs get larger more complex they will contain many more working memory elements A collection of working memory elements that share the same first identifier is called an object For example the three working memory elements that have S1 as their identifier are all part of the state object The working memory elements that make up an object are called augmentations We usually write all of the augmentations of an object together in a list surrounded by parentheses The first item in the list is the identifier that is shared by all of the augmentation followed by the pairs of attributes and values for each augmentation The objects for the above working memory elements are 51 io 11 superstate nil type state Il input link I3 output link I2 An individual augmentation can also be written in this form 51 type state 03 16 01 Soar Tutorial 18 working memory object usually represents something about the world such as an eater a piece food or a cell on the board The individual augmentations represent properties such as color size or weight or relations with other objects such as on top of behind or inside Soar can be used for many different tasks and for each different task working memory will contain descriptions of the task objects If you were writing a program in Soar to control a robot that stacked blocks you might represent the task objects such as a blue block on top of a yel
4. gt lt ol gt m ove direction lt dir gt The final rule removes the move command from the output link when it has completed sp apply move to food remove move state s io output link lt ol gt operator name move to food lt ol gt move lt move gt lt move gt status complete gt lt ol gt move move 03 16 01 Soar Tutorial 38 6 3 Shortcuts and Extensions The rules propose move to normalfood and propose move to bonusfood differ only in the tests for normalfood and bonus food Instead of writing an individual rule for each of those values it is possible to write a single rule that tests for any one of a set of alternative values The alternative values are written in the same position as a single value but are surrounded by double angle brackets normalfood bonusfood Any number of different values can be included but none of them can be a variable Using this notation the two rules can be rewritten as the following rule Sp propose move to food state s io input link my location dir content lt lt normalfood bonusfood gt gt gt lt s gt operator o Make sure there is a space lt o gt name move between the lt lt gt gt and the values direction lt dir gt This notation can also be used for testing alternative values of attributes Soar supports another shortcut similar in spirit to dot notation that allows you to elimina
5. 1 1 Installing Eaters and Soar Before reading the tutorial you should install Soar and its associated software on your computer so that you can run the examples and exercises Using your favorite browser visit the Soar Tutorial page http ai eecs umich edu soar tutorial html Follow the link to the Eater tutorial and follow the directions on that page for installation 03 16 01 Soar Tutorial 1 2 Creating an Eater Start the Eaters game by double clicking on the Eaters icon in the folder where you installed Eaters After Eaters has started you will have two new windows on your computer screen One of the windows is the Eaters Playing Board that was shown on page 5 The second window is the Eaters Control Panel which is shown below You will use this window to create and destroyer eaters and run the game Eaters are controlled by Soar programs which are automatically loaded when the eater is created The first step in creating an eater is to select the path to a folder directory on your computers that contains files of Soar programs for controlling eaters To select the path click and hold your mouse on the button to the right of the word Path which is highlighted in the figure below If you have two button mouse always click with the left mouse button unless explicitly told to click with the right Click on this to select the folder 03 16 01 Soar Tutorial When you click the button a menu possible pa
6. From apply move to food This tells you that apply move to food creates this working memory element If you want to find out what working memory elements matched apply move to food when it created I3 move m3 you can type red preferences I3 move wmes Preferences for I3 move acceptables M3 From apply move to food 212 S1 operator 08 205 O8 name move to food 206 08 direction north 3 ST ro Il 5 11 output link 13 You can also invoke preferences by clicking with the right mouse button on an attribute of a working memory element in the interaction window Select the preferences command from the menu that appears and then select the appropriate preferences command 03 16 01 Soar Tutorial 47 7 4 Monitoring Soar also has some automated monitoring mechanisms that can be invoked through the View item on the Interaction Window bar After clicking on this item a menu will appear that allows you to enable the monitoring of the state stack print stack the current set of productions about to fire match set or the preferences that have been created for the selection of the current operator Op preferences The first of these print stack is not very useful for the eaters because they do not use Soar s subgoaling but it will be useful for TankSoar in the next part of the tutorial Interaction Window Agent red The match set window will continually display all rules that currently match working memory a
7. Our planned extension to the move operator does not require any changes to the existing application rules However you must add two rules to maintain a memory of the last direction moved One of the rules must create the memory by adding the persistent o supported structure when an operator is applied and one must remove the old value when the next operator is selected You may think that you could write a single rule that both creates the last direction and removes any old value for last direction but then a second rule would have to be written to cover the initial situation when there is no existing last direction Try to write the English and Soar versions of these two rules Apply move create last direction If the move operator for a direction is selected create an augmentation called last direction with that direction sp apply move create last direction state s operator lt o gt lt o gt name move direction lt direction gt lt s gt last direction lt direction gt Apply move remove last direction If the move operator for a direction is selected and the last direction is not equal to that direction then remove the last direction sp apply move remove last direction state s operator o last direction lt direction gt lt gt direction lt gt direction name move lt 5 gt last direction direction
8. There are two ways to modify the proposal and selection rules so that the eater does not move backward One requires modifying the proposal rule so that the operator is never proposed and the second is to create a new selection rule that creates a preference that prevents the operator from being selected We will look at both possibilities In order to modify the proposal rule recall the final move proposal Propose move If the content of an adjacent cell is not a wall propose move in the direction of that cell with the cell s content and indicate that this operator can be selected randomly A condition can easily be added that tests that the direction of the adjacent cell lt d gt is not equal to the opposite of the direction of the last move However this will not work for the first move when there is no direction for the last move because no operator has applied to create the memory of a previous move An alternative is test that there does not exist an opposite of last direction that is equal to the direction of the adjacent cell How is that different The first tests that there does exist in working memory an augmentation of the state but its value is not equal The second tests that there does not exist in working memory an augmentation that is equal The second one will be correct for the first move Thus the revised English description is Propose move no backward If there is normalfood bonusfood eater or em
9. and take another step Now the eater moves and runs appropriately 03 16 01 Soar Tutorial 49 8 Generalized Move Operator The move to food operator you created in the last section would get stuck when there was no food in the cells adjacent to the eater It also did not prefer bonusfood to normalfood In this section you will generalize the move to food operator to be an operator that can move to a cell with any type of content Once you have created such a generalized move operator we will introduce additional preferences that allow you to create a greedy eater that never gets stuck 8 1 Move Operator Proposal The proposal for the move operator needs to test that there is an adjacent square that it can move into It should not propose moving into a wall There are two possible approaches to write this test The first is to test all of the content values that are ok to move into normalfood bonusfood eater or empty The second is to test that the content does not equal wall Taking the first approach gives us the following English version of the proposal 1 If there is normalfood bonusfood eater or empty in an adjacent cell propose move in the direction of that cell and indicate that this operator can be selected randomly It is straightforward to translate this into Soar based on the move to food operator proposal sp propose move l state s io input link my location dir content
10. elements Persistence is necessary for creating memories of prior events such as the memory of something sensed in the environment For example if an eater needed to remember the location of uneaten food so that it could return to it later the eater would have to create a persistent structure in its working memory Otherwise as soon as it stopped sensing the food it would forget about it In Soar all working memory elements created by an operator application rule are persistent A rule is an operator application rule if it tests a selected operator and modifies the state Persistent working memory elements are said to be operator supported or o supported because they are created by operators For example apply move north is an operator application rule and creates o supported working memory elements sp apply move north state s operator name move north Tests selected operator io output link lt ol gt lt ol gt move direction north Actions are o supported Just as it is important to have persistent memories it is also important to have structures that are removed automatically when the reason for creating them goes away Actions of rules that test only the state or that test the operator and elaborate only the operator create non persistent preferences or working memory elements Obvious examples of non persistent structures are the preferences for operators These are created by operator proposal rules which retract th
11. lt lt empty normalfood bonusfood eater gt gt gt lt s gt operator lt o gt lt o gt name move direction lt dir gt Although this is adequate it will make future selection rules simpler if the operator also contains the contents of the cell Thus an alternative version is Propose move la If there is normalfood bonusfood eater or empty in an adjacent cell propose move in the direction of that cell with the cell s content and indicate that this operator can be selected randomly To translate this into Soar requires matching the cell s content to a variable and then using that variable in the action as an augmentation of the operator such as content content However the value is already matched by lt lt empty normalfood bonusfood eater gt gt What is needed is a way to match both a variable and the list at the same time In Soar this is done by surrounding the two or more things to match against the same item with curly braces Thus the Soar version of the proposal becomes sp propose move la state s io input link my location dir content content lt lt empty normalfood bonusfood eater gt gt lt s gt operator o lt o gt name move direction dir surround multiple tests for same value content lt content gt 03 16 01 Soar Tutorial 50 Although this rule is adequate it forces you to list all of the con
12. 7 m 1 dir d 1 gt gt gt gt d 1 contant lt lt normalfood bonusfood gt gt c 1 0 complete matches There is a problem with the last condition You can examine working memory to find out what it should be matching and after some examination you should realize that the name of the attribute should be content not contant Change the rule in the file If you have been using Visual Soar it would have found this error while you were creating the Eater To avoid destroying and creating a new eater you can just reload the rules by clicking on the agent button in the menu bar of the Interaction Window This will bring up a list of active eaters and you can select your eater and then select the reload button Now you can try going one step again You should have the following in your interaction window red 0 gt S S1 1 01 move to food At this point you can check which rules are about to fire by using the matches command red gt matches O Assertions apply move to food I Assertions Retractions That looks fine so take one more step Unfortunately the eater doesn t move What s the problem You should examine the output link to see if the move command was correctly created red print depth 2 i3 moves M1 1 direction east Unfortunately you have to inspect this structure and realize that the command it creates is moves not move Correct this reload
13. above and then rerun it This time we are going to increase the tracing so that we can see the individual changes to working memory To do this either type watch wmes in the Interaction Window or click on the watch menu at the top of the interaction window and select 4 WMEs You should also trace the production firings The figure below shows the end of the trace The trace is long because it includes the addition and removal of all of the sensory data that changes during a move not shown below In the trace an addition to working memory is shown preceded by an gt while a removal from working memory is preceded by lt Each working memory element also contains a number such as 153 for the top element in the trace below This is the timetag of the working memory element a unique number generated when a working element is created Soar sometimes displays only timetags instead of the full working memory element and the timetag can be used in the print and wmes commands for displaying the full working memory element more details later Windin Agent med 153 status complete Firing proposes meve north Retracting propose move north 155 51 operator 02 154 02 nome move north WM 121 El 01 Remove from working memory 122 25 Q1 Timetags 2 0 02 mave
14. but you should always pick a name that is meaningful Following the name there must be at least one condition A condition tests for the existence or absence of some data in working memory If all of the conditions match then the rule will fire and all of the actions are performed Most actions create new structures in working memory Some actions remove structures from working memory and some actions perform other functions such as writing text to the screen or halting as in hello world In the next several sections we will explore the structure of conditions and actions and explain what all of the special symbols such as s and type mean Before doing that we need to first look at the structure of working memory in more detail 03 16 01 Soar Tutorial 17 2 3 Working Memory Working memory contains all of a Soar entity s dynamic information about its world and its internal reasoning It contains data from sensors intermediate calculations current operators and goals Soar organizes this information as states with all data being associated with a state For the eaters you will build there will be a single state and all information will be connected directly or indirectly to the state Below is a graphic picture of the part of working memory every Soar entity starts with nil State identifier State attributes State value state Working memory is a graph structure with nodes such as 51 11 12 13 nil and state
15. contents of both the north and south cells for use in the action you could use the following conditions state s io input link my location lt my loc gt my loc north content north south content south lt gt north Remember the not equal test lt gt must directly precede the symbol or variable it refers to Soar also has tests for greater than gt less than lt greater than or equal to gt and less than or equal to lt These can be used when matching numbers and also precede the value they refer to For example to test that the eater s score is greater than 25 the following condition can be used state s io input link eater score 25 03 16 01 Soar Tutorial 51 8 2 Move Operator Application This application rule for the move operator is a copy of the move to food operator application The English and Soar versions are the same except for the name of the operator Apply move If the move operator for a direction is selected generate an output command to move in that direction sp apply move state s io output link lt ol gt operator lt gt lt o gt name move direction lt dir gt gt lt ol gt move direction lt dir gt Apply move remove move If the move operator is selected and there is a completed move command on the output link then remove that command sp apply move remove mov state s io
16. in a direction does not contain a wall This is easy to add because every cell has the same four directional pointers so the desired cell can be tested via the direction augmentation on the adjacent cell instead of just lt dir gt use lt dir gt lt dir gt which tests two steps in the same direction because the same directional pointer must match both uses of lt dir gt In these examples we will use the proposal that does not test for the absence of backward moves We will include that in the selection knowledge Thus the English version is f Propose jump If the content of a cell two steps away in a direction is not a wall propose jump in the direction of that cell with the cell s content and indicate that this operator can be selected randomly sp propose jump state s io input link my location dir dir content content lt gt wall gt lt s gt operator lt o gt The first lt dir gt leads The second lt dir gt leads to a lt o gt name jump an adiacent cell cell two away from the eater direction lt dir gt content lt content gt in the same direction 03 16 01 Soar Tutorial 61 10 2 Jump Operator Application The application of jump is exactly the same as the application of move except that the jump name must be issued instead of a move Instead of creating a new rule for each operator you can reuse and generalize the original operat
17. its name its current score and its x y coordinates The second my 1ocation has additional substructure not shown that includes the eater s sensing of nearby cells Some of the eater information changes during the game e The x location will change when the eater moves east or west e They location will change when the eater moves north or south Thus whenever the eater moves either the x or y location will change We can modify the conditions of our proposal rule to test both of these working memory elements and eliminate the test for type state Sp propose move north state s io input link eater lt gt gt which changes after each move lt s gt operator o lt o gt name move north 03 16 01 Soar Tutorial 29 What will happen First when the original working memory elements for x are removed from working memory the original move north operator will be removed from working memory because the rule instantiation that created it no longer matches some of the working memory elements responsible for the match are gone We call this retracting the rule firing Rules such as propose move north maintain their actions in working memory only as long as they match exactly the same working memory elements Second a new instance of the move north operator will be created because propose move north will match the new values of x and y and fire To see these changes modify your move north operator as
18. know the basic structure of rules and operators in Soar You should be able to create your own eaters that print out simple messages with operators Although you haven t gotten the eater to move you have come a long way 9 input li typ state 03 16 01 Soar Tutorial 24 4 Move North Operator The first real operator you will create moves an eater north one step It might not even do that if there is a wall to its north when it is created The first step in creating an operator is to write down the proposal and application rules in English Not only will this force you to think through many of the details of the operator before you worry about how to write it in Soar but the English rules can be used as documentation for the Soar rules As mentioned on page 19 you can use either Visual Soar or a text editor to write your rules Type the English versions of the proposal and application rules for the operator move north We want these versions to be documentation so we have to tell Soar to ignore them You can do this by starting each line with the pound sign Soar ignores lines that start with a pound sign In Soar the name of the rule can be almost any string of characters but it is a good idea for it to be a meaningful summary of the purpose of the rule A useful convention is to split the name into parts separated by asterisks The first part is the task the second part is the function propos
19. narth Firing apply move north 158 M2 direction north 157 I3 move M2 164 52 quiescancae t WM 163 52 choices nons MWH 162 52 impasse no change 161 52 attribute operator MWM 160 52 superstate 51 159 52 type state 2 225 52 operator no change p 13 nave wove MZe structures are ot removed redy You will notice that your eater still doesn t move more than once even though a second move north operator is selected and a second move command is created The reason is that the original move command 13 move m1 is not removed and Eaters must have only a single move command if it is to move an eater The move command is not removed because it is the action of an operator application rule Such actions are not automatically removed when the rule no longer matches 03 16 01 Soar Tutorial 30 5 2 Operator Application Persistence As noted above proposing and selecting a second operator does not make the eater move a second time because the first move command is not removed from working memory Even if Eaters was more flexible the accumulation of more and more move commands is a problem Why aren t these commands automatically removed like the preferences for operators The reason is that the rule that creates them is part of the application of an operator and operator applications create persistent working memory
20. ol gt att value With these rules included in an Eater both the move and the jump operator require only proposals except when other actions are performed such as remembering prior moves To use both of these rules you need to modify the proposal rules so that they create the actions structure Below is an example of the jump operator proposal sp propose jump state s io input link my location dir dir content content lt gt wall gt lt s gt operator o Replaced direction lt o gt name jump lt dir gt with this actions jump direction lt dir gt content lt content gt Rules like this simplify the writing of Soar programs by creating conventions however these conventions also restrict what can be written in a Soar program For example if this rule is used in a Soar program then the status complete augmentation will always be removed and will not be available for other rules to test For this domain it doesn t seem like that will be a problem and it might not be for others as well It is just that before creating a rule that applies to all operators you should be careful Throughout this tutorial you will see additional rules that are used to simplify the writing of programs We have tried to be careful in selecting these types of rules 03 16 01 Soar Tutorial 63 10 4 Jump Operator Selection There are many strategies for selecting jump operators On
21. section you will use the techniques from the prior section to fix semantic errors In a rule based system semantic errors have three general results 1 A rule does not fire when it should 2 Arule fires when it shouldn t 3 The action of the rule is incorrect Unfortunately when you have an error you don t know which type it is Luckily there are general techniques for finding all types of semantic errors The first and most important step in finding semantic errors is knowing what you want the program to do at each step Only by knowing what the program should do will you be able to detect when it does something wrong Usually you will notice that the wrong operator is selected or that no operator is selected a substate is created l ve created a file called semantic error soar in the Tutorial directory for move to food that has some bugs Create an eater with this file and also open the file in a text editor so you can modify as we go along You should expect that propose move to food to fire during the first step so be bold and click on the step button and see what happens You should get a trace like red 0 gt S S1 T3 gt 5 S2 state no change This clearly indicates that propose move to food did not fire To find out why try matches propose move to food red matches propose move to food 1 state s io lt 1 1 gt 1 1 input link lt i 2 gt 1 i 2 my location lt m 1 gt
22. the rule To determine if the conditions are true Soar compares them to statements held in working memory Working memory defines the current situation which for an eater consists of its perception of its world results of intermediate calculations active goals and operators To see what the hello world rule does start up Eaters select the hello world rule file and create an eater Don t immediately click on run because you will not see a trace of the rule firing You must modify the level of tracing to see rule firings by typing the following into the Interaction Window followed by the Enter key Only type in the underlined part raction Window contains a trace of the hello red watch productions on Now click on the step button What happened The I world rule firing followed by the printing of Hello Interaction Window Agent red red Firing hellao warld T Hella World System halted Message printed by rule firing H Step Run Sop a Message Soar prints after halt Based on hello world you should be able to come up with English descriptions of rules that write out messages Note If you click on the run button Eaters will try to keep running even after Soar halts Eaters keeps running because there might be other eaters and it shouldn t stop just because of them halts Click on Stop to halt Eaters 03 16 01 Soar Tutorial 16 2 2 Hello World Rule Soar As stated earli
23. to say that a single value is as good or as bad a choice as other expected alternatives Indifferent preferences are used to signal that it does not matter which operator is selected which results in a random selection is made from among the alternatives 03 16 01 Soar Tutorial 8 5 The following trace shows how Soar fires and retracts many rules in parallel with operator proposals following selections Interaction Window Agent blue 03 16 01 Soar Tutorial 55 56 9 Advanced Move Operator The eater you created in the last section will greedily consume food and never get stuck However its behavior doesn t always appear to be very intelligent especially if it is surrounded by empty cells The specific problem addressed in this section is that the eater will sometimes move randomly back and forth when it is surrounded by empty cells That is clearly wasted effort and the eater should at least move to a cell different from the one it just came from There are other approaches to improving the eater such as having it test for food two spaces away but the point of this section is to avoid moving back to the same cell which will give you experience with creating persistent structures in working memory In order for the eater to avoid moving back to the cell it just came from the eater must remember which direction it moved to get to the current cell That information is available as an augmentatio
24. 01 gq means an acceptable re preference for an operator Step Run Siop eo You now see all of the attributes and values that have 51 as their identifier The attributes superstate and type are created automatically for the state when the program starts to run The operator attribute is created when the hello world operator o1 is selected Only the selected operator has a working memory element such as this withoutthe following In addition to the selected operator the acceptable preference for the operator is there marked with the If there were additional operators proposed with acceptable preferences there would be additional working memory elements with the operator attribute with the ids of the operators followed by the but for a given state there is only one working memory element with the operator attribute without the which signifies the selected operator The attributes are ordered alphabetically when they are printed but that is just to make it easier to find a specific attribute We can examine more of the structure of o1 using the print command This time type The letter p means print Almost all commands in Soar also have one or two character shortcuts Interaction Window Agen med File Shea May Productions Watch Monitor Commands 0 35 5 0 01 hello world Hella World System balted red S1 type state suparstate nil io 1 cparato
25. In Eaters PACMAN like eaters compete to consume food in a simple grid world Below is the Eaters Playing Board near the beginning of a game with four eaters Eaters Playing Board The Eaters world consists of a rectangular grid 15 squares wide by 15 squares high Walls bound all four sides Interior wall sections are randomly generated for each new game No two walls will touch so there are no corners except for exterior walls and no dead ends anywhere on the board Each eater starts at a random location Food pellets are in all other squares of the grid There are two kinds of food normal food blue circles and worth 5 points and bonus food red stars and worth 10 points An eater consumes food by moving into a square When an eater moves out of a square it will be empty unless another eater moves into it An eater can sense the contents of cells eater normal food bonus food and empty up to 2 squares away in all directions On each turn an eater can move one square north south east or west An eater can also jump two squares north south east or west An eater can jump over a wall or another eater An eater does not consume any food in the space it jumps over A jump costs the eater 5 points Whenever two eaters try to occupy the same cell at the same time they collide As a result of the collision their scores are averaged and they are teleported to new random locations on the board 03 16 01 Soar Tutorial
26. Selection The alternative to modifying the proposal rule is to add a rule that eliminates from consideration any operator that moves opposite to the last direction This requires a new preference called reject represented by a dash This is different from the operator application action that is also called rejection because that rejection removes a working memory element When a reject preference is created for an operator the decision procedure will not select that operator no matter which other preferences have been created However the reject preference will be retracted when the rule that creates it no longer fires allowing the rejected operator to be selected when the situation changes Reject is used when an operator should not be selected for the current situation even if there are no other options In contrast a worst preference is used when an operator can be selected but only if there are no better options One side effect of reject is that it disables better worse preferences where the rejected operator is better than some other operator Normally that other operator would not be selected but if the better operator is rejected the better worse preference is ignored Try writing both English and Soar versions of this rule Select move reject backward If there is a proposed operator to move in the direction opposite the last move reject that operator sp select move reject backward state lt s gt op
27. The Soar 8 Tutorial John E Laird University of Michigan February 23 2001 This tutorial is the culmination of work by many people Eaters was developed by Randy Jones and then refined and updated by Scott Wallace Mazin As Sanie developed TankSoar based on Tag Soar which was originally developed by Mike van Lent Soar 8 is based changes to Soar 7 suggested by Bob Wray s thesis work but also includes changes to the decision cycle suggested by Randy Jones and refined by Bob Wray Karen Coulter and Mike van Lent Karen Coulter brought all of the pieces of Soar 7 and Soar 8 together and is responsible for the final integration and release of the Soar 8 code Brad Jones developed visual Soar Jessica Laird tested the tutorial and pointed out ambiguities and complexities in earlier versions 03 16 01 Soar Tutorial Introduction This is a guide for learning to create software entities in Soar version 8 It assumes no prior knowledge of Soar or computer programming The goals of this document are e Introduce you to the basic operating principles of Soar e Teach you how to run Soar programs and understand what they do e Teach you how to write your own Soar programs This tutorial takes the form of a sequence of lessons Each lesson introduces concepts one by one and gives you a chance to use them creating Soar entities Each lesson builds on the previous ones so it is important to go through them in order To make the best use of this tut
28. Unfortunately Soar does not give very good error messages so it is often hard to figure out what the problem is We are working on improving this ONOOARWNH gt To start open up the syntax error soar file in the tutorial bugs folder This has the move operator from the previous section but with many errors You will make corrections to the syntax error soar file until it loads in with no errors Next start up Eaters and select the tutorial bugs folder Then try to create a syntax error eater When you do you will immediately get a pop up error window Couldn t lond agent code for syntax error mwalid command name wall EY Somewhere early in the file Soar ran across the word will when it was looking for production rules starting with sp You will get a similar error whenever there are words in your file that are not preceded by the comment character or are not legal Soar commands like or watch Correct this error by adding before will 03 16 01 Soar Tutorial 41 To continue click ok to the pop up window delete the eater and try to create it again You will now get pop up error window and a message in the interaction window CET Interaction Window Agent ned E Once again Soar has been unable to find a legal command in this case it can t find sp because the is missing Unfortunately Soar does not provide a helpful error message the prob
29. World halt Once you have modified these rules for move north make sure you save move north soar as a text file with linefeeds Turn the page and compare your rules to the ones that wrote 03 16 01 Soar Tutorial 26 4 2 Soar Version Below is the proposal rule wrote The proposal rule is exactly the same as the proposal rule for hello world except that the names of the rule and the operator are changed sp propose move north Replaced hello world with move north state s type state gt lt s gt operator o lt o gt name move north The rule that applies the operator has more differences Its action is to add a move command to the output link This command will cause the eater to move one cell to the north In order to add the command to the output link the rule must match the output link identifier in its conditions with a variable Therefore conditions are included that match the io io object and then the output link o1 sp apply move north state lt s gt operator lt o gt io must be matched to get to the output link io io x TTE output link gives path to identifier for actio lt io gt output link lt ol gt p 3 P i lt o gt name move north Add action to output link to move north lt ol gt move move lt move gt direction north The exact order of the conditions and actions does not matter except that the first c
30. alfood normalfood bonusfood normalfood east east east east west west west input link O narth normalfood EE 27 normalfood normalfood normalfood E Mim x Walco bel 5 Store x5 000 Boog EOD 03 16 01 Soar Tutorial 6 2 Soar Version Below is the proposal rule 37 wrote without dot notation so that it is clear which working memory elements are being matched The proposal rule tests a sequence of linked identifier attribute values and includes a variable for the attribute that leads to an adjacent cell The variable will match north east south or west if the final condition matches an adjacent cell containing has content normal food sp propose move to normalfood state lt s gt inpu io lt io gt t link input link Matches any attribute input lin k gt my location lt m my loc lt direction gt S lt p lt cell gt cont nt normal 009 matches cell with normalfood gt lt s gt operator lt o gt Hy sant indiferenirandon lt 5 gt operator o lt o gt name move to food Use matched direction in direction lt directi il The indifferent preference tells Soar that a random selection can be made between proposed operators The direction in the action augments the operator with the direction of an adjacent cell containing normalfood When an eate
31. although it will be larger and have additional panes Across the top are a series of pull down menus which are described later The main body of the window is where you can type in commands and where trace and debugging information will be displayed The bottom of the window contains buttons for single stepping running or stopping the eater There is also a search button that creates a pop up window for searching through the trace and debugging information lnterection Window Agen red File Slee Beney Productions Watch Monitor Commands Help red Sc The eater is referred to by its color which is listed in the window title Agent red and in the prompt in the interaction window red gt The s in the window following the red prompt are printed for the individual rules that are successfully loaded into the eater In Soar a program consists of rules and move to food has only three simple rules that move the eater to a neighboring cell that contains food As your eaters get more sophisticated more rules will be loaded The Eaters Info window is the other window created This window contains information about your eater such as its current score the number of moves it has taken and a graphical depiction of its sensory data The number of steps taken by eaters since the map was initialized The eater s current score The number of moves made by the eater The current sensor data for the eater empty
32. alue does not have an acceptable preference or is rejected the better worse preference is ignored Otherwise the worse value is removed from consideration Better and worse are simple inverses of each other so that A better than B is equivalent to B worse than A e Best gt A best preference states that the value should be selected if it is not rejected or if there is no other value better than it If a value is best and not rejected or worse than another it will be selected over any other value that is not also best If two values are best then the remaining preferences worst indifferent will be examined to determine the selection If a value that is not rejected is better than a best value the better value will be selected This result is counter intuitive but allows explicit knowledge about the relative worth of two values to dominate knowledge of only a single value e Worst lt A worst preference states that the value should be selected only if there are alternatives A worst will only be considered if the above preferences have not filtered the choices to a single choice In this case any value with a worst preference will be discarded unless all of the values have worst preferences e Indifferent An indifferent preference states that there is positive knowledge that it does not matter which value is selected This may be a binary preference to say that two values are mutually indifferent or a unary preference
33. and an operator will not be selected if it does not have an acceptable preference Input link representation The input link has two augmentations eater and my location Remember that the value of the my location augmentation is the eater s current position and is a cell in middle of the 5x5 Eaters Info sensory field On the next page there is a graphic depiction of this cell and all of the other cells in the sensory field Adjacent cells are augmentations labeled north east south and west Every cell also has a content augmentation whose value can be wall empty eater normalfood bonusfood If the cell has an eater in it there will be additional augmentations not shown in the figure for the color of the eater eater color and the eater s current score eater score Below the figure for the input link structure is the corresponding Eaters Info window Based on the information in those figures you should try to write a Soar rule for propose move to normalfood Two hints T 2 Write down the sequence of attributes that go from the state to the value of the content of a cell separating each attribute with a Use a variable to match the direction augmentations to a neighboring cell and then test that the content is normalfood That variable in the attribute position will match any direction augmentation between cell north east south Or west You can write it variable 03 16 01 Soar Tutorial 36 wall norm
34. arts Part uses a Pacman like game called Eaters to introduce the basic concepts of Soar After working through Part you should be able to write simple Soar programs Part II uses a grid based tank game called Tank Soar Part II concentrates on Soar s subgoaling mechanism as it is used for task decomposition Part uses the Water Jug and Missionaries and Cannibals problems to introduce internal problem solving and search Part IV uses the same tasks as Part to introduce look ahead planning and learning Part V covers the Soar system that plays Quake ll The software for Part V will be available soon Soar has its own editor called Visual Soar which is highly recommended for used in developing Soar programs Visual Soar is available from the Soar homepage To get a more abstract overview of Soar and the associated research issues you should read A Gentle Introduction to Soar To get more details on the exact operation of Soar you should read The Soar Manual The manual is available on our web site at http ai eecs umich edu soar docs html and we would be happy to send the other paper to you 03 16 01 Soar Tutorial 03 1 6 01 Soar Tutorial Part Simple Soar Programs Throughout this tutorial you will be writing and running Soar programs for simple games In this part the programs are simple and do not use Soar subgoaling or learning mechanisms 1 The Eaters Game The game used in this part is called Eaters
35. asier to create a structure in working memory with the information and have a general rule match against it and do the translation This is similar to the way opposite directions were computed The first rule to write is the one that creates the structure in working memory It needs to include an object for each pair of name and content and for each pair the expected value to the eater sp init elaborate name content valu state s type state gt lt s gt name content value cl c2 c3 c4 c5 c6 cT lt c8 gt lt cl gt name move content empty value 0 lt c2 gt name move content eater value 0 lt c3 gt name move content normalfood value 5 lt c4 gt name move content bonusfood value 10 lt c5 gt name jump content empty value 5 lt c6 gt name jump content eater value 5 lt c7 gt name jump content normalfood value 0 lt c8 gt name jump content bonusfood value 5 To compare two operators you can write a rule that matches the operators and the name content value structure but it is easier to understand the reasoning if you break it into two rules The first rule matches each operator and the appropriate name content value and copies the value onto the operator sp elaborate operator value state s operator o name content value lt ccv gt lt o gt name lt
36. because the eater hasn t started 03 16 01 Soar Tutorial 1 3 Running an Eater Your eater is now ready to start eating Click the Run button on either the Eater Control Panel highlighted below or the Interaction Window The eater will start to move and consume food After a few moves click the Stop button on either the Eater Control Panel highlighted below or the Interaction Window At this point the Eaters Playing Board will look something like the one below Your board will look different because the walls and eater starting position are different each time the game is played pE o B BEHEE a a u hs Hg Row H y ow S H 44 d w 5 H E E KGG H 9 u HEH Bo H ub mw Ho fF aa el lo el 03 16 01 Soar Tutorial 11 During the run the Eaters Info window will change with each move showing the food pellets walls and empty squares that the eater senses As shown below an eater can sense a 5x5 grid of cells although the move to food eater only looks at the four neighboring cells Eqaler Decision 0 is creation of th
37. cceptable preference for the operator which is written in the condition as the operator augmentation of the state with a value for the operator identifier followed by a plus sign state lt s gt operator lt ol gt Acceptable preferences are the only preferences that are added to working memory All of the other preferences better best worse worst and reject are not added to working memory They are held in preference memory and persist as long as the rule instantiations that created them still match They are not in working memory because there is little advantage to having them available for other rules to match against whereas the acceptable preferences must be in working memory because they define what operators are candidates for selection An operator can be preferred by creating a better than preference and the decision procedure will use that preference in determining which operator to select it will never select an operator if it is worse than another candidate operator unless that candidate is rejected In addition to the better preference there is a worse preference that is exactly the opposite In an action the better preference is the greater than sign gt It is used in the same place as an acceptable or indifferent preference except that a variable that matched the identifier of the better operator is put before the greater than sign and the variable that matched the identifier of the worse operato
38. condition to write would be 51 type state However s1 is just an arbitrary symbol and might not be the identifier of that state every time the eater is Thus we need a test that there is an identifier but without testing a specific value That is exactly what a variable does it matches any symbol in working memory with the only constraint being that all occurrences of it in a rule match the same symbol A variable is a symbol surrounded by lt and gt such as s The exact symbol used in the variable such as s is irrelevant but should be picked to be meaningful to its use Putting these pieces together gives lt s gt type state That is almost correct but in Soar every rule must start by matching a state and to remind you of this the first condition of every rule must start with the word state A variable that matches any identifier in this position ne CREAR aio This condition tests that there is a state starts with state state s type statej4 amp Vertical bars surround text Prints the following items write Hello World to the Interaction Window halt Halts the eater The original text for the rule s actions was then write Hello World and halt The rule s first action prints Hello World in the Interaction Window Vertical bars mark constants with special characters These constants can contain any characters and allow you to pri
39. connected by links such as superstate io type output link and input link Soar has two kinds of nodes identifiers and constants The nodes that can have links emanating from them such as 1 are called identifiers while the others such as state and ni1 are constants In the example above s1 is the identifier for the state Identifiers are always created automatically by Soar and consist of a single letter followed by a number The case of the letter does not matter so 1 or s1 mean the same thing Although I2 and 13 do not have any links emanating from them they can in the future and are identifiers In contrast the symbol state is not an identifier and cannot have links emanating from it The links are called attributes and are always prefaced by an Only identifiers can have attributes S1 has three attributes superstate io and type I1 has two output link and input link The graph can be thought of as consisting of a set of triples where each triple is an identifier an attribute and value and where the value is that node pointed to by the attribute In the example above the symbols nil 11 state I2 and are all values of various attributes Each of these identifier attribute value triples is a working memory element There are five working memory elements in the figure above 1 superstate nil 1 io 11 51 type state 11 output link I2 11 input link This is the minimal contents of working memory
40. ctions n e s lt w gt value north opposite south lt gt value east opposite west s value south opposite north lt w gt value west opposite east This is the first rule you ve seen where there is an action with multiple values lt n gt lt e gt lt s gt lt w gt fora single attribute direction Each value can be written as individual actions however as a shortcut all of the values can be listed following their common attribute One might be tempted to have the values of direction be the symbols north east south and west However these values cannot be further augmented with their opposites only identifiers can have augmentations It is not legal to have augmentations of the form north opposite south Rules such as initialize state directions are quite common in Soar program because they create fixed working memory structures These structures simplify operators by making it possible to directly match relations such as opposite instead of having to write rules that are specific to each of the directions This rule will fire during the first cycle when s1 type state is added to working memory The structures it creates will have i support because the rule conditions do not test an operator However the structures will never be removed because the conditions match throughout the life of the eater 03 16 01 Soar Tutorial 57 9 2 Advanced Move Operator Application
41. d augmentation of the move object called speed which is irrelevant in Eaters you do not want to do the following gt lt ol gt move direction north move speed fast This is equivalent to gt lt ol gt move lt movel gt move lt move2 gt lt movel gt speed fast lt move2 gt direction north These actions will create two move augmentations on the output link each with a single attribute The correct action is gt lt ol gt move lt move gt lt move gt speed fast direction north 03 16 01 Soar Tutorial 28 5 Move North Operator Multiple Moves Although the move north operator did move one step north the eater never takes a second step In this section you are going to find out why it takes only one step and modify the eater so that it can take multiple steps This is one of the most complex sections of the tutorial so study it carefully 5 1 Operator Selection Multiple Instances In Soar each action in the world such as moving an eater should be performed by a separate operator instance An operator instance is a separate operator in working memory element created by the firing of an operator proposal rule Thus each action should test for the creation of a new operator object in working memory Different instances of the same operator will have the same name and sometimes will have the same augmentations but a given instance will be used for only one move Some operator in
42. e state 1 Operator selections Scroll bar The line starting with 0 gt shows the creation of the first state This is followed by successive selections of move to food operators The move to food operator causes the eater to move to a new Cell Some of the eaters will also jump others will halt when they cannot sense any food If the trace gets longer than the window can hold the printing will scroll up You can look at decisions that scroll off the window by using the scroll bar at the far right of the window You can search for information in the trace by using the search function at the lower right hand corner of the Interaction Window 03 16 01 Soar Tutorial 12 If you let the eater run for long time it will eventually get to place where there is food directly next to it The move to food eater does not have any rules to respond to this situation although you could easily add so the eater will stop moving The trace will look as follows llerection Window Agent ned When eater does know how to respond to a situation it will start generating new states such as 52 S3 S4 in the above trace above In later sections of the tutorial you will learn how to write rules that take advantage of these new states but for now you just need to know that when they arise the eater does not know what to do At anytime you can create more eaters You can create additional eaters f
43. e apply elaborate and the third is the name of the operator There may be additional parts for more details of what the rule does In the tutorial so far there is really no task so you should name your rules just with function operator name Even if you don t think you know what you are doing it is worthwhile to take the time to write something before you turn the page and look at our example A good idea is to copy as much as you can from what we ve already done so it would be a good time to look back at the hello world operator To save you some time here is how the English version of hello world might appear in a file TREE HERE EE HE E E ESSE Hello world operator HJEdEEEEEEEEEEEEEEEB EE E HEE HH E Propose hello world If I exist propose the hello world operator Apply hello world If the hello world operator is selected write Hello World and halt dE db db You should now try to write an operator that moves the eater north one step This is easy and the operator you come up with will be similar to hello world except that the action of the operator will be different You can assume that there is an action command move north that moves an eater to the north Don t turn the page until you ve written move north 03 16 01 Soar Tutorial 25 4 1 English Version Here is one possible version of the move north operator HEHEHE EEPEEPEEEE EE EE E ESSE Move north operator Propose move north If I exist the
44. e you see that two rules are firing at the same time apply move north and apply move north remove move One is adding the new move command to the output link at the same time that the other is removing the previous move command There are also examples of rules firing and retracting at the same time where an operator is being removed from working memory at the same time that a new operator is being created You can see how the rules fire in different phases by turning on the watch for phases The easiest way to do this is to click on the watch button on the menu bar and then select phases You can also type in watch phases on 03 16 01 Soar Tutorial 33 Instead letting Soar run free you can step Soar through each decision The default will stop each step after the application phase when output is being processed This is just after the output commands have been added to the output link and just before the eaters are about to move In the following trace the step button has been used and then the output link is examined This is repeated twice Interectian Window Agent From prior runs you know that 13 is the identifier of the output link Although Soar does not guarantee that 13 will always be the identifier of the output link it always is just as 11 is the identifier of the io object 12 is the identifier of the input link and 1 is the identifier of the first state When you print 13 you see that the move command is c
45. e move to food operator e You need one rule to propose the operator when there is normal food in a neighboring cell and a second rule to propose the operator when bonus food is in a neighboring cell Unlike the move north operator these proposal rules do not have to test the coordinates of the eater because the contents of the neighboring cells will change when the eater moves The contents will change the working memory elements for contents of all of the sensed cells are removed and re added to working memory even if the sensed object is the same type The operator proposal rules can also create the indifferent preferences that lead to a random selection e You need a third rule to apply the operator and move the eater in the correct direction e You need a fourth rule to remove the move command from the output link Now try to write English versions of the move to food operator Use the English versions of the move north operator as a guide FHFHHHFEFEEEEEEEEEEPEEEEEHEE Move north operator Propose move north If I am at a specific location then propose the move north operator Apply move north If the move north operator is selected generate an output command to move north Apply move north remove move If the move north operator is selected and there is a completed move command on the output link then remove that command 03 16 01 Soar Tutorial 35 6 1 English Version Here is one possible set of rules for
46. e operators when the proposal conditions change Other examples include state elaboration rules and operator elaboration rules Non persistent working memory elements and preferences are called instantiation supported or i supported because they only persist as long as the rule instantiation that created them For example propose move north is not an operator application rule because it does not test a selected operator All of its actions are i supported and they will be removed from working memory when propose move north no longer matches gt sp propose move north state s io input link eater lt e gt lt gt x x y lt gt lt s gt operator o i supported actions lt o gt name move north 03 16 01 Soar Tutorial 31 Returning to the problem of moving the eater you need to add a rule that removes old move commands from the output link after the move is finished In Eaters the output system creates an augmentation on the move object after the action has executed status complete To remove a structure from working memory a rule rejects a working memory element in its action A reject must be part of an operator application rule because it is a persistent change to working memory Therefore the removal must test the move north operator so that it is an operator application rule In English the rule is Apply move north remove move If the move north operator is select
47. e simple strategy is to prefer operators that jump into cells with bonusfood to operators that move into empty cells while rejecting operators that jump into empty cells We can generalize some of the rules for move to cover both jump and move sp select move bonusfood better than normalfood empty eater state s operator lt ol gt operator lt o2 gt lt ol gt name lt lt jump move gt gt lt name gt content bonusfood lt 02 gt name lt name gt content lt lt normalfood empty eater gt gt gt lt s gt operator lt ol gt gt lt o2 gt sp select jump bonusfood better than move empty state s operator lt ol gt operator lt o2 gt lt ol gt name jump content bonusfood lt o2 gt name move content empty gt lt s gt operator lt ol gt gt lt o2 gt 03 16 01 Soar Tutorial 64 10 5 Jump and Move Operator Selection In order to cover all of the cases of move and jump operators for all of the different cell contents you would need to write lots of rules Is there an easier way One way is to translate the different names and contents into numbers that correspond to the number of points the eater will get A rule could then compare the numbers and create better preferences for operators with higher numbers You can translate the names and contents into numbers by writing one rule for each name and content pair however it is much e
48. ed and there is a completed move command on the output link then remove that command In Soar the action of a rule can remove a working memory element by following it by a reject preference which is designated with a minus sign The above rule is translated to Soar as follows sp apply moye ngrti PEMOS MONG Cannot use dot notation for lt 01 gt and lt move gt state lt s gt operator name move north because they are needed in the action io output link ol lt ol gt move lt move gt Created by the output system when the lt move gt status complete move action is completed lt ol gt move move means remove from working memory The action of this rule removes the working memory element specified by lt ol gt move lt move gt which would be something like 13 move m1 When this working memory element is removed all of the augmentations of m1 are automatically removed because they are no longer inked to the rest of working memory In this case m1 direction north and ml status complete are removed These would not be removed if they remained linked via another working memory element that had m1 as a value This is an operator application rule so it will not fire during the following operator proposal phase Instead it will fire during the next operator application phase after a new move north operator has been selected It will not interfere with o
49. elect between moving into an empty cell or into a cell with another eater The new selection rule can be written in English as Select move avoid empty eater If there is a proposed operator to move to an empty cell or a cell with another eater then avoid that operator Here we use the word avoid to mean that the operator will only be selected if there is nothing worse A worst preference is written as a less than sign lt This is exactly the same as a worse preference except that there is no second variable that the first variable is compared to sp select move avoid empty eater state s operator lt ol gt lt ol gt name move signifies acceptable preference content lt lt empty eater gt gt gt lt signifies the worst preference lt s gt operator lt ol gt lt Just as there is a worst preference there is also a best preference The best preference means that an operator should be selected as long as there is no other operator better than it or it is not worse than another operator is Thus the meaning of best is a bit odd in that better preferences are more important than the best preferences and an operator with a best preference will not be selected if another operator is better than it You could have used a best preference for a move into a cell with normalfood instead of using the worst preference The move to normalfood would then be selected over a move to an empty cell
50. er Soar has a very stylized and precise language you have to use Here is the Soar rule for hello world This is about the simplest Soar program you can create sp stands for Soar The starts body of a rule The name of the rule immediately follows the production and The name can include letters numbers and starts every rule Thisistheitoatoi hello world is is the if part o the rule condition ona lt s gt write ello World The gt separates halt These are the then parts of the rule actions The ends the rule the if and then parts of the rule Every rule starts with the symbol sp which stands for Soar production The remainder of the rule body is enclosed in curly braces and The body consists of the rule name followed by one or more conditions the if part then the symbol gt and then one or more actions the then part Below is template for rules Sp rule name condition condition means additional conditions can follow action actio means additional actions can follow The name of the rule can be any arbitrary combination of letters numbers dashes and asterisks 77 The one exception is that a name cannot be a single letter followed by a number Soar reserves those names for its own purposes The specific name is irrelevant to the operation of the rule
51. erator lt o gt Uses lt dir gt from operator to directions lt d gt match lt dir gt in directions and last direction LI then match opposite lt d gt value lt dir gt opposite lt o dir gt lt o gt name move proposed operator direction lt o dir gt gt means reject so that this lt s gt operator o operator will not be selected Note that this rule will not reject the proposed operator for the first move because the attribute 1ast direction will not initially exist lt odir gt must match opposite of last direction and direction of 03 16 01 Soar Tutorial 60 10 Jump Operator All of the eaters you ve created so far have a single type of operator move In many situations more than one instance of the operator is created but still there was only one operator Adding operators does not change the way Soar operates but it does give you a chance to use what you ve learned on a slightly different problem In this section you are going to write the jump operator An eater can jump over a cell to two moves away however a jump costs the eater 5 points the same as it gains from a normalfood The eater can jump over a wall but it cannot jump into a cell with a wall In writing the jump operator you should write and test the proposal and application rules without including the move operator This will let you debug the jump rules first without getting things
52. es that this is an identifier in all actions o name hello world acceptable preference The first action creates an acceptable preference for a new operator which is added to working memory and the second action creates a working memory element that augments the operator with its name A preference looks just like other working memory elements except that it has a fourth item the type of preference which in this case is The identifier of the preference is lt s gt which means that the identifier matched to lt s gt in the condition is used in creating the action For example if working memory contained 51 type state then when this rule fired the preference would begin with s1 operator The value of the preference lt o gt is a new variable that did not occur in the condition When new variables appear in actions Soar automatically creates a new identifier and uses it for all occurrences of that variable in the action For example if o1 is the identifier created for lt o gt then s1 operator ol and 01 name hello world are added to working memory For action variables such as o a different identifier is created each time a rule fires Additional rules may create preferences to compare operators The decision procedure selects an operator based on all the created preferences If a single operator is proposed that operator is selected In this case propose hello world fires creating a single acceptab
53. g memory elements arguments Matches can be invoked by clicking with the right mouse button on the name of a production and then selecting production from the menu that appears 03 16 01 Soar Tutorial 46 preferences There is a special command to print out the preferences for selecting an operator This command also works for any working memory element prior versions of Soar allowed preferences for all working memory elements and there are still vestiges of them in the current version To use the preference command you give an identifier and an attribute Soar will then print out all of the preferences for all values of that identifier attribute pair For example to print out all of the preferences for the operator attribute red gt preferences sl operator Preferences for 51 operator acceptables O7 move to food O8 move to food O9 move to food unary indifferents O7 move to food O8 move to food O9 move to food This example shows that there are three operators proposed O7 O8 O9 and each one has an acceptable and indifferent preference The preferences command has another feature that makes it extremely useful Using the name argument it will tell you the name of the production that created the preference For example if you want to discover why there is the working memory element I3 move m3 you can type red preferences I3 move names Preferences for I3 move acceptables M3
54. hat happened in the past and what is about to happen This subsection is organized by the different commands To learn the details of all of these commands you should check the Soar User s Manual print You have already seen the print command which is used to print out working memory structures Print can take a variety of arguments One of the most useful is to print to a given depth This prints not only the current identifier and all of its augmentations but also all of their augmentations recursively to a given depth For example you can print out the current state to a depth of 2 by using the following command red gt print depth 2 sl The order is important and s1 must come at the end of the print statement The result is S1 type state superstate nil io Il operator 02 operator 04 operator operator 02 operator 01 Il input link I2 output link 13 O2 name move to food direction south O4 name move to food direction west O3 name move to food direction north Ol name move to food direction east You can also use the mouse to print working memory objects by right clicking on an identifier If you select the print option you will see that there a many other options for printing objects in working memory wmes The wmes command can also be used to print out individual working memory elements instead of complete objects This command also prints out the timetag of an individual work
55. have stopped before the eater moved 4 3 Shortcuts The apply move north rule has lots of variables in it whose sole purpose is to make connections between attributes For example lt o gt is used to later match the name of the operator and lt io gt is used to later match the output link Similarly move is used in the action to connect the output link to the final direction None of these variables is used in both conditions and the actions Sp apply move north state s operator o io 4102 lt io gt output link lt ol gt lt o gt name move north gt lt ol gt move lt move gt lt move gt direction north To simplify the writing and reading of rules Soar allows you to combine conditions that are linked by variables To do this you can just string together attributes replacing the intermediate variables with a period to separate the attributes In Soar we call this dot or path notation Below is the same rule as before using dot notation sp apply move north state s operator name move north o Meme ol 3 lt ol gt move drrection north This rule is exactly the same as the original from Soar s perspective One mistake you want to avoid making is to use dot notation in the action when you are creating multiple sub attributes of a new object This will create multiple objects each with a single sub attribute For example if you want create a secon
56. ing memory element This is a unique number that Soar uses to keep track of each working memory element red gt wmes ol 120 ol name move to food 121 ol direction east Timetags can also be used as arguments in the print and wmes commands Print will display all of the working memory elements that share the same identifier as the working element with the given timetag while wmes will display only the single working memory element red print 120 Ol name move to food direction east red wmes 120 120 ol name move to food 03 16 01 Soar Tutorial 45 matches One of the questions you will frequently want to ask is What rules are about to fire The matches command will return a list of all rules that are ready to fire separated into those that will be operator applications Assertions those that are will create augmentations Assertions and those that will remove I supported augmentations Retractions red gt matches O Assertions I Assertions Retractions Matches also can be invoked through the show item on the menu list or by right clicking on the interaction window then selecting the production item on the menu that appears Matches can also take as an argument the name of a rule It will then print out the rule condition by condition with information on how many working memory elements match that condition and are consistent with all of the variables in the previou
57. ings item off the Start menu Select Folder Options and the pick the File Type tab Select New Type and in the pop up window define the soar type You need to fill in soar without quotes under the Associated extension and select text plain under Content Type Whenever you save the file make sure you save it as a text file with linefeeds Soar cannot handle formatted text and text without linefeeds 81 will always be the identifier of the first state but that is an artifact of the way Soar is implemented 03 16 01 Soar Tutorial 20 3 Building Simple Eaters Using Operators In this section you will learn how to use rules to select and apply operators Operators perform actions either in the world or internally in the mind of an eater In Eaters there will be operators to move the eater around the board There could also be operators to remember uneaten food count food or remember where walls are The operators in a TicTacToe program would mark X s or O s on the board The operators for a soccer program would probably include move turn kick the ball send messages to teammates interpret messages from teammates choose a tactic or strategy and so on Operators are created in working memory by one or more proposal rules which test that the operator can apply The actions of an operator are performed by one or more application rules which test that the operator is selected and then make the appropriate changes t
58. is page has a summary of the structure of the top state for every eater It is a useful reference when you build your own eaters and you will probably want to make a copy of it All of the attributes of an object appear below it in outline form with indentation used to signify sub objects Possible values are listed on the same line as the attribute Sio input link eater direction east north south west name red blue yellow green purple black score 0 1000 x 1 15 y 1 15 my location content bonusfood normalfood eater empty wall east content bonusfood normalfood eater empty wall north content bonusfood normalfood eater empty wall south content bonusfood normalfood eater empty wall west content bonusfood normalfood eater empty wall output link move direction east north south west status complet created by Soar as feedback jump direction east north south west status complet created by Soar as feedback superstate nil type state 03 16 01 Soar Tutorial
59. l actions The first rule creates the action command on the output link To make this a completely general rule you need to have a standard way of representing action commands on operators so that a single rule can create the commands on the output link The simplest convention is to have the action command be an augmentation of the operator such as jump direction direction Another possibility would be to have a specific augmentation on the operator say actions that had the commands as subobjects lt o gt actions jump direction directionl You probably want to adopt this second approach because it makes it possible to write a single rule that copies the action commands to the output link without risk of copying other augmentations Under that convention the general command creation rule is sp apply operator create action command state s operator actions att value io output link lt ol gt gt lt ol gt att lt value gt The lt att gt variable will match jump and the value will match the identifier of the object that has direction as an augmentation It copies jump and that identifier on to the output link The second general rule removes a completed action command Sp apply operator remove command state s operator actions Included so action has io output link ol o support lt ol gt att lt value gt lt value gt status complete gt lt
60. le preference for o1 and then the decision procedure selects 01 to be the current operator and adds 51 operator o1 to working memory Note that this augmentation does not have the following the value Only the decision procedure can add such an operator augmentation for a state to working memory while proposal rules can add acceptable preferences for operators that differ by ending with the Once the operator is selected apply hello world should fire Test that an operator apply hello world has been selected state s operator o lt o gt lt ne E E Both occurences of o must ihe selected e match the same identifier apei i has name hello write Hello World halt This rule has exactly the same actions as hello world but with conditions that test that the operator hello world has been selected The first condition tests that some operator has been selected We cannot include a specific identifier for the value such as o1 because the exact value of the identifier can be different each time we run the program so a variable in this case o is used The second condition tests that some object in working memory has name hello world The rule will only match if both o s match the same identifier such as o1 This is true for all variables in Soar if the same variable shows up multiple times in the conditions of a rule the rule will not match and fire unless all
61. lem has nothing to do with state or a missing you have to hunt around a bit to find the problem To fix this problem add before the production name To continue click ok to the pop up window delete the eater and try to create it again You will no longer get a pop up error window and the interaction window will look like Interaction Window Agani sellow In this case Soar did not find and end to the first condition and encountered the gt Add a and try again 03 16 01 Soar Tutorial 1 Hon Window Agen red This time Soar loaded in the first rule correctly which you can tell because it printed out a without any errors However it did find an error in apply move to food Soar is confused in the conditions of this rule because there was an extra close parenthesis after name move to food so it thought there should be an arrow instead of the direction lt dir gt Remove the extra parenthesis and try again tion in Agent red Now Soar has loaded in the first two rules and is trying to load in the third The error message points out that somewhere there is missing for an attribute In this case it is the operator If you add the before the operator in the first condition the file will now load in correctly 03 16 01 Soar Tutorial 43 7 2 Write Statements One of the oldest debugging techniques in traditional programming languages is to add print statements thr
62. low block that is ona table using the representation below 1 block b1 block b2 table t1 b1 color blue name A ontop b2 size 1 type block weight 14 b2 color yellow name B ontop t1 size 1 type block under 61 Aweight 14 t1 color gray shape square type table under b2 Working memory usually also contains objects that are only conceptual things and do not have an identifiable physical existence such as state s1 which organizes other objects relations and properties The exact representation of objects is up to you the designer of a Soar program Soar does not require any declarations of the possible attributes and constants In fact some Soar programs generate new attributes and constant values as they execute The Soar editing and development tool Visual Soar does require declarations for the structure of working memory elements but those declarations are used only to check for errors in your rules and they are not used by Soar when it is executing a program 03 16 01 Soar Tutorial 19 2 4 Hello World Rule Soar Details You now know enough to return to the first example rule The original English version included the test If exist Remember that every eaterhas 51 type state in working memory which signifies in someway that the eater does exist Thus you can test for the presence of that structure in working memory to determine if the eater exists The obvious
63. mixed up with the rules for the move operator You should then write operator selection rules and combine your jump operator with the move operator In writing the jump operator you will want to use the initialization rule for directions from the previous section so you will want to copy that to your file in which you are writing the jump operator The rest of this section goes through the rules for jump If you feel confident in your knowledge of the aspects of Soar that have been presented so far you should try to write your own jump operator before reading this section As you are writing your own jump operator you should try to reuse or generalize some of the rules you wrote for the move operator You might find it is a bit tricky for your eater to correctly keep track of the previous direction it moved or jumped you get stuck or are unsure about what to do you should read these sections After you finish this section you can try your own strategies by creating different eaters with different control knowledge You can even have contests between them to see which strategies work best 10 1 Jump Operator Proposal There are only two differences between the proposal for the move operator and the jump operator e first difference is that the name of the operator should be jump not move e The second is that instead of testing that an adjacent cell does not contain a wall the jump operator needs to test that a cell two moves away
64. n of the move operator while the eater is moving but it disappears along with the operator once the move is completed What is needed is a persistent augmentation of the state that records the direction of the last operator This direction can then be used to avoid moving in the opposite direction You will need to change the operator proposal to avoid moving back to the prior cell and the operator application to record the direction of the prior cell A further change is needed to initialize some data structures in working memory that will make it easy to determine the opposite of each direction which is needed to avoid moving back to the last cell In this section we start with the initialization rules and then cover the operator application rules and operator proposals 9 1 Initialization Opposite Directions The rules that you will write for operator application and selection need to determine the opposite of the direction the eater moved last because that is the direction that needs to be avoided The easiest way to do this is to create a structure in working memory that contains each direction and each direction has an attribute that is its opposite direction This structure can be on the state and the following rule creates one possible structure that encodes this information sp initialize state directions Multip l nds cuc d b A ultiple values for a single attribute can be Eo ss state Soccer E lt ss gt dire
65. n propose the move north operator Apply move north If the move north operator is selected then generate an output command to move north This operator has only two changes from hello world First the name is move north instead of hello world Second the action of the second operator is to generate an output command to move north To write the Soar rule for apply move north you have to know how to get an eater to move All external actions are issued by creating working memory elements that are augmentations of the output link The output link is an augmentation of the io object which in turn is an augmentation of the state In Eaters a move command is issued by creating a move augmentation on the output link object which in turn has an augmentation called di rection with a value of the direction to move north south east or west For each task in Soar a set of output commands is defined and in Eaters there are two commands move and jump io output link move direction 0 0 5 0 You should now to write the Soar rules for the move north operator Here are the rules for Hello World that you can use to create your own version of the move north operator sp propose hello world state s type state T lt s gt operator o lt o gt name hello world sp apply hello world state s operator lt o gt lt o gt name hello world write Hello
66. name gt content lt content gt lt ccv gt name lt name gt content content value lt value gt gt lt o gt value lt value gt Now you can write a rule that compares the values associated with each operator and then creates a better preference for the operators with higher values sp select compare best value state s operator lt ol gt operator lt o2 gt lt ol gt value lt v gt lt o2 gt value lt lt v gt lt s gt operator lt ol gt gt lt 2 gt During a run the first rule will fire for every proposed operator and the second rule will fire for every pair of operators with different values All of these firings including the proposals of the operators happen during the proposal phase 03 16 01 Soar Tutorial 65 11 Advanced Eaters If you want to build more complex eaters here are a few ideas You will find it easier to build some of these after you complete the next part of the tutorial An eater that chases another eater An eater that tries to stay away from other eaters An eater that systematically searches for food when empty cells surround it An eater that looks ahead to see what move would be better based on what surrounds the cell it is going to move into An eater that takes advantage of the fact that bonus food comes in vertical lines each 4 cells apart PON e 03 16 01 Soar Tutorial 66 12 Top state Structure Th
67. nd are about to fire This is extremely useful because it let s you look into the future Below is an example match set monitor window for move to food when the Stop After Decision option is used Usually no productions will be in the match set when you halt Soar because all of the rules have fired and output is about to be called However if you select Stop After Decision under the Eaters button of the Control Panel Soar will also stop after an operator is selected In this case you can see that the rule to remove the previous move command on the output link is about to fire apply move to food remove move and the rule to add the new move command to the output link is about to fire apply move to food Monster maichtpet Assertions epply move to food remove move S1 applysmove to food 51 The Op preferences window continually displays the preferences for selecting the next operator This is helpful when you are trying to figure out which operator is about to be selected or why the current operator is selected agpreterencesManibor fle Shon Mower Commons Domos Preferences for 51 operator acceptables 01 move to food 02 move to food 03 mavae ta foad 04 mave to fced unary indifferents 01 move te food 02 0 03 move to food 04 move to fond 03 16 01 Soar Tutorial 48 7 5 Semantic Errors In this
68. nt spaces upper and lower case letters The second action is a special command in Soar that halts the eater From this simple example you should be able to write your own rules that print out different messages for Soar If you wish to try this out yourself you have two choices The first is to use Visual Soar Visual Soar is the Soar development environment and it let s you develop and manage Soar programs It has its own documentation and tutorial and can be found at the Soar web pages Although it will initially slow you down to learn Visual Soar it will be worth it in the long run If you choose to use Visual Soar first create a folder directory for all of the eaters you will be writing in the agents folder of the Eaters program Eaters agents The Tutorial folder is already there For example if were doing the tutorial on a PC might call it Johns Eaters Then install Visual Soar in that folder directory and use it to create a new project called move north If you want to use a text editor almost any will do such as Word WordPerfect Wordpad Notepad or Emacs In this editor create a new file named move north soar in your new folder directory Make sure the file ends soar This may be difficult to do in Wordpad or Notepad which automatically add txt to the end of a file but is necessary for the file to show up in the Eater file menu If you are having trouble with this in Windows go to the Sett
69. o working memory 3 1 Hello World Operator English Version Instead of using a single rule to print Hello World you will use an operator Operators allow you to have an action considered in multiple situations rules that propose the operator allow multiple reasons for selecting an action rules for selecting operators and allow multiple ways for doing it rules that apply the operator For this simple isolated action an operator may not be necessary but as soon as other actions are added operators become extremely useful Here are the rules for the hello world operator Propose hello world If I exist propose the hello world operator Apply hello world If the hello world operator is selected write Hello World and halt The first rule proposes the hello world operator and the second performs its actions after the operator has been selected Notice that the first rule only proposes the hello world operator An operator is selected by Soar s decision procedure which collects together proposed operators and selects one Select Operator decision procedure Propose Operators rules Apply Operator rules Soar s basic operation is a cycle in which operators are continually proposed selected and applied Rules fire to propose and apply operators while the decision procedure selects the current operator To see this operator run destroy any existing eaters such as hello world rule and then
70. occurrences of the variable in the rule match the same symbol in working memory In this case they both match o1 and this rule fires If the same variable is used in other rules it can match completely different identifiers or constants that is the identity of variables only matters within a rule The exact symbols used in a variable are irrelevant although as a general convention s is used to match state identifiers and o is used to match operator identifiers However this is only a convention to make it easier to understand the rules 03 16 01 Soar Tutorial 22 3 3 Examining Working Memory We can get an even more detailed look at Soar s processing by examining the data structures in working memory The Interaction Window allows you to print out the contents of working memory using the print command To print out all of the attributes and values that have 1 as the identifier first click in the interaction window and type print s1 followed by the Enter key the prompt will appear as soon as you start typing The Interaction Window should now look like Interechion Window Agen ned File Shen Productions Walch Monitor Commands Help What you typed s1 or S1 D e 5 51 will work 0 Ol hello world Hello World L I1 System halted as 81 O1 is selected operator 51 type state superstate nil io operator 01 ron
71. ondition must match the state identifier You should change your rules if they were significantly different than these Then create a move north eater and run it by clicking on the step button a few times until your eater moves north If your eater doesn t seem to be working skip ahead to the Debugging Your Eater section Once your eater has moved north your interaction window should look like the following Window Agent med Firing propose meve nortl ue 0 01 Firing apply mewve north 2i But what happened to your eater After selecting move north and taking one step the eater had nothing more to do and a new state is created s2 in the above Figure Unfortunately the rules you wrote are not sufficient to get the eater to continually move north In the next section you will modify your eater so that it continues to move north 03 16 01 Soar Tutorial 27 One alternative you might have tried was to include halt in the action apply move north If you tried that your eater did not move because the halt is executed before the output is processed Propose Operators Select Operator Apply Operator rules decision procedure rules In Soar after all of the application rules have fired the output system picks up new working memory elements on the output link and sends them to the Eaters world causing the eater to move If you had included a halt as an action in apply move north Soar would
72. or a cell with an eater Select move bonusfood better than normalfood empty eater will ensure that bonusfood is preferred to normalfood Select move prefer normalfood If there is a proposed operator to move to a cell with normalfood prefer that operator sp select move avoid empty eater state s operator lt ol gt lt ol gt name move content normalfood gt gt signifies the best preference lt s gt operator lt ol gt gt 03 16 01 Soar Tutorial 54 8 4 Summary Preferences This section summarizes the meaning of the preferences presented earlier There are two additional preferences require and prohibit that are only rarely used and are not covered in this tutorial but are described in the Soar 8 Manual The preferences can be thought of as a sequence of filters processed in the following order e Acceptable An acceptable preference states that a value is a candidate for selection Only values with an acceptable preference have the potential of being selected If there is only one value with an acceptable preference that value will be selected if it does not also have a reject preference e Reject A reject preference states that the value is not a candidate for selection A value will not be selected if it has a reject preference e Better gt Worse lt These preferences state that a value should be selected if the better value is a candidate If the better v
73. or application rules by allowing them to match an operator named either move or jump and then copying the operator name to the output link Apply move jump If the move or jump operator for a direction is selected generate an output name to move in that direction sp apply move state s io output link lt ol gt move or jump operator lt gt lt o gt name lt name gt lt lt move jump gt gt direction lt dir gt lt name gt be move or jump as lt ol gt lt name gt irection lt dir gt matched in condition f Apply move jump remove name If the move or jump operator is selected and there is a completed name on the output link then remove that name lt name gt will match sp apply move remove mov state s io output link lt ol gt operator name name name will match lt ol gt lt name gt drre move or jump lt direction gt status complete lt ol gt lt name gt direction 03 16 01 Soar Tutorial 62 10 3 Simplified Operators In writing the operator application rules for the jump operator you have probably noticed that both operators include a rule to create the action command move or jump on the output link and then remove that command when it has completed You can simplify the writing of future operators by writing two general rules that perform these functions for every operator that performs externa
74. orial we recommend that you read the tutorial do the exercises run the programs and write your own Soar entities The programs are available at http ai eecs umich edu soar tutorial html Please use the most recent versions Although the tutorial is long you should be able to work through it quickly What is Soar We call Soar a unified architecture for developing intelligent systems That is Soar provides the fixed computational structures in which knowledge can be encoded and used to produce action in pursuit of goals In many ways it is like a programming language albeit a specialized one It differs from other programming languages in that it has embedded in it a specific theory of the appropriate primitives underlying symbolic reasoning learning planning and other capabilities that we hypothesize are necessary for intelligent behavior Soar is not an attempt to create a general purpose programming language You will undoubtedly discover that some computations are more appropriately encoded in a programming language such as C or Java Our hypothesis is that Soar is appropriate for building autonomous entities that use large bodies of knowledge to generate action in pursuit of goals This tutorial is specific to Soar 8 which has significant changes from earlier versions of Soar These changes improve Soar s ability to maintain the consistency of its reasoning while interacting with dynamic environments The tutorial comes in five p
75. orrectly added to the output link You can see more than one level of augmentation by using the depth flag on the print command Here a depth of 2 was used which is sufficient for printing out the augmentations of 13 and 1 You can also step through one phase at a time by using the run p command 03 16 01 Soar Tutorial 34 6 Move To Food Operator In this section you will create an eater that greedily moves to any food it senses You will use the lessons you learned from the move north operator and learn more about the structure of the input link and operator preferences Each eater can sense the food and walls that surround it two steps in each direction The Eaters Info window shows what an eater can sense For this eater you will write an operator that moves the eater to one of the neighboring cells north east south or west that contains normalfood or bonusfood Since food can be in more than one of the neighboring cells more than one operator may be proposed Soar does not automatically select randomly from among a set of proposed operators it will get a tie impasse if there are multiple operators with only acceptable preferences To avoid ties Soar has additional preferences For this exercise it does not matter which food an eater consumes first you can use a preference that makes the decision procedure arbitrarily select one of the proposed operators Based on the above discussion you will need four rules for th
76. oughout the program Although not the most effective technique it can be easily used in Soar by adding write statements in the action of rules To make the output readable you want to have a linefeed before writing out any text using the command which stands for carriage return and linefeed For example if you want to keep track of all of the move to food operators that are proposed including their direction and expected food you could take the original rule given below Sp propose move to food state s io input link my location dir content lt lt normalfood bonusfood gt gt gt lt s gt operator lt o gt lt o gt name move to food direction lt dir gt and modify it by adding a write statement To get the right values in the action requires a variable for the food type in the condition sp propose move to food state s io input link my location dir content type lt lt normalfood bonusfood gt gt write crlf Propose move lt dir gt for lt type gt lt s gt operator o lt o gt name move to food direction lt dir gt The write command concatenates all of its arguments that can include constants and variables Interaction Window Agent red 03 16 01 Soar Tutorial 44 7 3 Runtime Debugging Commands While Soar is running there are many commands you can use to get information on what the current state of the system is w
77. output link lt ol gt operator name move lt ol gt move lt direction gt lt direction gt status complete 01 move direction The proposal rule together with these two rules will give you an eater that randomly moves around avoiding walls We can greatly improve its behavior by using more preferences 03 16 01 Soar Tutorial 52 8 3 Move Operator Selection To improve the performance of the eater we can add rules that prefer moving to bonusfood over normalfood or an empty cell and prefer moving to normalfood over moving into an empty cell or a cell with another eater The preference language in Soar is rich enough to support a variety of ways of ordering the choices and we will explore different possibilities in this section To get started you need to create a rule to prefer bonusfood to normalfood or empty or an eater The condition part of the rule must match against operator proposals while the action part must prefer the operator that moves to the bonusfood In English this would be Select move bonusfood better than normalfood If there is a proposed operator to move to a cell with bonusfood and there is a second proposed operator to move to a cell that is empty or has normalfood or another eater prefer the first operator The conditions of this operator must match against proposed operators before they have been selected A proposed operator can be matched by matching the a
78. placement information Spend some time creating running and destroying different eaters Notice how the eaters move around the board differently some being much more efficient at consuming food 03 16 01 Soar Tutorial 15 2 Building A Simple Eater Using Rules All of the knowledge in an eater is represented as if then rules In Soar rules are called productions and we will use the terms interchangeably Rules are used to select and apply things called operators and much of this tutorial will be describing how rules and operators fit together But before we get to operators we are going to learn about writing rules 2 1 Hello World Rule English The first eater we will look at just prints Hello World in the Interaction Window In general an operator should perform this type of activity but in order to ease you slowly into Soar we start with a single rule Below is a simple rule written in English hello world If I exist then write Hello World and halt Soar cannot directly interpret English so you must write rules in Soar s very stylized and precise language A major component of the rest of this tutorial is teaching you this language Soar works by testing the if parts of rules If exist These if parts are called conditions If the conditions of a rule are true in the current situation the then parts or actions of the rule write Hello World and halt are performed This is called firing
79. pty in an adjacent cell and there is no last direction equal to the opposite direction for that cell propose move in the direction of that cell with the cell s content and indicate that this operator can be selected randomly test for the absence an augmentation Soar uses dash The dash called negation precedes the augmentation that must not be in working memory for the rule to match The new proposal rule is as follows sp propose move no backward state s io input link my location dir content co lt gt wall means that this rule AUS will match only if no directions lt d gt working memory last direction lt o dir gt elements match this value lt dir gt attribute value opposite o dir lt dir gt matches the direction of the adjacent cell that is not a wall lt o dir gt matches the opposite of 7 direction of the adjacent cell that is lt s gt operator o not a wall lt o gt name move direction lt dir gt content lt co gt A negation can also precede a complete object where the identifier is followed by multiple attribute values In that case its is a test that there is no object with all of those attributes in working memory The semantics of using negation can be a bit tricky and the details of it are spelled out in the manual 03 16 01 Soar Tutorial 59 9 4 Advanced Move Operator
80. r 01 operator 01 01 name hello world red 9e so 03 16 01 Soar Tutorial 23 Operator o1 has augmentation with attribute name and value hello world We can also examine the augmentations of some of the other values 11 is the value of the io attribute which stands for input output To see more about input and output print 11 However instead of using the print or p command you can use the mouse to print information about 11 If you don t have a mouse just use print To do this move the cursor over 11 in the Interaction Window then click and hold the right mouse button A menu will appear that has a list of commands print preferences WMEs productions and run Move the mouse over the print command still holding down the button and slide it to the right A new menu will appear with different print options Slide the mouse over the top one and then release the button Your interaction window should look like There are two attributes of io input link and oubput link The input link is where an eater s sensory information is available i in working memory The output link is where action commands must be explore the structure of the input link 13 You can also try out some of the other commands availableXhrough the mouse although we will work our Rules augment the value of the output link with motor commands Sensory information is added to the value of the input link You now
81. r is put after the greater than sign Therefore the Soar rule is as follows sp select move bonusfood better than normalfood empty eater state lt s gt operator lt ol gt mm n signifies acceptable preference operator lt 2 gt lt ol gt name move content bonusfood lt 02 gt name move content lt lt normalfood empty eater gt gt nx signifies the better preference lt s gt operator lt ol gt gt 02 If there are adjacent cells with both bonusfood and normalfood this rule will fire right after propose move creates acceptable preferences but during the same proposal phase so that it will influence the next operator selection It will fire multiple times if there are multiple cells with bonusfood or normalfood After these preferences are created the decision procedure will gather them up to make a decision 03 16 01 Soar Tutorial 53 You can use exactly the same approach to prefer moving to cells with normalfood over moving to empty cells or cells with eaters Soar provides an alternative with the worst preference which means don t select the operator unless there are no other choices In this case you can create worse preferences for operators that move the eater into an empty cell or a cell with another eater With these additional preferences operators that move into cells with bonusfood or normalfood will always be selected if they exist and otherwise the eater will randomly s
82. r is surrounded by food the lt direction gt variable will match all directions leading to four matches of the rule In Soar all new matches fire in parallel creating new operators each with a different di rection augmentation For example if there was normalfood to the south and west two operators would be created one with direction south andone with direction west This rule can be written much more concisely using dot notation and a short cut for the preferences Sp propose move to normalfood state s io input link my location dir content normalfood gt lt s gt operator o lt o gt name move to food direction lt dir gt The rule that proposes the operator to move to consume bonusfood is very similar sp propose move to bonusfood state s io input link my location dir content bonusfood gt lt 5 gt lt gt means two preferences created acceptable and indifferent operator lt o gt name move to food direction lt dir gt The rule to create the move command on the output link is very similar to the one used in move north The only difference is that instead of always using north as the direction it uses the direction created by the operator proposal rule and matched by variable lt dir gt sp apply move to food state s io output link lt ol gt operator lt gt name move to food direction lt dir gt lt o gt
83. rom the same or different files so that you can create a set of identical eaters except for color or sets of different eaters Each time a new eater is created a new Interaction Window is created and the Eaters Info window is expanded to include information on the new eaters To destroy an eater click and hold the Destroy Eater button A menu will appear with the colors of all of the currently active eaters Select the one you wish to destroy and it will be removed from the game EU Control 03 16 01 Soar Tutorial 13 Additional menus are available via the labels at the top of the control window Eaters Windows If you click on Eaters a menu will appear that allows you to destroy all active eaters modify when Soar stops this will be explained in detail later or select some actions for a specific eater based on its color In the example there is only one eater red so only its color shows up as a selection in the menu extr oy AB Eaters Destroy all active eaters Siop After Decision Stop eaters after they select an operator Perform actions on selected eater If you click on red a new menu appears The most important action allows you to reload the production rules for the eater This is useful if you have found a bug modified the rules in the file and then wish to immediately test them on the current situation Soar will load in the rules replacing original versions with new ver
84. s conditions When Soar loads in a rule it automatically reorders the conditions of the rule so that it can efficiently match it so the ordering of the conditions from matches will not be the same as the ordering of the rule when you wrote it If a rule completely matches then it has either already fired or is about to fire red matches propose move to food 1 state s io i 1 1 i 1 input link lt 1 2 gt 1 i 2 my location lt m 1 gt 7 m 1 dir d 1 3 d 1 content lt lt normalfood bonusfood gt gt lt 1 gt 3 complete matches In this example the first three conditions have a single match and then the fourth condition matches seven different working memory elements These are all of the augmentations of my location The final condition then restricts the matches to be only those that have content normalfood or bonusfood If a rule does not completely match the condition that failed to match will be preceded by gt gt gt as in red matches apply move to food remove move 1 state s operator lt 1 gt lt o l gt name move to food 1 s io i 1 1 i 1 output link lt 1 gt 1 lt ol gt move lt move gt gt gt gt gt move status complete 0 complete matches Matches can also print out working memory elements that match the conditions by using the timetags for just the timetags or for complete workin
85. select hello world operator as the current eater s file and create an eater Once again change the tracing by typing in watch productions on Click on the run button The trace shows that propose hello world fires first to propose the operator The operator hello world O1 is then selected by the decision procedure After hello world is selected apply hello world fires and performs the actions of the operator by printing out Hello World and halting Interaction Window Agent red 7 Operator proposed Firing proposes hello world ie 0 01 fhello werld Firing apply hello werld Hello World System halted 03 16 01 Soar Tutorial 21 3 2 Hello World Operator Soar Version There is a one to one mapping of the English rules to Soar rules The condition of propose hello world is the same as the condition for the hello world rule The difference is in the action where propose hello world proposes the hello world operator A rule proposes an operator by creating an acceptable preference for the operator An acceptable preference is a statement that an operator is as a candidate for selection The rule below proposes the hello world operator s in the action is replaced Sp iste ce ype state iere eure by the identifier matched by state s type state replaced by a new unique identifier s in the condition gt 0 replaced by the lt s gt operator lt o gt y indicat
86. sions a is printed in the Interaction Window whenever rule is replaced and adding new rules Reset Eater reloads the production rules and restarts the eater as if it were just created Excise All removes all rules while Excise Chunks removes all learned rules more on learning much later Controls whether an eater s windows are displayed Raises eaters windows to front RBS Reloads all rules for eater Reset Eater Reloads rules and initializes working memory E Removes all rules Excise Chunks Removes all learned rules If you click on the Map button a menu with three options will appear You can load in a stored map by clicking on Load Map You can restart the eaters on the current map by clicking on the Restart Map button The eaters will be placed randomly on the board and all of the food will be regenerated You can also generate a completely new map by clicking on the Random button Load Map Restart Map Restart current map Create a random map 03 16 01 Soar Tutorial The Windows button lets you find or hide the Playing Board and Eater Info windows It also lets you save away the current configuration of windows so that the next time Eaters starts up your windows will be where you have them Waki Map Find or hide the Playing Board Eater Find or hide the Eater Info Sie Window Prefs Save current window placement information Load in window
87. stances may include many actions but they will be selected and applied only once Therefore new instances of the move north operator should be created in working memory for each new move You should not attempt to have the move north operator selected once and have it move an eater multiple times Instead you should design you eater so that a new instance of the move north operator is created for each move You can do this by having the operator proposal rule fire each time the eater is to move How can you change propose move north so that it fires after each move As the rule is currently written it will fire only once because it only tests type state which stays in working memory forever Your rule needs to test working memory elements that change each time the eater moves those working memory elements that correspond to the eater s senses on the input link Soar is designed so that changes to the input link are made following output just in time to affect operator proposals Input Propose Operators Select Apply Operator Output M rules rules The information that comes on the input link consists of objects with attributes and values I2 eater I4 my location I5 14 direction south name red score 25 x 1 y 10 south directiop 5 red 25 my location The input link object 12 has two augmentations The first eater has information about the eater its current direction
88. te variables in conditions whose sole purpose is to link conditions Dot notation works if there is a single augmentation However if there are multiple augmentations dot notation doesn t help Grouping using parentheses handles this case In place of where a variable would go as an action you can insert the augmentations of the value For example the original apply move to food was sp apply move to food state s io output link lt ol gt operator lt gt lt o gt name move to food direction lt dir gt gt lt ol gt move direction lt dir gt This can be replaced by sp apply move to food state s io output link lt ol gt operator name move to food direction dir gt lt ol gt move direction lt dir gt Although this does eliminate unnecessary variables it often makes the rules more difficult to read so this notation will not be used in the rest of the tutorial One more thing you might want to add is the ability to trace the direction of the selected operator You can do this with a rule that tests that the operator is selected and uses the write action sp monitor move to food state s operator lt o gt lt o gt name move to food direction lt direction gt gt write Direction lt direction gt This rule will fire in parallel with apply move to food because it matches a selected operator 03 16 01 Soar Tutorial 6 4
89. tents except walls This rule will have to be changed if we ever add other types of food e g superbonusfood It might be better to write a rule that tests that the content is not equal to wall This can be done in Soar by using lt gt The not equal test can also be combined with the variable as in propose move 1a giving the following rule sp propose move 2a state s io input link my location dir content content wall lt s gt operator o lt o gt name move direction lt dir gt Will match any value except wall content lt content gt The lt gt must be placed directly before the value it compares and in the example above it is correctly before wall The rule can also be written with the variable after the test that the content is not equal to wall sp propose move 2a state s io input link my location dir content lt gt wall content lt 5 gt operator o lt o gt name move direction lt dir gt The order of tests in does not matter content lt content gt The not equal test can also be used with variables For example if you want to test that the content of the cells to the north and south of the eater are not equal you could use the following conditions state s io input link my location lt my loc gt my loc north content north south content lt gt lt north gt If you wanted to match the
90. the move to food operator TAE EREEEEEREREEE E EE EE E EE EHE Move to food operator Ht eee tee HEE HE HEE HEE HE HEE Propose move to food normalfood If there is normalfood in an adjacent cell propose move to food in the direction of that cell and indicate that this operator can be selected randomly Propose move to food bonusfood If there is bonusfood in an adjacent cell propose move to food in the direction of that cell and indicate that this operator can be selected randomly Apply move to food If the move to food operator for a direction is selected generate an output command to move in that direction Apply move to food remove move If the move to food operator is selected and there is a completed move command on the output link then remove that command Converting these rules to Soar requires a more detailed examination of preferences and the input link Preferences To select randomly among the proposed operators Soar has a preference called indifferent The equal sign is used to signify an indifferent preference for an operator just as signifies acceptable The indifferent preference means that the decision procedure can randomly select among all operators with indifferent preferences so it is important that all proposed operators have indifferent preferences Even though we will create an indifferent preference for these operators the acceptable preference is still necessary
91. ther operator application rules because rules fire and retract in parallel as a wave The parallelism is only simulated but the effect is as if all the rules fire or retract at the same time Once a wave of rules has fired their actions may cause additional rules to match or retract Soar will continue to fire or retract additional waves of rules until no more rules match Thus within the phases of proposing and applying operators Soar fires all rules that match until quiescence that is until no more rules match During the propose phase only rules that have i supported actions will fire During the apply phase both o supported and i supported rules fire Returning to our diagram of the phases of Soar both the propose operator and apply operator phases can be expanded to show that multiple rules fire and retract in parallel until quiescence Propose Operators Apply Operator i supported gt gt gt gt gt gt gt Sel ema 03 1 6 01 Soar Tutorial 32 5 3 Running and Tracing When running your new eater it will go north until it hits a wall or the border When it can no longer move it will start generating states because it cannot successfully apply and terminate the move north operator Below is a sample trace of the interaction window for the first three moves to the north by an eater Inberection Window Agent red If you look closely at this trac
92. ths will come up If this is the first time that the tutorial has been run on your machine the only name that should come up is Tutorial Select that item and your control panel should look as follows Tutorial is now selected as the current path advanced move is now selected as the current file The Tutorial folder is now selected as the current path Below the path you will see that advanced move is selected as the current file Advanced move is selected only because it is the file in the folder that is first in alphabetic order Your next step is to select a file Different files have different programs which generate different behavior To select a file click and hold your mouse on the File button highlighted below A menu of all of the possible files will appear Select the file named move to food Ealer Control You can also pick a color for your eater by clicking on the button to the right of Color labeled red The color does not affect on the eater s behavior so pick your favorite color 03 16 01 Soar Tutorial Once you have selected the path the file and a color you are ready to create your eater by clicking the Create Eater button After clicking on Create Eater two new windows will appear Arrange the Eater windows so that they do not overlap One of the new windows is the Interaction Window The Interaction Window will look as shown below
Download Pdf Manuals
Related Search
Related Contents
Playmobil Car Repair Shop and Race Car with Headlights 4365 Ubiquiti Networks XTREME Range 5 カタログ(1.7 MB) Fujitsu 11000304 GE GDF510-540 User's Manual Copyright © All rights reserved.
Failed to retrieve file