Show Table of Contents
5.2. Rule Evaluation With PHREAK Algorithm
When the rule engine starts, all the rules are unlinked. At this stage, there is no rule evaluation. The insert, update and deletes actions are queued before entering the beta network. The rule engine uses a simple heuristic, based on the rule most likely to result in firings, to calculate and select the next rule for evaluation. This delays the evaluation and firing of the other rules. When a rule has all the right input values populated, it gets linked in. That means, a goal representing this rule is created and placed into a priority queue, which is ordered by salience. Each queue is associated with an AgendaGroup. The engine only evaluates rules for the active AgendaGroup by inspecting the queue and popping the goal for the rule with the highest salience. So the work done shifts from the insert, update, delete phase to the fireAllRules phase. Only the rule for which the goal was created is evaluated and other potential rule evaluations are delayed. While individual rules are evaluated, node sharing is still achieved through the process of segmentation.
Unlike the tuple oriented RETE ,the PHREAK propagation is collection-oriented. So for the rule being evaluated, the engine accesses the first node and processes all queued insert, update and deletes. The results are added to a set and the set is propagated to the child node. In the child node, all queued insert, update, and deletes are processed, adding the results to the same set. Once finished, this set is propagated to the next child node, and so on until the terminal node is reached. This creates a batch process effect which can provide performance advantages for certain rule constructs.
This linking and unlinking of rules happens through a layered bit mask system, based on network segmentation. When the rule network is built, segments are created for nodes that are shared by the same set of rules. A rule itself is made up from a path of segments. In case when there is no sharing of the node, it becomes a single segment.
A bit-mask offset is assigned to each node in the segment. Also another bit mask is assigned to each segment in the rule's path. When there is at least one input, the node's bit is set to on state. When each node has its bit set to on state, the segment's bit is also set to on state. If any node's bit is set to off state, the segment is also set to off state. If each segment in the rule's path is set to on state, the rule is said to be linked in and a goal is created to schedule the rule for evaluation. The same bit-mask technique is used to also track dirty node, segments and rules. This allows for an already linked rule to be scheduled for evaluation if it is considered dirty since it was last evaluated. This ensures that no rule will ever evaluate partial matches.
As opposed to a single unit of memory in RETE, PHREAK has three levels of memory. This allows for much more contextual understanding during evaluation of a rule.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.