public class DecisionTableOptimizedAlgorithm extends Object implements IDecisionTableAlgorithm
nullThe goal of optimizations is to decrease the number of condition checking required to determine which rule actions need to be executed. Action optimizations are not considered, even though some improvements could be possible. Sometimes the best results may be achieved by changing the order of conditions(columns) and rules(rows) but these approaches will change the algorithm's logic and must be used with caution. We are not going to implement these approaches at this point, but will give some guidelines to users on how to re-arrange rule tables to achieve better performance.
Out of the class of optimization algorithms that do not change the order of conditions or rules we are going to consider ones that optimize condition checking in one condition (column) at the time. In decision table with multiple conditions the algorithm will create a tree of the optimized nodes. The time of the of the tree traversing will equal the sum of times required to calculate each node.
The optimization algorithms that deal with single condition can be classified as follows:
Both algorithms are single-condition(column) based. Both work only if rule condition expression does not change it's value during the course of DT evaluation. In other words, the Decision Table rules do not change attributes that participate in condition evaluation. For indexing the additional requirement is necessary - the index value should be known at compile time. It excludes conditions with dynamic formulas as cell values.
If a Decision Table does not conform to these assumptions, you should not use optimizations. It is also recommended that you take another look at your design and ask yourself: was it really necessary to produce such a twisted logic?
Generally speaking, it would be nice to have system automatically apply optimizations, when appropriate, would not it? In reality there are always the cases where one doesn't want optimization happen for some reason, for example condition calls a function with side effects.. This would require us to provide some facility to suppress optimization on column and/or table level, and this might unnecessary complicate DT structure.
Fortunately, we were lucky to come up with an approach that gives the developer an explicit control over (indexing)
optimization at the same time reducing the total amount of the code in the condition. To understand the
approach, one needs to relize that
a) indexing is possible only for some very well defined operations, like equality or range checks
and
b) the index has to be calculated in advance
For example we have condition
driver.type == type
where driver.type is tested value and type is rule condition parameter against which the
tested value is being checked. We could parse the code and figure it out automatically - but we decided to simplify
our task by putting a bit more responsibility (and control too) into developer's hands. If the condition expression
will be just
driver.type
the parser will easily recognize that it does not depend on rule parameters at all. This can be used as the hint that
the condition needs to be optimized. The structure of parameters will determine the type of index using this table:
| Expr Type | N Params | Param Type | Condition | Index Performance |
|---|---|---|---|---|
| any T x | 1 | T value | x == value |
Constant(HashMap) performance |
| any T x | 1 | T[] ary | contains(ary, x) |
Constant(HashMap) performance |
| Comparable T x | 2 | T min, T max | min <= x && x < max |
log(n)(TreeMap) performance |
| any T x | 2 | <in|not in> Enum isIn, T[] ary | isIn == in ? contains(ary, x) : !contains(ary, x) |
Constant(HashMap) performance |
| Modifier and Type | Method and Description |
|---|---|
IIntIterator |
checkedRules(Object target,
Object[] params,
IRuntimeEnv env)
This method produces the iterator over the set of rules in DT.
|
static IConditionEvaluator |
makeEvaluator(ICondition condition,
IOpenClass methodType,
IBindingContext bindingContext) |
void |
removeParamValuesForIndexedConditions()
Clears condition's param values.
|
public static IConditionEvaluator makeEvaluator(ICondition condition, IOpenClass methodType, IBindingContext bindingContext) throws SyntaxNodeException
SyntaxNodeExceptionpublic void removeParamValuesForIndexedConditions()
removeParamValuesForIndexedConditions in interface IDecisionTableAlgorithmpublic IIntIterator checkedRules(Object target, Object[] params, IRuntimeEnv env)
checkedRules in interface IDecisionTableAlgorithmCopyright © 2004–2019 OpenL Tablets. All rights reserved.