| Reference > Rule Languages > ILOG Rule Language > IRL Keywords > evaluate |
evaluate |
PREVIOUS NEXT |
A left-hand side statement for specifying tests on objects. This topic is used in rule conditions.
evaluate (expression);
The evaluate statement is used in the condition part of a rule to test objects of the working memory. An evaluate statement must have a simple condition preceding it that binds a variable to an object or a value. Any such variable bound to an object or a value may be tested. Note that the statements not, exists, and collect are not simple conditions. An evaluate statement is true if all the tests carried out in the expression are true. The expression may be multiple tests enclosed by braces ({}).
In the case where the condition part of a rule ends with an evaluate statement, the action part can have an else part, executed if the evaluate statement returns false. If it returns true, the then part is executed.
The evaluate statement differs from the not and exists statements. The not and exists statements apply tests only within the scope of their statement. The evaluate statement is more general in that it specifies tests that must be satisfied by the objects that exist in the working memory.
rule CloseOrder {
when {
?s: CustomerShipment(?id:CustomerId; ?sl:shipmentList);
?o: CustomerOrder(?id==CustomerId; ?ol:orderList);
evaluate (?sl.isEqualTo(?ol));
}
then {
retract(?s);
insert Shipped(?o,currentDate());
}
};
rule CloseOrder {
when {
?s: CustomerShipment(?id:CustomerId; ?sl:shipmentList);
?o: CustomerOrder(?id==CustomerId; ?ol:orderList;
?sl.isEqualTo(?ol));
}
then {
retract(?s);
insert Shipped(?o,currentDate());
}
};
The two rules show equivalent ways of testing objects of the working memory. The first rule has two conditions followed by an evaluate statement. In the second rule the test of the evaluate statement is incorporated in the second condition.
For both rules, variable ?s refers to a CustomerShipment object, variable ?id returns the field CustomerId, and variable ?sl returns the field shipmentList. In the second condition, variable ?o refers to a CustomerOrder object where the CustomerId field matches ?id and variable ?ol contains the field orderList. The evaluate statement calls a test, the method isEqualTo, defined in either the CustomerShipment class or the IlrContext class, which returns true if the two lists contain the same elements. If the conditions are true, the action part is executed. The CustomerShipment object is deleted from the working memory using the retract statement, and a Shipped object is inserted into the working memory using the insert statement.
else (in if), exists, instanceof, isknown, isunknown, not, rule
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |