AnyLogic supports special type of functions - table functions. A table function is a function defined in the table form. You can simply make it continuous by interpolating and/or extrapolating. You may need table functions to define a complex non-linear relationship which cannot be described as a composition of standard functions, or to bring experimental data defined as a table function to a continuous mode.
Table function works in the following way: the user defines a function by giving a number of (argument, value) pairs, i.e. a number of base points on XY chart. AnyLogic builds the table function based on the given data and the chosen interpolation type. A call of a function with some value passed as a function argument, will return a (possibly, interpolated) value of the function. A number of behaviors are supported for the case x, which is out of original argument range.
To define a table
function
- To load table data from the existing Anylogic database, check the Loaded from database option and select the DB table from the Table drop-down list. If needed, define the conditions specifying the particular value you want to select from the database table in the Choice conditions option. Specify the Argument column and Value column by selecting the database table columns from the drop-down lists.
- If you have table data already defined in any other application or a file, you can simply copy it to clipboard and then paste it into the Table Data using the Paste from Clipboard button. Make sure to previously uncheck the Loaded from database option.
- You can also enter the table data manually into the table (that is shown in the Table data properties section if the Loaded from database option is unchecked). Each "argument-value" pair is specified in an individual row of the table. To define pair of values, go to the last row of the table and enter the argument value in the Argument cell and the function value in the Value cell. To remove a pair of values, select the corresponding row of the table and click the Delete button. You may sort entries by argument (in ascending order) by clicking the Sort button.
Name – The name of the table function. The name is used to identify and access the function.
Show name – If selected, the function name is displayed on a presentation diagram.
Ignore – If selected, the table function is excluded from the model.
Visible – If selected, the table function's icon is visible on the presentation at model runtime.
Interpolation – Specifies how the table function is interpolated:Table – Can be used to manually define data of the table function. Each Argument-Value pair is specified in an individual row of the table. You can add , remove , arrange ( , ) a pair of values, paste it from the clipboard or copy it to the clipboard.
Static – [Only visible
if Library
developer mode is enabled] If selected, the table function is static. Static function is
initialized once and has the same data for all instances of this agent
type. This is very useful in agent based models, in case your agents
have some table function defined. Making a table function static,
AnyLogic engine does not waste time on initializing this function
several times for numerous agents.
System dynamics units – If selected, you will be able to specify units of measurements for the value returned by this function in the edit box to the right. Having specified units for elements of your model, you may perform unit checking to find out dimension inconsistencies in the model.
To get the value of a table function for some argument, call the table function as any other function by its name, passing the argument value as the function parameter. For instance, if you have a table function named lookup1 in your model, to get the function value for the argument 5, call:
lookup1(5);
Alternatively, you can use the function get(double x) of the table function. For the example, considered above, the function call should be:
lookup1.get(5);
Both functions are identical. They return the table function value corresponding to the given argument, subject to the currently set interpolation type and out of range handling. In case the function only supports discrete values (that were provided as the argument set), and no interpolation is allowed, a call of such a function with an argument not matching any argument entry would result in exception thrown.
Table function can be interpolated.
To set up the function
interpolation type
The possible interpolation types are listed below.
If you want to get a smooth curve, the spline interpolation is the best. However, it takes more time to calculate a spline interpolation than a linear one. So, if a discontinuous function is acceptable, use the linear interpolation.
Interpolation type |
Description and Example |
None |
No interpolation applied. |
Step |
Step interpolation. The function value between two points is the same as in the point with less argument value. |
Linear |
Linear interpolation. The points are connected with straight-line segments. |
Spline |
4^{th} order spline interpolation. The points are connected with 4^{th} order polynomial segments. For each point 0^{th}, 1^{st}, and 2^{nd} derivatives of right and left segments are equal. The 2^{nd} derivative in the ending points equals zero. |
Approximation |
The resulting function is a polynomial of Order you specify in the edit box on the right, formed in order the sum of the root-mean-square error in the points is minimal. |
The feasible area of a table function is the function’s range, if the function is interpolated; or it is the defined set of points only, if no interpolation is set. You should define what should happen if a table function argument lies out of feasible area. Supported behavior types are the following: