A Guide to Rules Engines for IoT: Forward-Chaining Engines
Want to learn more about forward-chaining engines in IoT?
Join the DZone community and get the full member experience.Join For Free
What Is a Forward-Chaining Rules Engine?
An inference engine using forward chaining applies a set of rules and facts to deduce conclusions, searching the rules until it finds one where the IF clause is known to be true. The process of matching new or existing facts against rules is called pattern matching, which forward chaining inference engines perform through various algorithms, such as Linear, Rete, Treat, Leaps, etc.
When a condition is found to be TRUE, the engine executes the THEN clause, which results in new information being added to its dataset. In other words, the engine starts with a number of facts and applies rules to derive all possible conclusions from those facts. This is where the name "forward chaining" comes from — the fact that the inference engine starts with the data and reasons its way forward to the answer, as opposed to backward chaining, which works the other way around.
How About Backward Chaining?
In backward chaining, the system works from conclusions backward towards the facts, an approach called goal driven. Compared to forward chaining, few data are asked, but many rules are searched. Backward-chaining rules engines are not suited for dynamic situations and are mostly only used as expert systems in decision making.
What Are Some Examples of Forward-Chaining Rules Engines for IoT?
Most of the IoT platforms on the market today actually have a rules engine of this type. Here are a couple of examples of automation tools built on forward chaining engines that are available on the market at the moment: RedHat Drools, Cumulocity, Eclipse Smart Home, AWS Rules, Thingsboard, and many more.
Should You Use Forward-Chaining Engines to Model Complex Logic?
Condition action rules engines provide a good framework for expressing conditional (Boolean) logic. However, combining multiple non-binary outcomes of functions (observations) in the rule is not possible with forward chaining engines, since conditions are applied on Boolean (true/false) outcomes.
Forward chaining engines “collapse” on the majority voting requirement almost immediately, since they search inference rules until they find one or multiple where the IF clause is known to be true. This means that several, potentially contradicting rules may fire at the same time and the engine needs to deal with conflict resolutions to decide which one to execute. Adding majority voting into this mix is too much to handle.
Conditional executions of functions based on the outcomes of previous observations are not easy, as forward chaining rules engines expect all data to be present at the moment rules are evaluated.
Are Forward Chaining Engines Explainable?
For simple problems, forward chaining engines provide us with an easy way to design rules. In fact, there is nothing easier to grasp than if-this-then- that type of rules! However, adding more conditional statements into a rule leads to very complex analyses, which hinder the understanding of the rule’s intent.
Moreover, the actual conditions of the rules, which often include thresholds and other Boolean expressions, are written and buried somewhere in the code, and are, as such, difficult to expose to the outside observer. As a workaround, during the design phase, rules are often represented as graphs with conditional outcomes modeled as labeled “arrows.” However, these graphs are nowhere to be seen or inspected once the rule is implemented.
Simulation, debugging, and decision tracking (why has the rule fired at runtime) is not a trivial task since the data determines which rules’ paths are selected and used. Moreover, as described earlier, the conflict resolution requires a priori selection of the conflict resolution strategy, which is not part of the rule but often a configuration parameter of the rules engine.
Are Forward Chaining Engines Adaptable?
Changing rules is possible with forward chaining engines but always problematic, as conflict resolution needs to be re-evaluated every time a condition in the rule changes.
Adding third-party API services to forward chaining engines is not a straightforward task and it is often accomplished directly in the code, leading to the API endpoints being directly coupled at the rule level. Since thresholds and other conditions are also often defined in the code, it is difficult to reuse the same API services across multiple instantiated rules.
How Easy Are Forward Chaining Engines to Operate?
Applying the same rule across many IoT devices, for example, is possible as long as thresholds and other conditions do not change across devices. Anything more complicated is extremely difficult to achieve with FC since many inputs to the rules are buried deep inside the code.
Are Forward Chaining Engines Scalable?
Forward chaining rules are stateless, which means that you can easily run multiple rules in parallel, but you can not distribute the load to different processes while executing one instance of a rule.
This is an excerpt from our latest Benchmark Report on Rules Engines used in the IoT domain. You can have a look at a summary of the results or download the full report over here.
Published at DZone with permission of Veselin Pizurica, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.