### Table of contents, ht.s8 ### ### i. Some simple things to help beginners ### I. Propose the top space ### II. Propose the main operators ### III. Implement the main operators ### IV. Noticing when full ### V. Operator Set-up ### VI. Better object traces ### ### Copyright 1994. F. E. Ritter & R. M. Young. ### ### ### 3-Feb-2003 Tony Kalus - changed for Soar8(.3) ### ### 4-Jan-98 Richard Young - Some clean-up and internal consistency ### - Also added monitor rule for hungry/thirsty ### 3-Nov-96 Frank Ritter - moved to soar 7.0.4 ### 27/7/95 Gary Jones - Altered references to to be . ### For example, state is now state . ### Just to make it easier to understand. ### Also put in learn -off (because it should be). ### ### 5/7/95 Gary Jones - NNPSCM conversion. ### ### ### Save as Text Only so that it can be loaded into Soar. ### ### A simple hungry-thirsty problem space and operators ### ### The code supplied has these characteristics: ### - The operators Eat & Drink are proposed iff they're ### applicable. that is, Eat if (^hungry yes), Drink if (^thirsty yes) ### - There are hand-written control chunks making Eat the best thing to do. ### ### Example command within Soar to get to this code and load it: ### ### Macintosh: cd "joe:EuroSoar7:tutorial" ????????????? ### Unix: cd "/aigr/staff/ritter/res/soar/euro-soar93/tutorial/" ?????????????? ### Windows: Use SoarWin to start Soar and the tsi ### Then: source "ht.soar" (no "") from the tsi Source tab. ### ### ### i. Some simple things to help beginners ### ## For safety, excise -all excise -all ## Resets the watch level to the base level in case you changed it: watch 1 echo "watch 1" learn -off echo "learn -off " ## Default is not to print chunks as learned! watch learning -print ## This makes chunk firings print watch -chunks -print ## What to do with sets of indifferent context elements: take the ## first one. indifferent-selection -first ## Upon reload, resetting the goal stack to be empty is usually ## required and is a good idea: init-soar echo "init-soar" ### ### I. Propose the top space ### ### The code in this section proposes a simple space to work in, and a ### simple state to start working in. (One 'big' rule) ### sp {ht*propose-space*ht (state ^superstate nil) --> ( ^name ht-state ^problem-space.name hungry-thirsty ^thirsty yes ^hungry yes) } excise {ht*propose-space*ht} ## ## Or you could do this... (two smaller rules) ## sp {ht*propose-space*ht (state ^superstate nil) --> ( ^name ht-state ^problem-space.name hungry-thirsty) } ## ## ...combined with this... ## sp {ht*init-state*ht (state ^problem-space.name hungry-thirsty) --> ( ^name ht-state) ( ^thirsty yes ^hungry yes)} ## You can put the closing brace on its own line. ### ### II. Propose the main operators ### ### The code in this section proposes the two operators eat and drink. ### The third production creates a preference for choosing between ### them. ## Propose eat. ## Note that you can write the RHS like this (the 'old' way, but it still works)... sp {ht*propose-op*eat (state ^problem-space.name hungry-thirsty ^hungry yes) --> ( ^operator ) ( ^name eat)} excise {ht*propose-op*eat} ## ...or like this (the 'new' way) sp {ht*propose-op*eat (state ^problem-space.name hungry-thirsty ^hungry yes) --> ( ^operator.name eat)} ## Propose drink. sp {ht*propose-op*drink (state ^problem-space.name hungry-thirsty ^thirsty yes) --> ( ^operator ) ( ^name drink)} ## Eat is better if you are hungry and want not to be sp {ht*compare*eat*better*drink (state ^problem-space.name hungry-thirsty ^hungry yes) ( ^operator +) ( ^name eat) ( ^operator +) ( ^name drink) --> ( ^operator > )} #excise {ht*compare*eat*better*drink} ### ### III. Implement the main operators ### ## Implement the operators with productions that modify the state once ## the operators have been selected. ## ## Note: We make the new value acceptable and reject the previous ## value. sp {ht*apply-op*eat (state ^operator ^hungry yes) ( ^name eat) --> (write (crlf) | chomp chomp... |) ( ^hungry yes - no +)} ## ## For older versions of Soar, you had to explicitly terminate ## the operator like this: (but now you don't have to) ## #sp {ht*terminate*eat # (state ^operator ) # ( ^name eat) # ( ^hungry no) # --> # ( ^operator @)} ## Implement drink sp {ht*apply-op*drink (state ^operator ^thirsty yes) ( ^name drink) --> (write (crlf) | glug glug... |) ( ^thirsty no + yes -)} ## ## For older versions of Soar, you had to explicitly terminate ## the operator like this: ## #sp {ht*terminate*drink # (state ^operator ) # ( ^name drink) # ( ^thirsty no) # --> # ( ^operator @)} ### ### IV. Noticing when full ### ### This code terminates the problem solving when the goal is reached. ## ## There are several ways to do this: ## ## We can determine that we are no longer hungry like this... ## sp {ht*evaluate*state*success*not-hungry-1 (state ^hungry { <> yes } ) --> (write (crlf) |Method 1 - Finished with hungry | ) (halt) } #excise {ht*evaluate*state*success*not-hungry-1} ## ## ...or like this... ## sp {ht*evaluate*state*success*not-hungry-2 (state ^hungry ^hungry no) --> (write (crlf) |Method 2 - Finished with hungry | ) (halt) } excise {ht*evaluate*state*success*not-hungry-2} ## ## ...or like this. ## sp {ht*evaluate*state*success*not-hungry-3 (state ^thirsty -^hungry yes) --> (write (crlf) |Method 3 - Finished with hungry |) (halt) } excise {ht*evaluate*state*success*not-hungry-3} ## ## Similarly, we can determine that we are no longer thirsty like this... ## sp {ht*evaluate*state*success*not-thirsty (state ^thirsty { <> yes } ) --> (write (crlf) |Finished with thirsty | ) (halt) } ## ...etc.... ### ### V. Better state traces ### ### To trace the hungriness & thirstiness, we use the following ### "monitoring" rules (they don't affect the processing, they ### just print out some information. ### These show how to use 'print statements' to show what is happening. ### However, with the TSI, you can also use the tabs (e.g. Working memory Elements) ### to see the same results. sp {monitor*top-state*hungry (state ^superstate nil ^problem-space.name hungry-thirsty) ( ^hungry ) --> (write (crlf) |** Top-state has ^hungry | )} sp {monitor*top-state*thirsty (state ^superstate nil ^problem-space.name hungry-thirsty) ( ^thirsty ) --> (write (crlf) |** Top-state has ^thirsty | )} ## need to do this to get a new line echo "" ###--------------------------------------------------------------- ### END OF FILE ###---------------------------------------------------------------