Data builtins report the value of model variables at a particular time in the simulation.
This section describes the following builtins:
The ENDVAL builtin returns the ending value of input, from the most recent simulation run in a session with a model. You can use any expression for input, though it will typically just be a model variable or SELF. The first time you run the model after opening it, ENDVAL will return the initial value you've specified. If you don't specify an initial value, ENDVAL will return the initial value of input during the first run.
Example:
Is_Performance_Improving = Current_Performance_Indicator -
ENDVAL(Current_Performance_Indicator,0)This will look at the current performance, relative to the ending value of performance in the last simulation run of a given simulation session. In so doing, ENDVAL provides a mechanism for looking at run-to-run performance changes, and thus can provide a vehicle for triggering "as-needed" coaching to the model consumer.
You can use ENDVAL(SELF,init_val) to capture the value of a variable at the end of the previous run. This can be used to implement a custom version of RUNCOUNT as in:
My_RUNCOUNT = IF reset <> 0 THEN 0 ELSE ENDVAL(SELF,-1) + 1
Note You must include an explicit initial value when using SELF.
When you're editing a model, the ENDVAL function will reset (return the initial value) when you make changes to the equation using it directly, or through actions such as changing array definitions. In this case, it will act as if there is no previous run in the session.
Note Publishing a model from the interface will also cause ENDVAL to reset.
The HISTORY builtin returns the value of a variable at a prior time in the current run, or in another run (from the model or imported). <variable> is a model variable and <time> the time at which to get the value. If <time> is greater than the current time, or less than the first time available, HISTORY returns 0 unless the optional <run> parameter is used.
If the options argument <run> is used then HISTORY returns the value of the variable from another run. 0 is the current run (so that HISTORY(var,t,0) is the same as HISTORY(var,t)), 1 is the first active run as shown by the Data Manager, 2 the second and so on. Negative numbers can be used for the previous run as discussed below.
The <source> argument determines which run list to use. 0 is the active run list. 1 is the saved run list as shown in the Data Manager and -1 changes the meaning of <run> to be relative to the current run, so that 1 is the previous, 2 the run prior to that and so on. Alternatively, you can pass a negative value for <run> and leave <source> off to get this result.
If the <run> and <source> values specified do not identify a valid run HISTORY will return NAN. You can use the ISNAN builtin to check this. If <time> is before the start of the identified run the first value from the identified run is used, is after the last value.
By default, HISTORY will interpolate data. You can, however, specify that it return NAN except when time is within DT/2 of actual data points (this is the same logic as the Raw option discussed in Import Data dialog box. To do this use a decimal value of .5 in the <source> argument. For example HISTORY(population,TIME,1,0.5) would get the population points that exist in the first run, and return NAN at all other times.
Note The <run> and <source> parameters are evaluated only during initialization. If their values change during a run it will have no effect.
Note: HISTORY (stock, TIME-1) is the same as DELAY (stock,1).
The INIT builtin takes the initial value of the stock, flow, converter, or expression, where the initial value for the variable has been calculated at the outset of a simulation.
Examples:
Distance_Traveled = Position - INIT(Position)
Computes Distance Traveled as the difference between current position and the initial value of position.
Debt_Ratio = Debt/INIT(Debt)
Computes Debt Ratio as the ratio of Debt to its initial value. When creating graphical functions, it's often useful to normalize the input to the graphical function in this manner.
The PREVIOUS builtin returns the value of a variable or array at the previous time in the simulation. When there's no previous time, it returns the <initial> value.
Examples:
PREVIOUS(A, 0) returns the value of A at the previous time, or returns 0 if there's no previous time.
PREVIOUS(SELF,2) returns the value of the current variable at the previous time, or returns 2 if there's no previous time.