ReteOO Algorithm:
ReteOO algorithm is enhanced version of Rete algorithm. Rete is a Latin word which means Network.
ReteOO is an efficient pattern matching algorithm that compares large collection of object (facts) with large collections of pattern. Rete Algorithm can be broken into two parts: Rule Compilation and Runtime execution.
1) Rule Compilation :
Rule Compilation describes how the rules in production working memory are used to filter the data as it propagates through the network. Below diagram better describes about the simple Rete Network:
How does ReteOO Algorithm Work?
Rete Algorithm is responsible for matching facts against the rules in Pattern Matching Production System. ReteOO Algorithm has the some of the important components:
Root Node: Root node is the first entry point for all the facts. If there is no entry point defined, then it would be DEFAULT entry point. It’s act an interface for passing all the facts to Object Types Node. It applies the Rete algorithm to fact before passing it to Object Types Node.
Object Types Node: Object Types Node is the node that distributes the load to the down layer nodes. Object type node will specify the type of node it is filtering. E.g.:
age org.critasdemo.rule
import org.critasdemo.model.Customer;
rule "Set Address Match True for Customer"
#Name of the customer can pick dynamically, I have hard coded just for reference
when
#condition
Customer: Customer ($name == “Vikas”)
then
#action
List<Address> addresses = customer.getAddresses ();
for (Address address : addresses) {
address.setMatch(true);
}
end
This rules to set the match value true for all the customers whose name is Vikas. In this case, Object Type specified is org.critasdemo.model.Customer.
Alpha Node : Alpha nodes are the node which is used to filter the facts (data) fields.
Left Input Adapter Node: This is used to transform single object that was propagated from Alpha node to Tuples that contains this single object. This all needs to be done to reach to the terminal nodes to activate the rules.
Terminal Node: This node is used to activate the rules. This will get the agenda and create an activation item with the left tuples that contains the fact handlers with the matched object.
Characteristic of RETEOO Algorithm:
- It stores the partial matches when performing the joins between fact types. This allows Production System to avoid re-evaluation of facts each time changes are made to Production System Working Memory. Production System will only evaluate the changes made to working memory.
- It efficiently removes the memory element when Facts are retracted from Working Memory.
This article is for basic understanding of the ReteOO Algorithm. Please follow JBPM documentation for core understanding of the Rete Algorithm. Happy learning :)