Difference between revisions of "Descrete events"
Ilya Kiselev (Talk | contribs) |
Ilya Kiselev (Talk | contribs) |
||
Line 7: | Line 7: | ||
==Behavior details== | ==Behavior details== | ||
Logic of events can be quite complicated. Time point at which event should be executed may be different totime point at which it is executed due to preset time delay. Events execution may affect other events causing them to trigger or deactivating already triggered events. If several events are to be executed at the same time - order of execution is managed according to their priorities which are represented by mathematical expressions and may also be changed when other events are executed. It should be noted that events may form infinite loop triggering each other, so model creator should be cautious while using events in models. | Logic of events can be quite complicated. Time point at which event should be executed may be different totime point at which it is executed due to preset time delay. Events execution may affect other events causing them to trigger or deactivating already triggered events. If several events are to be executed at the same time - order of execution is managed according to their priorities which are represented by mathematical expressions and may also be changed when other events are executed. It should be noted that events may form infinite loop triggering each other, so model creator should be cautious while using events in models. | ||
+ | |||
+ | When event is executed, for each assignment, right hand side is evaluated and assigned to correspondent variable. Values of variables used in right hand side are fixed before execution and thus order of assignments does not matter. Let's consider example: | ||
+ | <code> | ||
+ | :Before event execution: x = 1, y = 2, z = 3. | ||
+ | :Assignments: | ||
+ | ::x = y + 5, | ||
+ | ::y = x - 2, | ||
+ | ::z = z + 1. | ||
+ | :After event execution: x = 7, y = -1, z = 4. | ||
+ | </code> | ||
Event attributes: | Event attributes: |
Revision as of 16:26, 10 February 2017
General definition
Descrete events are used to instantaneously change values of model variables when given conditions are met. For example when model time reaches certain value or when boolean expression becomes true. Generally event consists of two parts: trigger - which defines conditions of event and execution - actions which should be performed after event is triggered. In BioUML events are handling according to latest SBML specification.
Events handling is independent from time course simulation and can be used in different types of models including ODE solving, stochastic simulation, algebraic models. Solver should be able to recognize that event was triggered, calculate specific time point at which it happened and stop simulation. Special wrapper solver EventLoopSimulator takes control, processes triggered events changes model variable values, reinits main solver and restarts it. Most solvers which are able to detect events have option Locate event which is set to true by default.
Behavior details
Logic of events can be quite complicated. Time point at which event should be executed may be different totime point at which it is executed due to preset time delay. Events execution may affect other events causing them to trigger or deactivating already triggered events. If several events are to be executed at the same time - order of execution is managed according to their priorities which are represented by mathematical expressions and may also be changed when other events are executed. It should be noted that events may form infinite loop triggering each other, so model creator should be cautious while using events in models.
When event is executed, for each assignment, right hand side is evaluated and assigned to correspondent variable. Values of variables used in right hand side are fixed before execution and thus order of assignments does not matter. Let's consider example:
- Before event execution: x = 1, y = 2, z = 3.
- Assignments:
- x = y + 5,
- y = x - 2,
- z = z + 1.
- After event execution: x = 7, y = -1, z = 4.
Event attributes:
- Trigger specifies conditions for event to occur. It is a mathematicla boolean expression from model variables. If during simulation this expression transits from false to true - event is considered as triggered. It is usually better to formulate trigger in terms of inequalities:
time > 9
,x+y > z
. - Assignments - list of assignments which should be performed when event is executed. Each assignment consists of variable and mathematical expression. When event is executed, expressions are evalueated and results are assigned to variables.
- Priority - defines order of events execution in the case when several events are to be executed at the same time. Prioity is a evaluated expression from model variables and is recalculated each time it is checked.
- Delay - defines time delay between event triggering and execution. Delay should be assgined by numerical value and can not be changed during simulation.
- Use trigger time values - if true then assignment expressions are calculated using values of variables at the time of triggering. If false - at the time of execution.
- Persistent tigger - if true then once event is triggered - it will be executed no matter what happends before execution time. If false and event tigger transits from true to false after event is triggered then event is considered switched off and will not be executed. Note that if then trigger will transit from false to true again - event will be triggered again.
- Trigger initial value - defines whether event may be triggered at the start of the simulation (i.e.
time = 0
). If set to true then event can not be triggered attime = 0
even if Trigger expression is true at this time. If set to false and trigger experssion evaluates to true attime
= 0 then event will be triggered.
Implementation
Processing of events done by EventLoopSimulator goes as follows:
- Check which events were triggered. Add all these events to the pool of pending events.
- Calculate prioirty for each of triggered events - choose one event with the highest priority, or if there are several events with maximal priority - choose one of them randomly.
- Process chosen event
- Recalculate triggers of all other events.
- If it was not triggered before step 3 but is triggered now (it was switched on by executed event) - add it to the pool of pending events.
- If event has Persistent trigger = false and its trigger expression evaluates to false - remove it from the pool (it was switched off).
- If list of pending events is empty - reinit solver and start it with new values. Else - goto 2.