Building a Rules Base


Building a rules base is not a simple task, but there are a number of ways to simplify the task.

Rules should be logically ordered based upon their context. For example, rules that have similar antecedents could be placed together since they are attempting to deduce the same or similar facts from the working memory. Similarly, rules that share similar consequents could also be grouped together since they result in similar actions (represent similar deductions).

For complex rule bases, state machines can be introduced using staging elements. For example, consider the following two rules in Listing 8.25.

Listing 8.25: Example of Staging Rules.
start example
 (defrule stage1-check       (stage stage1)       (battery-temp low) =>       (add (check battery-temp))       (delete (stage stage1))       (add (stage stage2)) ) (defrule stage2-check       (stage stage2)       (battery-temp low) =>       (add (check battery-pressure))       (delete (stage stage2)) ) 
end example
 

We've introduced the "(stage stageX)" facts as markers. Instead of acting as simple information in the working memory, these facts act as guards for the rules. Neither of the rules is considered unless the staging rule matches.

Finally, nothing beats pure testing. In order to fully test, there must be some way to introduce stimulus into the system. Outside of simply introducing facts through the init rule, time-triggered rules can also be used to simulate the addition of facts asynchronously. Recall from Listing 8.2 the use of time-triggered events to simulate sensor failures.




Visual Basic Developer
Visual Basic Developers Guide to ASP and IIS: Build Powerful Server-Side Web Applications with Visual Basic. (Visual Basic Developers Guides)
ISBN: 0782125573
EAN: 2147483647
Year: 1999
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net