home
 
 
Reaction Rules
 
 


Reaction rules are, in a sense, AI's counterpart to the more general computer science concept of event-driven programming. In event-driven programming, the design of software is centered around the processes which happen in response to certain events-a mouse click, a change in stock prices, and so on. A "reaction rule" is a rule which fits into a rule-based system but which is designed to respond to a particular event. To understand how this might work, we first need to take a step back and look at the design of rule-based systems in general. Why do we use rule-based systems at all, when the same functionality could probably be obtained just through more conventional coding? The answer is that rule-based systems are based upon something called the Rete algorithm, which implements the kinds of things that rules have to do in a fast manner. If you had to go through your list of rules, and your lists of facts and objects, in detail every time when something changed in the world, it would be a major drag on computing time. The Rete algorithm, which was originally designed by C.L. Forgy, is a fast way of doing only the things which are relevant in a given situation. Most rule-based systems come with the Rete algorithm already implemented-the programmer doesn't need to concern him/herself with worrying about the Rete implementation but can focus simply on the problem at hand.

So, in a sense, rule-based systems are already to some extent event-driven. As we saw when we first talked about rule-based systems, the rules have a left-hand side, consisting of the conditions under which the rule is supposed to operate, and a right-hand side, consisting of the actions that it is supposed to perform. The rule responds to the events listed on its left-hand side, and the Rete algorithm ensures that this happens in an efficient.

Yet this is not always going to be enough. As we saw in the last edition on real time AI, there are times when a system has to operate under well-defined time constraints-that is, deadlines. How can we guarantee this in a rule-based system? One way is through the concept of "salience". The reaction rules-the ones which need to respond to particular events-are given a higher salience than other rules. Thus, when the Rete network (this is another term for the Rete algorithm) identifies a number of rules which potentially can execute at a given time, the higher salience ones are given priority. This can work well under certain circumstances, where all that is needed is the ability to respond quickly. Yet there can be other circumstances where there is a well-defined deadline-you want to respond quickly, but not too quickly. How can a reaction rule take this into account?

Well, it can do so by establishing a particular deadline by which it needs to have a response. Then, when the deadline is reached, a second reaction rule is executed taking action. Let's illustrate this point with a simple example:

(defrule consider-offer  
  (offer-price 50.00)
(fair-value 49.9375)
(time 10:38:00)
=>
(assert (deadline 10:38:05))
(assert (best-decision sell))
   
)  
(defrule accept-offer  
  (time ?t)
(deadline ?t)
(best-decision sell)
=>
(best-decision sell)
   
)  

These are reaction rules (simplified for purposes of illustration) that might appear in an electronic marketplace for buying and selling stocks. In the first rule, "consider-offer", an offer comes in from another player offering to buy a stock (which we own) at 50.00. At the present time, we actually consider the fair value of the stock to be 49.9375, so this looks like a good deal for us. However, let's say the rules of this particular marketplace mean that an offer remains open for 5 seconds. It isn't necessarily to our advantage to act immediately. So instead we establish a deadline of 5 seconds in the future (by which time we have to act), and we also note that our current decision would be to sell. In the second rule, "accept-offer", five seconds have elapsed, and if nothing has changed, we do at this point decide to sell. So if nothing happens, we will sell in five seconds. But this allows for the possibility that another rule (not shown here) might execute in the meantime, changing our decision.

The biggest difference between these reaction rules and more standard rules is that they have a clear concept of time. Otherwise they can fit into a standard rule based system. Existing Rete technology doesn't necessarily handle time-based issues in an especially efficient manner; however, it would probably not be too difficult to extend the Rete approach to deal with time in as clear a manner as it handles everything else.

More information about Rete networks may be found at the Jess homepage. This site explains Rete (which is Latin for "net") from the context of the Jess language, which we've talked about in earlier editions. Jess is one AI language that uses Rete, but it is certainly not the only one. The rules given in the examples above are intended to look more or less like Jess.

 
  Home

Home: Ramalila.NET

 

 

Legals:
All copyrights are maintained by respective contributors and may not be reused without permission. Graphics and scripts may not be directly linked to. Site assets copyright © 2000 RamaLila.com and respective authors.
By using this site, you agree to relinquish all liabilities and claims financial or otherwise against RamaLila and its contributors. Visit this site at your own risk.