Runtime rule selection

You can define a selection filter on a rule task to specify dynamically what rules of the rule task must execute.

You specify the rules selected at run time in the Rule Selection tab of the Properties view. You can select individual rules, or packages containing several rules, that are considered for execution in this rule task, and filter out some of them. You can specify this filter with dynamic or static BAL constructs, or IRL. The filter is applied at run time, and the rule engine runs only the rules that pass through the filter. If you use the Fastpath algorithm, the conditions of the other rules might also be evaluated.

Note:

An empty list of rules and packages means that all the rules from the project are selected for execution at run time.

Selecting rules with BAL

Typically, the filtering process is based on the values of rule properties and execution parameters. The filter tests each rule in the ruleflow task to determine whether the rule should be selected for execution. For example, the following code filters on the name of the rule and is called for every rule in the task.

the name of 'the rule' contains "Age"

You can further refine runtime rule selection by using specific BAL constructs such as is, is over, is under, to define hierarchical relationships between the rules (see Hierarchies).

With the decision engine, there is no difference between dynamic BAL and static BAL. The filter is evaluated each time the rule task is invoked. Candidate rules can be selected based on the ruleset parameter state. For example, you can specify that the expiry date of the rule is after the date of the loan.

With the classic rule engine, you can set runtime rule selection to use either dynamic BAL or static BAL. The selection method changes the way the filter is applied to the rules.

  • With dynamic rule selection, the filter is evaluated each time the rule task is invoked.

  • With static rule selection, the filter is evaluated only the first time the rule task is called.

Selecting rules with IRL

You can select rules directly in IRL in the following ways:

Static body

The list of rules is specified simply by including the names inside the rule task body.

body = { R1, R2 }
Static body using the select keyword

Here is an example of selecting rules using the select keyword:

body = select(?rule) { <boolean returning code> }

This first example shows that a body of the rule task can be an IRL predicate that selects the relevant rules among all the rules of the ruleset.

In this second example, the specification selects all the rules available in the ruleset:

body = select(?rule) { return true; }

With the classic rule engine, the rules are selected only once regardless of how many times the rule task is executed.

Important:

With the decision engine, there is no difference between dynamicselect and select. select behaves the same way as dynamicselect where the statement is called each time the task is executed.

Dynamic body

The list of rules is selected by a function-like expression that takes an IlrRule object as its argument and evaluates to a Boolean expression. The pseudo-variable ?rule represents the IlrRule argument of the expression. This filter applies to each rule in the ruleset each time the rule task is activated. Hence, this expression might well depend on environment variables such as ruleset parameters or fields whose values can change between two executions of the rule task.

body = dynamicselect(?rule) {
      return myRuleSelection(?rule);
   }
Dynamic body in a domain

The domain is an expression that evaluates to a Java™ array or collection of IlrRule objects. The dynamic body is also an expression. You can use expressions to select the subset of the rules of the domain for the next rule task execution. The dynamic body is evaluated each time the rule task is activated.

It accepts two different signatures.

  • Dynamic body that returns a collection of rules:

    The dynamic body is an expression that evaluates to a Java array or collection of an IlrRule object.

       body = dynamicselect() {
          return myRuleDomainSelection();
       }
       in myInitialRuleDomain();
    Attention:

    There is no check at run time that the collection of rules returned by the dynamic body is really a subset of the initial rule domain. You must enforce such verification.

  • Dynamic body that returns a Boolean value:

    The dynamic body is a function-like expression that takes an IlrRule object as its argument and evaluates to a Boolean expression. The pseudo-variable ?rule represents the single IlrRule argument of the expression. The engine passes to this rule filter only the rules that belong to the initial rule domain.

       body = dynamicselect(?rule) {
          return myRuleSelection(?rule);
       }
       in myInitialRuleDomain();

    See Memory consumption reduction for more information.

Scope

The scope defines in a symbolic way what rules compose the body of a rule task. This provides a simpler way of describing the selection than using IRL expressions such as an in expression. The scope makes use of the package organization.

Note:

Because the IRL in expression and the scope provide alternate selection methods, you cannot use them together.