Databases Reference
In-Depth Information
The only remaining drawback with this approach is that the ruleset will still assert all
bid objects contained within the bidHistory element of auctionItem into working
memory. While this won't change the outcome, it still means all these bids will
be evaluated in the process of firing the rules, though none of them will cause an
activation to happen.
When we have only a relatively small number of facts this doesn't really cause a
problem, but if the number of facts is in the high 100s or order of 1000s, then this
may make a noticeable difference.
Using functions to control the assertion of facts
The reason that all facts are asserted into the working memory of the rule session is
that we specified (by checking the Tree checkbox) that the decision function should
assert all descendants from the top-level element for each of our input facts.
This causes the function assertTree to be called for each fact passed in by the
decision service (as opposed to assert ), which causes all the descendants of the
fact elements to be asserted at runtime.
An alternative is to leave this unchecked and write a function for each fact passed in
that asserts just the desired facts. So, in our case, we would write a function to assert
the winningBid element in auctionItem and all the bid elements contained in bids .
Summary
The business rules engine is built on a powerful inference engine, which it inherits
from its roots in the Rete algorithm. We spent the first part of this chapter explaining
how the rule engine evaluates facts against rules. The operation of the Rete algorithm
can be a challenge to completely understand, so re-reading this section may
be beneficial.
However, once you have an appreciation for how the rule engine works and can start
"thinking in Rete", you will have a powerful tool not just for implementing complex
business rules but also a certain type of service.
We demonstrated this by developing a complete ruleset to determine the winning bid
for an auction. Looking at the final list of rules, we can see that we needed relatively
few to achieve the end result and that none of these were particularly complex.
As is the case when implementing more typical decision services, we have the
added advantage that we can easily modify the rules that implement a service
without having to modify the overall application, giving us an even greater
degree of flexibility.
 
Search WWH ::




Custom Search