AnyLogic provides several ways of changing values of parameters and variables:
There are some common rules for all these ways:The simplest way of modifying values of parameters and variables at model runtime is to use inspect windows. Inspect windows allow users to modify values of:
You can also modify a variable/parameter by associating it with a control and changing the control at model runtime.
The table below lists controls that can be linked to variables and parameters:
Control |
Can be associated with variable/parameter of type |
Comments |
|
boolean |
When you select the check box, the associated variable/parameter becomes true, when you clear it - false. |
|
String, double, int |
In some cases it may be more convenient to modify variables and parameters of the
int
type with sliders. |
|
double, int |
In some cases it may be more convenient to modify variables and parameters of the double type with edit boxes. |
|
int |
The first choice corresponds to value 0, the second - to 1, and so on. |
|
String |
Can be editable or fixed - in the latter case, the choice is limited to a defined set. |
|
String |
If you choose the Multiple selection option, the list box cannot be linked to variables and parameters. |
To modify value of a variable/parameter using a control
You can take a look at the simple demo model where the value of a parameter is modified with the slider.
Demo model: Slider Linked To Parameter
Either parameters and variables can be accessed from code simply by their names, e.g.: parameter, plainVar.
You can modify their values programmatically by typing the corresponding lines of code in actions of events and statechart transitions, functions, action parameters of your flowchart objects, etc.
To modify the value of a scalar variable, use the simple assignment operator, e.g. plainVar = 10;
In the case of, say, variable - array of int values (variable plainVar with typeint[] and initial value new int[5]), to assign 10 to the first element of this array, you should call the code line plainVar[0]=10;
You can change a parameter programmatically in the same way as a variable, using the simple assignment operator, e.g. parameter = 10;
If, however, you want this modification to be propagated down along the parameter dependencies, you need to call the
set_parameterName()
function (in our case,
set_Parameter()
) automatically generated by AnyLogic, passing the value you want to assign as a function parameter.