A function decorator used to register an Event. When triggered, an event stores the data output at that time and registers on the visualizer. TimeSeries
, for example, draws a vertical line on the plots (see the image to the right), and Charts
will flash the background. In the image to the right there are two events, marking the increase and leveling off of population.
This decorator can be used bare (i.e. without parentheses) on a function whose name will be used as the event name. It can also take arguments, which are passed to Events.add()
.
The decorated function will run at the end of each period, immediately after data collection but before the modelPostStep
hook.
Parameters
name — str, optional
An optional reference name, to override the function name.
Default value: None
repeat — bool, optional
Whether the event should trigger once, or every time the criterion is satisfied.
Default value: False
**kwargs — optional
Further options to be passed to the visualizer's
event()
method.TimeSeries.event()
, for example, draws a vertical line on the plot area, and takescolor
,linestyle
, andlinewidth
arguments to customize its appearance.Default value: {}
charwick
Dec 14, 2020 at 22:05The image above is generated by the following two events, the first of which fires when the increase in population over the last 20 periods is greater than 3, and the second when the first has triggered and the increase in population over the last period.
The second is an example of ordering events: the second will only fire after the first.
charwick
Dec 14, 2020 at 22:08The decorated function can be written so as to take an action when the event is triggered, as in the following:
charwick
Dec 14, 2020 at 22:12Models can be set to stop at an event, by setting the
stopafter
parameter to the name of an event, as in this example from the walkthrough, which terminates the model once the volume of trade for each good is under 20.