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).
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
- Open the diagram of the Simulation experiment (by double-clicking the Simulation item in the Projects view).
- 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.
- 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.
- 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).
- In the NumberOfElephants field, specify the actual value for this parameter by typing: slider.getIntValue(). Use code completion to type this code.
- 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.
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?
-