Download AN INTRODUCTION TO SOAR PROGRAMMING

Transcript
Operators: Typical Use
Because they are the only way to make persistent changes to working memory, operators
are the key to any Soar program. The typical programming scheme for using operators
requires productions to do three things:
¥ propose the operator (IF condition-x THEN operator=foo)
¥ apply the operator (IF operator=foo THEN do things to memory)
¥ terminate the operator (IF not-x THEN reconsider operator=foo)
If you try to write a ÒsimpleÓ Soar program without using this scheme, youÕll almost
always run into problems with things being retracted from working memory before they
should.
HereÕs how the three kinds of productions typically sequence:
1. A proposer with Òstomach-state=hungryÓ on its IF side fires and puts [operator=eat +]
into preference memory.
2. The acceptable preference for ÒeatÓ is moved into working memory.
3. Assuming no other operators have been proposed, the ÒeatÓ operator is installed in the
operator context slot.
4. Now that ÒeatÓ is the operator, the operator-application productions can fire. They have
Òoperator=eatÓ on their IF side and Òstomach-state=hungry ÐÓ on their THEN side.
5. The preference-arbitration rules are applied to Òstomach-state=hungry +Ó, which was in
memory to begin with, and Òstomach-state=hungry ÐÓ. The result is that Òstomachstate=hungryÓ is removed from working memory. Now the production that proposed the
ÒeatÓ operator is no longer applicable, so the + preference for that operator disappears.
6. A terminator production fires. It has the form, ÒIF stomach-state is not hungry THEN
reconsider the eat operator.Ó
7. At the next decision cycle, the eat operator is reconsidered, and since the preference that
suggested it is gone, the operator is taken out of slot. Since Òstomach-state=hungry ÐÓ was
put into preference memory by a production that tested the operator, its effect will persist
after the operator is gone, and the eat operator wonÕt be proposed again.
Soar Language: Basic Syntax
HereÕs a typical production, written in the Soar language:
(sp suggest-lunch-agenda*friday
(state <s> ^day <d> ^agenda lunch)
(<d> ^name friday)
-->
(<s> ^operator <o>)
(<o> ^name eat-steak))
; production name
; IF side (LHS)
;
; THEN side (RHS)
;
The productionÕs name is like a subroutine name: defined by convention for programmer
readability, but not semantically meaningful to the system. Semicolons are comment
Soar Introduction
17