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 simulation.
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.