Parameters or Variables: What to Use?

You can define agent data using parameters and variables. 


Parameters are usually used for defining some characteristics of the modeled object. They are helpful when object instances have the same behavior described in class, but differ in some parameter values. Generally, numeric parameters are used, while you can define a parameter of any Java class. 


Agent can contain variables. Variables are generally used to store the results of model simulation or to model some characteristics of objects, changing over time. AnyLogic supports two types of variables – variables and collections. 

variable is a simple variable of an arbitrary scalar type or Java class. 

However, you cannot set any formula for a variable. If you need a variable that changes its value according to specified differential equation, please use Stock. Otherwise, if you need a variable that changes its value according to some algebraic formula, please use dynamic variable. You can find both these variables on the System Dynamics palette. 

Collections are used for defining data objects that group multiple elements into a single unit. AnyLogic supports the following collections defined in the Java Collections Framework: ArrayList and LinkedList.

What to use: parameters or variables?

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. 

Use a variable instead of a parameter if you need to model some data unit continuously changing over time. Use a parameter instead of a variable if you just need to model some parameter of an object changed only at particular moments of time.

All parameters and variables are visible and changeable throughout the model execution, so you can simply adjust your model by changing them at runtime.