If you want to monitor a certain condition and execute an action when this condition becomes true - use condition triggered event.To add a condition triggered event
Name – The name of the event. The name is used to identify and access the event.
Show name – If selected, the name of the event is displayed on a presentation diagram.
Ignore – If selected, the event is excluded from the model.
Visible - If selected, the event is visible on a presentation at runtime.
– The event's trigger type:
Timeout – The event is timeout triggered. The event occurs according to the chosen Mode.
Rate – The event is rate triggered. The event occurs with the specified Rate.
Condition – The event is condition triggered. The event occurs when the specified boolean Condition becomes true.
Mode – [Visible if Trigger type is Timeout] Choose here the mode of the timeout triggered event:
– The event will work in manual mode. It will occur only when the user calls the event’s restart function passing the timeout as the argument, for instance
If the timeout is fixed, you can define it once in the Timeout property and simply call myEvent.restart() without specifying the timeout as a function parameter.
– The event will occur only once exactly in the specified
Occurrence date. You can define the occurrence time as a calendar date (choose
Use calendar dates) or as a number of model time units to be passed from the model start (choose
Use model time).
Please note that here you define the absolute time and in the case the event will be created after the specified time, it will never occur.
– The event will occur cyclically. You define the
First occurrence time (absolute)
for an event. The first occurrence time can be defined either as a calendar date (choose
Use calendar dates), or as a number of model time units to be passed from the model start (choose
Use model time).
Please note that you define absolute times. If you want to use relative times (i.e. count the first occurrence time from the moment this event will be created), use time() function in the First occurrence time (absolute) property. time() will refer to the moment this event was created at..
Timeout – [Visible if Trigger type is Timeout and Mode is User control] The expression evaluating the timeout that should pass from the moment when the user starts the event by calling its restart() function.
Use model time - [Visible if Trigger type is Timeout and Mode is Occurs once or Cyclic] If selected, the event will occur at the specified model time.
Use calendar dates - [Visible if Trigger type is Timeout and Mode is Occurs once or Cyclic] If selected, the event will occur at the specified calendar date.
Occurrence time (absolute) – [Visible if Trigger type is Timeout, Mode is Occurs once and Use model time is selected] The absolute time of event occurrence defined as a number of model time units to be passed from the model start.
Occurrence date - [Visible if Trigger type is Timeout, Mode is Occurs once or Cyclic and Use calendar dates is selected] The calendar date and time of the event.
First occurrence time (absolute) – [Visible if Trigger type is Timeout, Mode is Cyclic and Use model time is selected] The absolute time of the first occurrence of the cyclic event, defined as a number of model time units to be passed from the model start.
Recurrence time – [Visible if Trigger type is Timeout and Mode is Cyclic] The recurrence time of the cyclic event.
Rate – [Visible if Trigger type is Rate] The rate triggering the event. Event will occur with the timeout distributed exponentially with the parameter rate. I.e. if the rate is 5, event will occur on average 5 times per time unit.
Condition – [Visible if Trigger type is Condition] The condition triggering the event. Event will occur when the specified Boolean expression is true.
Log to database – If selected, information on all event occurrences will be logged into the model execution log events_log.
Java code to be executed on event occurrence.
By default condition triggered event occurs only once, when the specified boolean condition becomes true for the first time. Once occurred, the event does not monitor its condition anymore. Such behavior is implemented to prevent simulation loops, when the condition stays true, and the event's action code is executed again and again infinitely often.
However, in some cases you may need to continue monitoring the specified condition to detect when it will be met again.
If you want your event to continue monitoring the condition after the event has occurred once, end the Action of this event with the code string event.restart();
To eliminate immediate triggering of this event, please do not forget to set the condition, that triggers this event, to false (do it in the same Action field just before restarting the event).
Condition triggered event occurs when the specified Boolean condition is true. If the condition is initially true, the event occurs immediately. Otherwise, it becomes enabled as soon as the expression becomes true.
It is important to understand, when an event's condition is checked by the model.
When specifying a condition, you should keep in mind the so-called sensitivity problem. Let the event wait for the Boolean condition x>=5, and let x changes continuously in time as shown in the figure below:
As the numeric equation solver works by steps, it may happen that x will exceed the value 5 and get back in between the two steps. In this case the change event will not be detected. You should be aware of such situations when modeling systems where such error might be critical. If you encounter such a problem, you should make numerical method accuracies smaller.
You can control the condition triggered event programmatically via its API:
void reset() - Cancels the currently scheduled event, if any. Stops waiting on the condition, (this can be later on resumed by calling restart()).
void restart() - Resumes waiting on the condition. Can be called in the event action or when event is inactive.
Timeout triggered event
Rate triggered event
API reference: EventCondition class