AnyLogic
Expand
Font size

Setting up parameters prior to model execution

Controls can be placed on the experiment’s front-end page and used to set up parameters prior to the model execution (as shown in the figure below).

The experiment’s presentation isn't displayed at model run by default. To make it visible, go to the experiment’s properties and deselect the Skip experiment screen and run the model option.

Let’s study this on the example of our model called Wandering Elephants. This model has the NumberOfElephants parameter defined in the Main top-level agent. This parameter defines the number of elephants. Let us enable users to set up this parameter from the simulation experiment page prior to the model execution.

To link a control on the experiment page to a parameter of the model top-level agent

  1. Open the diagram of the Simulation experiment (by double-clicking the  Simulation item in the Projects view).

  2. On the experiment page, add a slider to vary the number of elephants. Drag the  Slider element from the  Controls palette into the graphical editor.

  3. Configure the slider. In the slider’s properties, set the Minimum value, Maximum value, and Default value parameters of the slider. Click the Add labels... button to add labels to the slider that will display its min, max, and current values.
  4. Now we will link it to the parameter of the model’s top-level agent Main. Open the Parameters section of the Simulation experiment’s properties. Here you can set up values of all the parameters of the model’s top-level agent (Main).

  5. In the NumberOfElephants field, specify the actual value for this parameter by typing: slider.getIntValue(). Use code completion to type this code.

  6. Run the experiment and play with the slider. You will see that the number of elephants in the model is equal to the number that you have defined with the slider prior to running the model.

We have used the getIntValue() function of the slider here to get the current integer value of the slider and link it to the NumberOfElephants parameter of the Main agent.

You can use the same technique for other controls.

You use different functions, and the function name differs depending on the control and the value type of the parameter you are linking.
Control Type of value Can be linked to type Function to get value
Checkbox boolean boolean isSelected()
Edit box String String
double
int
getText()
getDoubleValue()
getIntValue()
Radio buttons int int getValue()
Slider double double
int
getValue()
getIntValue()
Combo box String String getValue()
List box String String getValue()

How can we improve this article?