| Reference > Rule Languages > ILOG Rule Language > IRL Keywords > priority |
priority |
PREVIOUS NEXT |
A rule header property that controls the sequence of rule execution. This keyword is used in rule properties.
priority = {maximum|high|low|minimum|expression};
A rule header may contain a property priority. The priority may be an integer expression. If not specified, the value 0 is used as the default priority.
The priority of a rule determines its position in the agenda. The priority can be static or dynamic.
A static priority may be used to alter the sequence of rule execution among different rules. Static priorities are any integer between -109 and +109. The larger the number, the higher the firing priority of the rule. Four predefined constants of the IlrPriorityValues class are provided to be used as static priorities. They have the following values:
When rules have the same priority, a conflict set resolution strategy is applied. Rules are processed in the agenda according to the order by which they are listed. Rules are listed in the agenda with most recently inserted being before less recently inserted. For rules inserted at the same time, the order the rules appear in the agenda corresponds to the order the rules appear in the ruleset source file.
A dynamic priority may be used to alter the order of execution between several instances of the same rule, when several rule instances are in the agenda. Dynamic priorities are expressions whose value depends on variables bound in the condition part of a rule. All variables defined in the condition part of the rule and whose scope is global, that is, for the entire rule, can be used in the expression. If the expression returns a noninteger, it is converted into an integer following the Java language specification. The predefined priority values may be used within an expression, for example priority = high + ?p.
rule StaticExample {
priority = high;
when ...
then ...
}
The rule StaticExample has a static priority value of high, meaning it will be listed in the agenda before rules with a priority lower than 1,000,000.
rule ActiveStockByChange{
priority = ?c;
when {
?s:Stock(?p:currentPrice; ?l:lastClosingPrice;
?c = (?p-?l)/?l);
}
then {
System.out.println(?s.symbol +" : price: "+ ?p +
" change: "+ ?c);
}
The rule ActiveStockByChange has a dynamic priority equal to the percent change of the stock price. This means that for all the Stock objects of this class, the order of rule execution will be according to the change in price. The larger the positive change, the earlier the rule will fire. The larger the negative change, the later the rule will fire.
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |