Agent may have parameters. Parameters are frequently used for representing some characteristics of the modeled object. They are helpful when object instances have the same behavior described in agent type, but differ in some parameter values. There is a clear difference between variables and parameters. A variable represents a model state, and may change during simulation. A parameter is commonly used to describe objects statically. A parameter is normally a constant in a single simulation, and is changed only when you need to adjust your model behavior.
All parameters are visible and changeable throughout the model execution. Thus, you can simply adjust your model by changing parameters at runtime.
Top-level agent parameters can serve as inputs for the model experiments. The Label defined for the parameter in the Value editor section will be used as a default name of the corresponding input. If a certain Control type is set for the parameter in the Value editor section, it will be used as the default control type for the corresponding input in the experiment dashboard. Note that you can use only Static parameters (defined in the Expert properties section) of int, double, boolean and String value types for the model inputs.
AnyLogic supports parameters of primitive types: double, int, boolean. Also AnyLogic gives you infinite possibilities to parameterize your objects by supporting parameters of any Java class.
You can define parameters of common Java classes — e.g., a parameter of String class to represent character strings. You can create a parameter of the Object class (the base class for all Java classes) and assign an instance of any Java class to this parameter. Later on you will need to check the actual type of this parameter and cast it explicitly to the original Java class. For details on Java classes, see Java SDK documentation.
Since all AnyLogic objects are instances of Java classes, you can define parameters of these classes and thus use AnyLogic objects as parameters.
You can define parameters of your own classes, defined elsewhere in your model.
To create a parameter
- Drag the Parameter element from the Basic Elements palette onto the graphical diagram of agent type.
- Go to the Properties view.
- Type the name of the parameter in the Name edit box. The name is used to identify and access the parameter.
- If your parameter defines one of the following: time, speed, length, acceleration, rate, or area, specify this explicitly by choosing the corresponding Type for this parameter. Then choose the Unit from the drop-down list below.
- Otherwise, specify the Java type for the parameter. You can choose one of the most-used types (int, double, boolean, String) using the corresponding option from the Type buttons group. If you need a parameter of some other Java class, choose the Other... option that will open the edit box, then type the required class name there.
- Specify the parameter’s default value in the Default value edit box. The value of the parameter can be changed afterwards during the model simulation using the set_parameterName(new value) function. If default value is not specified, Java rules apply, for example a parameter of type double is set to 0, a parameter of type boolean is false.
- General
-
Name — The name of the parameter. The name is used to identify and access the parameter.
Show name — If selected, the name of the parameter is displayed on a presentation diagram.
Ignore — If selected, the parameter is excluded from the model.
Type — [Visible if the Static or Dynamic option in the Expert properties section is selected] The type of the parameter. Choose a measurable type (Time, Rate, Length, Speed, Acceleration, Area, Amount, Flow Rate, Angle, or Rotation speed) or one of the Java primitive types (int, double, boolean, String) using the corresponding option from the Type list. You can select here any agent type that is defined in this model. If you need a parameter of some other Java class, choose the Other... option and type the required class name in the following edit box.
Unit — [Visible if the Type parameter is set to one of the measurable types (Time, Rate, Length, Speed, Acceleration, Area, Amount, Flow Rate, Angle, or Rotation speed)] The measurement units of the parameter value. The set of available units depends on the selected Type. For example, if Length is set as the parameter type, length units (inch, mile, meter, etc.) will be available for selection.
Default value — You can define the default value for the parameter here. The value of the parameter can be changed afterwards during the model simulation. If default value is not specified, Java rules apply, for example, a parameter of type double is set to 0, a parameter of type boolean is set to false.
Arguments — [Visible if the Dynamic or Action option in the Expert properties section is selected] Here you can define some optional arguments for your dynamic or action parameter to enable passing some additional input data necessary for parameter calculations.
Each row of the table specifies one particular argument. To remove an argument, hover the mouse over the corresponding row in the table and click the Delete row button to the right. Rearrange arguments in the table by hovering the mouse over the corresponding row and dragging up or down the icon displayed on the left. - Value editor
-
In this section of the properties you can customize the control that will be used to define the actual value of the parameter in the model.
Not yet supported in AnyLogic 9. - Expert
-
Static — If selected, the parameter is static, i.e. it is evaluated once, but may be changed during the model execution. In the field of a static parameter you can define its value (that can be cast to the type of the parameter).
Dynamic — If selected, the parameter is dynamic, i.e. its value is recalculated each time you assess the parameter and it acts as a function. Dynamic parameters are accessed using function-call notation: myParameter(), not myParameter.
Action — Dynamically executed code piece, evaluated each time a certain event occurs at the object.
System dynamics units — [System dynamics is not yet supported in AnyLogic 9] [Visible if the parameter is Static or Dynamic] If selected, you will be able to specify units of measurements for this parameter as system dynamics modelers do. Say, you define people as the SD units for this parameter in the edit box to the right of this option. Having specified units for all system dynamics elements of your model, you may perform unit checking to find out dimension inconsistencies in your model.
On change — [Visible if the parameter is Static] The code that will be executed on every parameter change. Please note that this code will be called only on set_<parameter name>() function calls (simple assignment like parameter=5; will not invoke the change handler). And the handler is also not executed in the case set_<parameter name>() function assigns the value equal to the actual parameter value.
Here in the code you can use the variable oldValue that stores the old value of the parameter (the value this parameter had before this particular change of the value).
If your parameter defines one of the following: Time, Rate, Length, Speed, Acceleration, Area, Amount, Flow Rate, Angle, or Rotation speed, you can specify this explicitly and define units for this parameter in a handy way.
For example, the following units are supported for Time and Speed:
- Time: milliseconds, seconds, minutes, hours, days, weeks, months, years.
- Speed: meters per second, kilometers per hour, feet per second, feet per minute, miles per hour, knots.
Just choose the corresponding Type, and then choose the Unit from the drop-down list below. Finally you have just to type the parameter’s value in the Default value property.
-
How can we improve this article?
-