Font size

Static, dynamic, and code parameters

Parameter types

Parameters of all AnyLogic library blocks are of three types: static, dynamic and code parameters

Static parameters

Static parameter has a value, which you define in the Properties view. This value is evaluated once and stays the same during the whole model run. However, if required, the user can change the value at the model runtime by calling the corresponding function. The example: Capacity parameter of the Delay block.

In the Properties view, static parameters are marked with the icon.

Dynamic parameters

Dynamic parameter does not have a constant value. Its value is evaluated each time it is needed, e.g. each time the delay time, the speed or other property of an agent needs to be obtained.

Example: the Delay time parameter of the Delay block. It is evaluated for each agent, when the agent enters the block.

In the dynamic parameter’s field, you can specify a value, e.g. 5, or a Java expression that returns a value. It can be a call of a probability distribution function, e.g. exponential(0.1), or a call of the user-defined function. The expression must return a value of the required or compatible type.

You should put a semicolon at the end of Java expression, otherwise you may get a compilation error.

In the Properties view, dynamic parameters are marked with the icon. In documentation, dynamic parameters are marked with the similar icon.

Code parameters

Code parameters are usually located in the Actions section of the block’s properties. The name of the code parameter usually starts with the word On, for example, On enter. If you join these words together: Action on enter, you will understand the meaning of the parameter. Code parameter is actually the place where the user can define Java code, which will be evaluated in the certain moment of agent’s life within the block: the agent enters (like in our example) or exits the block, the pedestrian finishes servicing, conveyor stops, etc.

On contrary to dynamic parameter’s expression, in the field of the code parameter you should put a semicolon at the end of each line of Java code.

In the Properties view, code parameters are marked with the icon.


Type of parameter Block Parameter Example of value
Static Queue Capacity 15
Static Delay Agent location pathDelay
Dynamic SelectOutput Condition randomTrue(0.7)
Dynamic Service Delay time agent.amount * 60
Code Sink On enter
dataset.add( time() - agent.timestamp );
Code TrainSource Car setup
if( carindex == 0 ) {
   car.setShape( locomotive );
else {
  car.setShape( boxCar );

Local variables

Either in expressions of dynamic parameters and in code of code parameters you can use local variables. For example, in Process Modeling Library the most common local variable is agent. It refers to the current agent for which the expression (code) is executed. The similar local variable ped in Pedestrian Library blocks refers to the current pedestrian, in Rail Library you can use local variables train, track, etc.

You can see the list of available local variables by clicking in the parameter’s field and hovering the mouse over the bulb icon in the top left corner of the field.

Changing static parameter’s value at runtime

You can modify static parameters of library blocks dynamically at model runtime.

To change a value of some parameter, you should call the automatically generated function set_parameterCodeName(), passing the value you want to assign as a function parameter.

For example, to change the Capacity of Queue block to 50, you should call queue.set_capacity(50);

The code name of the parameter is not the label of the parameter that is shown in the Properties view. To obtain the code name of a parameter, refer to the Library Reference Guide. There you can find the full description of block parameters. Expand the parameter description by clicking the label, and you will see the required name in the Syntax line.

Here we talk about static parameters, not dynamic ones. Dynamic parameters are evaluated each time they are needed, e.g. each time the delay time, the speed or other property of an agent needs to be obtained, so they do not have any persistent value, and it is meaningless to speak about changing values of dynamic parameters.
How can we improve this article?