Reference > Rule Languages > ILOG Rule Language > IRL Keywords > before

Summary

A binary temporal constraint in an event condition. This keyword is used in rule conditions.

Syntax

[?var:] event className(?eventVar1 before [interval] ?eventVar2);

Description

The before keyword is used in the condition part of a rule in an event condition. A temporal constraint between two events is expressed using the after and before keywords. An interval is of the form [lowerBound, upperBound], where a bound is either an expression evaluating to an integer, or the $ sign which denotes infinity. Consider that the timestamp of ?event1 is t1 and that the timestamp of ?event2 is t2.

The before operator can be expressed as follows:

  1. ?event1 before[min,max] ?event2
  2. is satisfied if the value of t2 - t1 is between the values of min and max, inclusive.
  3. ?event1 before[min,$] ?event2
  4. is satisfied if the value of t2 - t1 is greater than or equal to the value of min.
  5. ?event1 before[$,max] ?event2
  6. is satisfied if the value of t2 - t1 is less than or equal to the value of max.
  7. ?event1 before ?event2
  8. is satisfied if the value of t2 - t1 is positive or null.

Example

rule ReportAlarmPairsToUsers {
   when {
      ?u: User();
      ?a1: event Alarm();
      ?a2: event Alarm(?a1 before[1, 4] ?this);
   } then {
      ?u.report(?a1, ?a2);
   }
};

Assume that a User instance is in the working memory and that an Alarm instance is inserted. A partial instance of the ReportAlarmPairsToUsers rule will be created and maintained for 4 ticks. If the User instance is then retracted, the partial instance of the rule will be immediately deleted. An instance of the ReportAlarmsToUsers rule is created on each instance of the User class in the working memory when ?a1 is no greater than 4 ticks before a second alarm event ?a2 is inserted.

See Also

after, event (in rule conditions), occursin, timeof