AnyLogic
Expand
Font size

Option list

Option list is the element for defining agent attributes that have limited choice of alternative options, e.g.:

  • Gender (male, female)
  • Marital status (single, married, separated, divorced, widow)

For example, you can define the agent’s gender attribute as a Gender option list with the following elements: Male, Female.

To create an option list

  1. In the Projects view, right-click (macOS: Ctrl + click) the model you are currently working with and choose New >  Option List… from the context menu.

  2. The New Option List dialog box opens. In the Name box, specify the name of the new option list. In our example the name is Gender.
  3. In the Specify elements table, type the names of the options (Male and Female).

  4. Click Finish to complete the process.

In the project tree, option lists appear on the upper level, grouped in the  Option Lists branch.

Having defined the option list, you can choose this list as the agent parameter’s type.

Now you can assign values (Male or Female) to the agent’s gender parameter.

To set a default value, specify an option list’s value in the parameter’s Default value field, e.g: Male.

To change the value at the model runtime, type gender = Female;

If you need to assign values for the whole agent population, you may do it e.g. in the top level agent’s Startup code.

Select one random option from an option list

For example, you have the option list named Gender. To randomly select one option from this option list, use one of the following functions:

  • randomFrom( Gender.class );
  • Gender.random( this );
How can we improve this article?